- Joined
- Dec 11, 2007
- Messages
- 3,666
- Solutions
- 1
- Reaction score
- 125
- Location
- Warsaw, Poland
- GitHub
- tayandenga
- Twitch
- tayandenga
Hello people,
long time I haven't posted anything around, so I decided to share this tiny feature here.
Title says everything, though I'll explain it a little. System works on storage values and few other cool stuff instead modal dialog. Just simply set actionid to 6666 for any item you want to be working as "statue" and you are ready to go. You can of course adjust the config part too if you know what you're doing.
Have fun.
long time I haven't posted anything around, so I decided to share this tiny feature here.
Title says everything, though I'll explain it a little. System works on storage values and few other cool stuff instead modal dialog. Just simply set actionid to 6666 for any item you want to be working as "statue" and you are ready to go. You can of course adjust the config part too if you know what you're doing.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Offline Training System" version="1.1" author="Elf" contact="[email protected]" enabled="yes">
<config name="OfflineTraining.Config"><![CDATA[
config = {
pool = 12 * 60 * 60 * 1000,
minimum = 10 * 60,
premium = true
}
storage = {
time = "offlineTrain.time",
skill = "offlineTrain.skill",
logout = "offlineTrain.logout" -- optional, only if server does not have getPlayerLastLogout
}
rates = {
[SKILL_FIST] = 0.5,
[SKILL_AXE] = 0.5,
[SKILL_CLUB] = 0.5,
[SKILL_SWORD] = 0.5,
[SKILL_DISTANCE] = 0.4,
[SKILL_SHIELD] = 0.25,
[SKILL__MAGLEVEL] = 0.5
}
]]></config>
<event type="login" name="OfflineTraining.Login" event="script"><![CDATA[
function onLogin(cid)
domodlib("OfflineTraining.Config")
if(getCreatureStorage(cid, storage.time) == EMPTY_STORAGE) then
doCreatureSetStorage(cid, storage.time, config.pool)
elseif(not getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) then
local logout
if(not _G["getPlayerLastLogout"]) then
logout = getCreatureStorage(cid, storage.logout)
else
logout = getPlayerLastLogout(cid)
end
local skill, offline = getCreatureStorage(cid, storage.skill), os.time() - math.max(getPlayerLastLogin(cid), logout)
if(skill > EMPTY_STORAGE and offline > config.minimum and rates[skill] ~= nil) then
local time = getCreatureStorage(cid, storage.time)
local vocation = getVocationInfo(getPlayerVocation(cid))
local ticks = math.min(time, offline * 1000)
if(skill == SKILL__MAGLEVEL) then
doPlayerAddSpentMana(cid, ((ticks / (vocation.manaGainTicks * 1000)) * vocation.manaGain) * rates[SKILL__MAGLEVEL], true)
else
doPlayerAddSkillTry(cid, skill, (ticks / vocation.attackSpeed) * rates[skill], true)
end
doPlayerAddSkillTry(cid, SKILL_SHIELD, (ticks / 1000) * rates[SKILL_SHIELD], true)
doPlayerPopupFYI(cid, "You have been training for " .. table.concat(string.diff(ticks / 1000)) .. ".")
doCreatureSetStorage(cid, storage.time, math.max(0, math.min(config.pool, math.abs(time - offline * 1000))))
else
doCreatureSetStorage(cid, storage.time, math.max(0, math.min(config.pool, getCreatureStorage(cid, storage.time) + (offline * 1000))))
end
end
doCreatureSetStorage(cid, storage.skill, nil)
return true
end
]]></event>
<event type="logout" name="OfflineTraining.Logout" event="script"><![CDATA[
function onLogout(cid, force)
domodlib("OfflineTraining.Config")
if(not _G["getPlayerLastLogout"]) then
doCreatureSetStorage(cid, storage.logout, os.time())
end
local time = getCreatureStorage(cid, storage.time)
if(time < config.pool) then
doCreatureSetStorage(cid, storage.time, math.max(0, math.min(config.pool, time + ((os.time() - getPlayerLastLogin(cid)) * 1000))))
end
return true
end
]]></event>
<event type="channelrequest" name="OfflineTraining.ChannelRequest" event="script"><![CDATA[
function onChannelRequest(cid, channel, custom)
unregisterCreatureEvent(cid, "OfflineTraining.ChannelRequest")
if(not custom) then
return true
end
domodlib("OfflineTraining.Config")
if(type(channel) ~= "number" or rates[channel] == nil) then
doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
return false
end
doCreatureSetStorage(cid, storage.skill, channel)
doRemoveCreature(cid)
return false
end
]]></event>
<action actionid="6666" event="script"><![CDATA[
function onUse(cid)
if(getPlayerCustomFlagValue(cid, PLAYERCUSTOMFLAG_GAMEMASTERPRIVILEGES)) then
return true
end
domodlib("OfflineTraining.Config")
if(premium and not isPremium(cid)) then
doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUNEEDPREMIUMACCOUNT)
return true
end
local skills = {}
for skill, _ in pairs(rates) do
if(skill ~= SKILL_SHIELD) then
skills[skill] = SKILL_NAMES[skill]:gsub("^%l", string.upper)
end
end
unregisterCreatureEventType(cid, "channelrequest")
doPlayerSendChannels(cid, skills)
registerCreatureEvent(cid, "OfflineTraining.ChannelRequest")
return true
end
]]></action>
<talkaction words="!offline" event="script"><![CDATA[
function onSay(cid)
domodlib("OfflineTraining.Config")
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have " .. table.concat(string.diff(math.max(0, math.min(config.pool, getCreatureStorage(cid, storage.time) + ((os.time() - getPlayerLastLogin(cid)) * 1000))) / 1000)) .. " of offline training available.")
return true
end
]]></talkaction>
</mod>
Have fun.