• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved script stop working after logout (exp amulet)

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
922
Location
Chile
hello guys! i have a script of an action that gives you X experience for X ammount of time, the one i will post here is x3 exp for 24 hours, but when the player logs out the exp comes back to normal :/ and if they want to want it again, it says is not possible because there's still some exp time left

plz guys help me to make this script last thopse 24 hours, no matter if the player log out, or the server goes down, etc, so 24 hours of gameplay

Code:
local config = {
        rate = 3.0, -- 4x More Experience
        time = 24, -- Hours of Exp Time
        storage = 20011
    }
    local function endExpRate(cid)
        doPlayerSetRate(cid, SKILL__LEVEL, 6.0) --config.lua rate
        setPlayerStorageValue(cid, config.storage, -1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
    end
    function onUse(cid, item, fromPosition, itemEx, toPosition)
        if(getPlayerStorageValue(cid, config.storage) == -1) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your extra experience rate is now: " .. config.rate .. ". It will last for ".. config.time .." hours.")
            doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
            setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600 * 1000)
            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
 
Thanks to @Printer for the string formatting.
Should show how much time you have left if you have any, otherwise it uses the item and gives you 24 hours.
Code:
local config = {
    rate = 3.0,
    time = 24,
    storage = 20011
}

local function endExpRate(cid)
    if not isPlayer(cid) then
        return
    end

    doPlayerSetRate(cid, SKILL__LEVEL, 6.0)
    setPlayerStorageValue(cid, config.storage, -1)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local timeLeft = getPlayerStorageValue(cid, 20011)
    if timeLeft > os.time() then
        local timeTable = os.date('*t', timeLeft)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, string.format("You still have %d %s %d %s %d %s left of extra experience.", timeTable.hour, timeTable.hour > 1 and "hours" or "hour", timeTable.min, timeTable.min > 1 and "minutes" or "minute", timeTable.sec, timeTable.sec > 1 and "seconds" or "second"))
        return true
    end

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, string.format("Your extra experience rate is now: %d. It will last for %d hours.", config.rate, config.time))
    doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
    setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600 * 1000)
    addEvent(endExpRate, config.time * 3600 * 1000, cid)
    doRemoveItem(item.uid, 1)
    return true
end
 
Last edited:
Thanks to @Printer for the string formatting.
Should show how much time you have left if you have any, otherwise it uses the item and gives you 24 hours.
Code:
local config = {
    rate = 3.0,
    time = 24,
    storage = 20011
}

local function endExpRate(cid)
    if not isPlayer(cid) then
        return
    end

    doPlayerSetRate(cid, SKILL__LEVEL, 6.0)
    setPlayerStorageValue(cid, config.storage, -1)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local timeLeft = getPlayerStorageValue(cid, 20011)
    if timeLeft > os.time() then
        local timeTable = os.date('*t', timeLeft)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, string.format("You still have %d %s %d %s %d %s left of extra experience.", timeTable.hour, timeTable.hour > 1 and "hours" or "hour", timeTable.min, timeTable.min > 1 and "minutes" or "minute", timeTable.sec, timeTable.sec > 1 and "seconds" or "second))
        return true
    end

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, string.format("Your extra experience rate is now: %d. It will last for %d hours.", config.rate, config.time))
    doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
    setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600 * 1000)
    addEvent(endExpRate, config.time * 3600 * 1000, cid)
    doRemoveItem(item.uid, 1)
    return true
end

sorry but i get this error :(
RQEVRpMjp.png
 
Change this line:
Code:
local timeTable = os.date('*t', timeLeft)
to:
Code:
local timeTable = os.date('*t', timeLeft - (os.time() + 3600))

The message you got:
"You still have 22 hours 40 minutes 35 seconds left of extra experience."
Is actually the time when your extra experience will end, 22:40:35 (o'clock), rather than time left. We have to subtract the current time from the time in the player's storage value. I should have read the code more carefully.

So why do we remove an extra hour (3600 seconds)? os.date generates the date table based on seconds passed since epoch (os.time() = seconds since epoch). The thing we have to compensate for is that "epoch" is determined to be January 1st 1970 01:00 (1 am). What this does is when we get the time table, the base value is that of epoch, so os.date("*t", 0), would make the hour 1, even though time is 0 (no time has passed since epoch). When we remove that extra hour, the date table's hour field will start at 0 instead of 1.
 
Change this line:
Code:
local timeTable = os.date('*t', timeLeft)
to:
Code:
local timeTable = os.date('*t', timeLeft - (os.time() + 3600))

The message you got:
"You still have 22 hours 40 minutes 35 seconds left of extra experience."
Is actually the time when your extra experience will end, 22:40:35 (o'clock), rather than time left. We have to subtract the current time from the time in the player's storage value. I should have read the code more carefully.

So why do we remove an extra hour (3600 seconds)? os.date generates the date table based on seconds passed since epoch (os.time() = seconds since epoch). The thing we have to compensate for is that "epoch" is determined to be January 1st 1970 01:00 (1 am). What this does is when we get the time table, the base value is that of epoch, so os.date("*t", 0), would make the hour 1, even though time is 0 (no time has passed since epoch). When we remove that extra hour, the date table's hour field will start at 0 instead of 1.

oh man :( still doesn't work right, time is decreasing, yes, but when a new player uses the item, it says the message you got extra experience, and when it uses again to see the remaining time it says 59 min 59 segs, so it's only giving one hour, and the other problem is that the time decreases even tho the player is not logout, altho i like this way, if it decreases still if the player is not logged in fine by me, better :P
well that's it, i better post what i have now to make less messy this thread
Code:
local config = {
    rate = 3.0,
    time = 24,
    storage = 20011
}

local function endExpRate(cid)
    if not isPlayer(cid) then
        return
    end

    doPlayerSetRate(cid, SKILL__LEVEL, 6.0)
    setPlayerStorageValue(cid, config.storage, -1)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local timeLeft = getPlayerStorageValue(cid, 20011)
    if timeLeft > os.time() then
        local timeTable = os.date('*t', timeLeft - (os.time() + 3600))
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, string.format("You still have %d %s %d %s %d %s left of extra experience.", timeTable.hour, timeTable.hour > 1 and "hours" or "hour", timeTable.min, timeTable.min > 1 and "minutes" or "minute", timeTable.sec, timeTable.sec > 1 and "seconds" or "second"))
        return true
    end

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, string.format("Your extra experience rate is now: %d. It will last for %d hours.", config.rate, config.time))
    doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
    setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600 * 1000)
    addEvent(endExpRate, config.time * 3600 * 1000, cid)
    doRemoveItem(item.uid, 1)
    return true
end

sorry for the troubles ;c
 
Why don't you just use my original working script and be done with it..
Code:
setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600)
 
Last edited by a moderator:
Why don't you just use my original working script and be done with it..
Code:
setPlayerStorageValue(cid, config.storage, os.time() + config.time * 3600)
damn sorry for bumping this thread but still doesn't work propèrly,
i use that line and the timer works perfectly! but when it gets to zero the player still has the exp bonus and the counter starts again!
00:00:01 and back to 23:59:59 immediately
plz guys help me solve this
 
Ok guys script is fully functional thank to all of you and Limos who helped me privately, so here i share the script if anyone wants to use it

What id does:
gives you (in this case) x3 bonus exp for 24 hours
if you use the item again, doesn't give you more bonus, it tells you how much time you have left, and then you can use the item again
if the time ends when you are logged in you get a message telling you time has ended
when it finishes, exp goes back to normal

creaturescript login.lua
Code:
 if getPlayerStorageValue(cid, 20011) >= os.time() then
        doPlayerSetRate(cid, SKILL__LEVEL, 3.0)
    else
        doPlayerSetRate(cid, SKILL__LEVEL, 1.0)
        setPlayerStorageValue(cid, 20011, -1)
    end

actions
Code:
local config = {
    rate = 3.0,
    time = 24,
    storage = 20011
}

local function endExpRate(cid)
    if not isPlayer(cid) then
        return
    end

    doPlayerSetRate(cid, SKILL__LEVEL, 1.0)
    setPlayerStorageValue(cid, config.storage, -1)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your extra experience time has ended.")
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local timeLeft = getPlayerStorageValue(cid, 20011)
    if timeLeft > os.time() then
        local timeTable = os.date('*t', timeLeft - (os.time() + 3600))
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, string.format("You still have %d %s %d %s %d %s left of extra experience.", timeTable.hour, timeTable.hour > 1 and "hours" or "hour", timeTable.min, timeTable.min > 1 and "minutes" or "minute", timeTable.sec, timeTable.sec > 1 and "seconds" or "second"))
        return true
    end

    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, string.format("Your extra experience rate is now: %d. It will last for %d hours.", config.rate, config.time))
    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)
    return true
end

that's it, thanks guys <3
 
Back
Top