• 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!

Lua How to set a storage to "decay" ?

darkshin

New old member
Joined
Dec 14, 2010
Messages
231
Reaction score
22
Hello guys!

I wonder how can I set a time to a storage decay or be erased?
Thats it!
 
If its a player storage create a function that checks if the player exists if it doesn't return, if it does set the value to -1, use an addEvent to execute the function give it the time, the player and storage value.

If it is a global storage use the appropriate functions
 
Using addEvent has the limitation of not working if the player is offline. What might be a better option is to set the storage to os.time() and rather than checking if the storage = 1 in w.e script you are using it, instead compare the storage with the current os.time().
 
Using addEvent has the limitation of not working if the player is offline. What might be a better option is to set the storage to os.time() and rather than checking if the storage = 1 in w.e script you are using it, instead compare the storage with the current os.time().
I know that is why i said for it to return false if the player didn't exist, I could of just wrote a script for them (& so could you) but what would they learn from that?
 
Using addEvent has the limitation of not working if the player is offline. What might be a better option is to set the storage to os.time() and rather than checking if the storage = 1 in w.e script you are using it, instead compare the storage with the current os.time().

I've tried to set the storage like that, as I saw in a script from Limos: setPlayerStorageValue(player.uid, 3000, os.time() + 1*60), didn't worked as I expect. I understand now that the match I've made was wrong: if getPlayerStorageValue(player.uid, 3000) < 2 then. I should do it like this?: if getPlayerStorageValue(player.uid, 3000) os.time() + < 2 then, so they are equal type of values?

I know that is why i said for it to return false if the player didn't exist, I could of just wrote a script for them (& so could you) but what would they learn from that?

I understood what you said. It sounds simple. I've though of another way, but I don't really know its impact at server, would be like this: I add another storage with the value equal to the time I want, and I set it to -1 on every onThink function, until I reach the value 1 or 0, and then another statement checks it, but as I said, yours more simple. hahaha
 
I know that is why i said for it to return false
Again, that is a limitation. If the player is offline and the event fails, the player will have that storage the next time they log in. You could do some fancy onlogin stuff to check if the player has the storage or you could just use the timestamp.

I should do it like this?
No. The concept is to compare 2 times together. os.time() is in seconds so all you have to do is say for example:
storage = os.time()+60
This means 60 seconds more than the current time and if you want to compare it you just need to check if the current os.time is LESS than the stored time. If the time is MORE than the stored time then it is "expired".
 
os.time is a bit buggy in 1.x, i know its a default function in lua, it might be because how the server handles its internal scheduled tasks that causes an issue, if you have an issue with os.time() use os.date(), it returns a table of time.
http://www.lua.org/pil/22.1.html
 
Back
Top