potinho
Advanced OT User
Hello guys, I have this script which is an exp scroll, it gives twice the experience for two hours, but if the char does not log out, the bonus experience continues, and only ends as soon as the char logs out. Can you help me fix the script?
in login.lua i've got:
Lua:
local config = {
rate = 2,
time = 2, -- Hours of Exp Time
storage = 20014
}
local function endExpRate(cid)
if isPlayer(cid) == TRUE then
doPlayerSetRate(cid, SKILL__LEVEL, 1) -- config.lua rate
setPlayerStorageValue(cid, config.storage, -1)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
end
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerStorageValue(cid, config.storage) < os.time() then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have experience rate x2 It will last for ".. config.time .." hours.")
doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600)
addEvent(endExpRate, config.time * 3600 * 1000, cid)
doRemoveItem(item.uid, 1)
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
end
return TRUE
end
in login.lua i've got:
Lua:
last = math.ceil((getPlayerStorageValue(cid, 20014) - os.time())/60)
if (getPlayerStorageValue(cid, 20014) > os.time()) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Extra experience rate is now: 2.0x than normal. It will last for ".. last .." minutes.")
doPlayerSetRate(cid, SKILL__LEVEL, 2.0)
else
doPlayerSetRate(cid, SKILL__LEVEL, 1.0)
end