• 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 Item useable every 3 days

Northnorial

Member
Joined
May 30, 2009
Messages
742
Reaction score
5
Location
Germany
Hello,

I've been trying to make an item work only every 3 days, but it's simply not working for me.

Basically I can't get the storage working for that matter.

Can anybody give me a short explanation to let storage work as a timer?

Or give me an example script? I been looking here on OtLand, but couldn't find anything really useful.

Thanks in advance! :)
 
Which server do you use? You can you storage with os.time() as value + extra time. Then compare os.time() with the storage value to see if the 3 days are over.
The storagevalue will be higher as long as the 3 days aren't over yet.
 
I use TFS 0.3

config looks like this
Code:
config = {
    valid_time = 3 * 24 * 60 * 60,
    storage = 18000,
    }
Code:
        if (getPlayerStorageValue(cid, config.storage) < os.time()) then
   
            setPlayerStorageValue(cid, config.storage, os.time()+config.valid_time)

        else
         
        end

is this gonna work?
 
TFS 0.3 has a Lua made function in data/lib/034-exhaustion.lua which works the same way, you could use that.
To set time
Code:
exhaustion.set(cid, config.storage, config.valid_time)
To check if the time isn't over yet
Code:
if exhaustion.check(cid, config.storage) then
To get the time in seconds that is still left
Code:
exhaustion.get(cid, config.storage)

But you can also do it the way you did, it's the same thing.
 
Last edited:
Just that is enough, what exactly happens?
Which 0.3 version do you use? In some really old servers you need to add == TRUE to check if a function returns true.
 
I dont really know which 0.3 Version this is, but it might be old.

I just added == true and its perfectly working now

How can I make
exhaustion.get(cid, config.storage)

tell me the hours?
 
Last edited by a moderator:
00:28 You have to wait 71 hours, 30 minutes and 13 seconds before you can use another stone of wisdom.

its working fine :p


EDIT: I just change the storage and this happens

00:30 You have to wait 0 second before you can use another stone of wisdom.
00:30 You have to wait 0 second before you can use another stone of wisdom.
00:30 You have to wait 0 second before you can use another stone of wisdom.
 
Script looks like this btw:

Whats wrong?
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

    cfg = {
        valid_time = 3 * 24 * 60 * 60,
        storage = 18025,
        min = 8,
        experience = getPlayerLevel(cid) * 5000
    }

    if (exhaustion.check(cid, cfg.storage) == true) then
        local time = exhaustion.get(cid, cfg.storage)
        local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)       
        if time >= 3600 then
            text = hours.." "..(hours > 1 and "hours" or "hour")..", "..minutes.." "..(minutes > 1 and "minutes" or "minute").." and "..seconds.." "..(seconds > 1 and "seconds" or "second")
        elseif time >= 120 then
            text = minutes.." "..(minutes > 1 and "minutes" or "minute").." and "..seconds.." "..(seconds > 1 and "seconds" or "second")
        else
            text = seconds.." "..(seconds > 1 and "seconds" or "second")
        end
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You have to wait " .. text .. " before you can use another stone of wisdom.")
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
        return true
    end

    if (getPlayerLevel(cid) < cfg.min) then
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You have to be level " .. cfg.min .. " or higher to use this.")
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
    return true
    end
   
    exhaustion.set(cid, cfg.storage, cfg.valid_time)
    doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You gained " .. cfg.experience .. " experience points.")
    doPlayerAddExp(cid, cfg.experience)
    doRemoveItem(cid, item.uid, 1)
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_SOUND_RED)
return true
end
 
It's possible your server is not supporting this
Code:
"..(hours > 1 and "hours" or "hour").."
So you could try to change it to hours/minutes/seconds instead of the code that checks for the amount.
You could add an extra elseif statement to make a difference between hour and hours.

I also just posted the script, can you check it? Please
 
I didn't notice your edit with the result, so you can ignore the thing I posted first :p

You can do the same thing for hours, minutes and second, add then in print and look what it says in your console.
 
You can also use broadcast if there are no players online atm (else it will be a bit weird for players:p)
Code:
doBroadcastMessage(time)

Or a normal textmessage.
 
Back
Top