• 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
 
Add this onLogout/onDeath
Code:
setPlayerStorageValue(cid, 20011, -1)
That is no good because they are still wasting the exp item when they die or logout

What you want to do is set their xp rate in login based on if they have enough time left stored in the storage value.
 
I usally dont help older tfs, but since you got a pokemon as an avatar. Here you go:

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)
    if getPlayerStorageValue(cid, config.storage) >= os.time() then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
        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

Add this login.lua
Code:
    if getPlayerStorageValue(cid, 20011) >= os.time() then
        doPlayerSetRate(cid, SKILL__LEVEL, 3.0)
    else
        doPlayerSetRate(cid, SKILL__LEVEL, 6.0)
        setPlayerStorageValue(cid, 20011, -1)
    end
 
Last edited:
I usally dont help older tfs, but since you got a pokemon as an avatar. Here you go:

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)
    if getPlayerStorageValue(cid, config.storage) == -1 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
        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

Add this login.lua
Code:
    if getPlayerStorageValue(cid, 20011) >= os.time() then
        doPlayerSetRate(cid, SKILL__LEVEL, 3.0)
    else
        doPlayerSetRate(cid, SKILL__LEVEL, 6.0)
        setPlayerStorageValue(cid, 20011, -1)
    end
hahah thanks man! <3


uuhhh didn't work, it says to everyone who uses the object about the extra time left :/
and i just made this account and char
FgNpfTDDD.png
 
Last edited:
It because they still have time left, do you want to remove extra exp after logout?
 
It because they still have time left, do you want to remove extra exp after logout?
No, i created a new account and a new character, and when i right click on the object it sends that message instantly and the item is not consumed
 
Why does nobody give me credit? If your going to use the script you should follow my entire post. lmao.
Xikini said:
Actions
Code:
<action itemid="11111" event="script" value="donator/exp.lua"/>
Code:
local config = {
   rate = 4, -- 4x More Experience
   time = 1, -- Hours of Exp Time
   storage = 20013
}
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) < 0) and getPlayerLevel(cid) > 199 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)
     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
Creaturescripts
Code:
<event type="login" name="expRate" event="script" value="extraExpRate.lua"/>
Code:
registerCreatureEvent(cid, "expRate") -- login.lua
Code:
local config = {
   rate = 4, -- 4x More Experience
   storage = 20013
}
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 onLogin(cid)
   local str = getPlayerStorageValue(cid, config.storage)
   if(str >= 0 and (str - os.time()) > 0) then
     doPlayerSetRate(cid, SKILL__LEVEL, config.rate)
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Your extra exp rate will expire at: " .. os.date("%X", str))
     addEvent(endExpRate, (str - os.time()) * 1000, cid)
   else
     doPlayerSetRate(cid, SKILL__LEVEL, 1) -- config.lua rate
     doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You do not have any extra experience time.")
     setPlayerStorageValue(cid, config.storage, -1)
   end
   return TRUE
end
 
@Printer working so far, now it's consumable, i disconected and i'm still with triple exp, but how do i see this?
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))
because when i use the item again i see is you still have some extra experience

@Xikini Sorry man but printer helped me first so i checked his way first ;c thanks anyway, if doesn't work i will use yours :D
 
Is there any way to know how much time you have left? that work with every item that gives extra eperience? because a have a few, this was 3x 24 hours, i have x2 for 7 days, etc
plz plz plz? :D
 
Is there any way to know how much time you have left? that work with every item that gives extra eperience? because a have a few, this was 3x 24 hours, i have x2 for 7 days, etc
plz plz plz? :D
If you are storing the time in milliseconds, you can pass that data to os.date, this function returns value is a table.
For instance:
Code:
local timeLeft = getPlayerStorageValue(cid, config.storage)
local timeTable = os.date('*t', timeLeft)
Now you can access any 1 of timeTable's properties
Code:
-- properties of timeTable, all return a number
yday -- day of the year
wday -- day of the week
year -- current year
month -- current month
day -- date of the day for the month
hour -- hour of the day
min -- minute
sec -- second

If you wanted to see how many hours, minutes or seconds you had left, you could write
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have"..timeTable.hour.." hour(s) "..timeTable.min.." minute(s) "..timeTable.sec.." second(s) left of extra experience.")

You can also alter the time using the reverse of this process.
 
Last edited:
If you are storing the time in milliseconds, you can pass that data to os.date, this function returns value is a table.
For instance:
Code:
local timeLeft = getPlayerStorageValue(cid, config.storage)
local timeTable = os.date('*t', timeLeft)
Now you can access any 1 of timeTable's properties
Code:
-- properties of timeTable, all return a number
yday -- day of the year
wday -- day of the week
year -- current year
month -- current month
day -- date of the day for the month
hour -- hour of the day
min -- minute
sec -- second

If you wanted to see how many hours, minutes or seconds you had left, you could write
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have"..timeTable.hour.." hour(s) "..timeTable.min.." minute(s) "..timeTable.sec.." second(s) left of extra experience.")

You can also alter the time using the reverse of this process.


thanks! ok, but about this
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have"..timeTable.hour.." hour(s) "..timeTable.min.." minute(s) "..timeTable.sec.." second(s) left of extra experience.")

when it is used? with a talkaction? and will that work for every of my experience multiplier items? :)
 
just add it onto ur old script and ppl will see remaining time left :p
but how will they see it?

i replaced
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")

for

Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have"..timeTable.hour.." hour(s) "..timeTable.min.." minute(s) "..timeTable.sec.." second(s) left of extra experience.")

but it only says you cannot use this object, i'm sure something is missing
 
Last edited:
Do as @Codex NG said, but i would done it something like this:

Code:
function onSay(cid, words, param)
    local timeLeft = getPlayerStorageValue(cid, 20011)
    if timeLeft <= os.time() then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have no extra experience time.")
        return true
    end

    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
 
Do as @Codex NG said, but i would done it something like this:

Code:
function onSay(cid, words, param)
    local timeLeft = getPlayerStorageValue(cid, 20011)
    if timeLeft <= os.time() then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have no extra experience time.")
        return true
    end

    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

the problem is i didn't understand very well what @Codex NG said, now i have this

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)
    if getPlayerStorageValue(cid, config.storage) == -1 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You still have extra experience time left.")
        return true
    end

    local timeTable = os.date('*t', timeLeft)
    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

but clearly i have done something bad because when i click the ticket i see this:

Your extra experience rate is now: 3. It will last for 24 hours.
and it consumes the item, and always says that

Also when someone with no exp booster uses it it says:

You still have extra experience time left

plz guys help me fix this mess :(
 
Just copy the code i've done, since i see you made changes in the action code.
 
Back
Top