• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Storage Times

imkingran

Learning everyday.
Premium User
Joined
Jan 15, 2014
Messages
1,317
Solutions
35
Reaction score
435
Hello,

I am wondering if is possible to set clock that will stop when the player is offline and start again when he is back online.

Right now when the player uses this item it will start counting down 2 hours whether he is online or offline. Is there a way to make it so that when the player is offline the clock will pause?


Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local doubleexp = 7200
local delaytime = 86400
if getPlayerStorageValue(cid, 63667) > 0 then
doPlayerPopupFYI(cid, "You may only use this once a day!.\nYou have to wait: " .. math.floor((getPlayerBonusDelay(cid))/3600) .. " hours and "   .. ( os.date("%M",getPlayerBonusDelay(cid))) ..  " minutes and " .. ( os.date("%S",getPlayerBonusDelay(cid))) .." seconds before you can use it again.")
else
doSendMagicEffect(getCreaturePosition(cid),29)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have just activated 2 hours of 25% bonus exp!!!")
setPlayerStorageValue(cid, 63666, os.time()+doubleexp+getPlayerBonusTime(cid))
setPlayerStorageValue(cid, 63667, os.time()+delaytime)
doRemoveItem(item.uid)
end
return true
end
 
Make a column in the player table to query onlogin/out.

Okay but even if I make the table to monitor log- in and log out. How, will I be able to make the time freeze when they are logged out? The storage will still be counting down unless I'm missing something.
 
The os.time() counts up, not down. For example os.time() is 1401873500, 10 seconds later it's 1401873510. By comparing os.time() with the storage value you can check if the time is over.
You can set a different storage and use the value - os.time() of the storage of your actionscript in a logout script, this way the time that is left will be set as value for a different storage when someone logs out.
Code:
setPlayerStorageValue(cid, 70000, getPlayerStorageValue(cid, 63667) - os.time())
Then in a login script, set that value + os.time() to the actionscript storage.
Code:
setPlayerStorageValue(cid, 63667, getPlayerStorageValue(cid, 70000) + os.time())
 
The os.time() counts up, not down. For example os.time() is 1401873500, 10 seconds later it's 1401873510. By comparing os.time() with the storage value you can check if the time is over.
You can set a different storage and use the value - os.time() of the storage of your actionscript in a logout script, this way the time that is left will be set as value for a different storage when someone logs out.
Code:
setPlayerStorageValue(cid, 70000, getPlayerStorageValue(cid, 63667) - os.time())
Then in a login script, set that value + os.time() to the actionscript storage.
Code:
setPlayerStorageValue(cid, 63667, getPlayerStorageValue(cid, 70000) + os.time())

Thanks I will try it!

Edit: Thanks it's working perfectly!

@Limos
 
Last edited:
Back
Top