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

Timed storage value?

strutZ

Australian OT Member {AKA Beastn}
Joined
Nov 16, 2014
Messages
1,391
Solutions
7
Reaction score
550
Hey OTland!

How do I make a storage value timed? as in... player uses item.. which sets storage value to 1 and then after x amount of time changes back to 0?

TFS 1.1
 
Last edited:
I do believe addEvent is a function in tfs 1.1 and if so, when you assign the storage, make a local function to check if creature is alive and set storage back to 0 using addEvent.
 
Code:
setPlayerStorageValue(cid, 1000, 1)
addEvent(function() setPlayerStorageValue(cid, 1000, -1) end, 5000) -- 5 sec
 
Code:
setPlayerStorageValue(cid, 1000, 1)
addEvent(function() setPlayerStorageValue(cid, 1000, -1) end, 5000) -- 5 sec
keep in mind that you should force this function to happen on player death and stop the event too if you don't want errors.
 
I would recommend using os.time() instead.

Code:
setStorage(1337, os.time() + (1*60*60))---One hour

if(os.time() <= getStorage(1337)) then
return true
else
return false
end
 
I would recommend using os.time() instead.

Code:
setStorage(1337, os.time() + (1*60*60))---One hour

if(os.time() <= getStorage(1337)) then
return true
else
return false
end
You recommend os.time for a player storage? That's not too logical at all especially if the script is an action, movement, or spell.
 
You recommend os.time for a player storage? That's not too logical at all especially if the script is an action, movement, or spell.

Wait what?
I would use addEvent if it's a schedule event, if there should be a limit ex. you can use the chest once every 24h the ideal way is to set the storage value with ostime.
What do you think happens if the server crashes or restarts? The end result is that you will never be able to use it, since it will always be 1 until a god resets your storage value.
 
Wait what?
I would use addEvent if it's a schedule event, if there should be a limit ex. you can use the chest once every 24h the ideal way is to set the storage value with ostime.
What do you think happens if the server crashes or restarts? The end result is that you will never be able to use it, since it will always be 1 until a god resets your storage value.
There are several options to reset the storage back to 0 if there is a crash, or a player dies during the duration.
 
There are several options to reset the storage back to 0 if there is a crash, or a player dies during the duration.

Still why even bother?
Come with a real argument to why it's better to use addEvent and then an onStartup? script to reset all the values.
And still, if you do that you still run the risk of people abusing it if the server crashes:
Ex do warzones 2 times in one day, let's say the server start is 10.00 and the player does it at 9.00.
 
Still why even bother?
Come with a real argument to why it's better to use addEvent and then an onStartup? script to reset all the values.
And still, if you do that you still run the risk of people abusing it if the server crashes:
Ex do warzones 2 times in one day, let's say the server start is 10.00 and the player does it at 9.00.
Or just simply add to login.lua i mean hell, that's a hell of a process. Rough work.
 
Or just simply add to login.lua i mean hell, that's a hell of a process. Rough work.
been there done that.

Code:
for k, pot in pairs(potions) do removePotion(cid, k) end
    for k, v in pairs(moreFood) do player:setStorageValue(v.storage, -1) end
 
Or just simply add to login.lua i mean hell, that's a hell of a process. Rough work.

And you still can't come up with an argument for why a scheduled event event is better then a storage value with what the time was is better.
There is really no reason to even execute that code and make the code where the player logs on even longer.
But if you prefer to add even more code to your server for no reason then do that.
 
And you still can't come up with an argument for why a scheduled event event is better then a storage value with what the time was is better.
There is really no reason to even execute that code and make the code where the player logs on even longer.
But if you prefer to add even more code to your server for no reason then do that.

the reasons why its better to use addEvent
1. You dont need onThink function
2. It's shorter code than if you want to use os.Time
3. Code is cleaner and smoother

I think everyone agree with me you dont need to keep discussing about that
 
1. And why would you need an onThink function? Please do explain.

2. Invalid, @owned's version is 2 lines longer.

Code:
player:setStorageValue(x, os.time() + 1 * 60 * 60)

Code:
player:setStorageValue(x, 1)
addEvent(function (player) if(not player) then return false end player:setStorageValue(x, 0) end, 1 * 60 * 60, player)

-- Login part
player:setStorageValue(x, 0)

3. How is it cleaner and smoother? The code is not longer but would be even longer if you want it clean.

I highly doubt that since only you and owned has defended it and the type we are talking about is used in alot of places.
Just to take one: https://github.com/orts/server/blob/master/data/actions/scripts/quests/warzone_rewards.lua#L28

The reason to use our way is that you don't need to reset 50 storage values when you restart the server, also our way can't be abused like your type can if the server crashes / server restart etc.
So as I said, I highly doubt people prefer a method that isen't fully working.
 
1. And why would you need an onThink function? Please do explain.

2. Invalid, @owned's version is 2 lines longer.

Code:
player:setStorageValue(x, os.time() + 1 * 60 * 60)

Code:
player:setStorageValue(x, 1)
addEvent(function (player) if(not player) then return false end player:setStorageValue(x, 0) end, 1 * 60 * 60, player)

-- Login part
player:setStorageValue(x, 0)

3. How is it cleaner and smoother? The code is not longer but would be even longer if you want it clean.

I highly doubt that since only you and owned has defended it and the type we are talking about is used in alot of places.
Just to take one: https://github.com/orts/server/blob/master/data/actions/scripts/quests/warzone_rewards.lua#L28

The reason to use our way is that you don't need to reset 50 storage values when you restart the server, also our way can't be abused like your type can if the server crashes / server restart etc.
So as I said, I highly doubt people prefer a method that isen't fully working.
Used in a lot of places? Are you retarded? It's not used in a lot of places lmao And how is it not a fully working method? Please explain? Cause any person that's not a moron can make sure that it can't be abused. There's absolutely no reason on earth to use os.time for something that's probably not even over 20 seconds for the reset, and on top of that, depending on the script, a person may not just want a storage set back to 0, they may need other results as well. So your beloved os.time is only productive for this specific use. It's by no means better, and achieves nothing better. The functionality of it provides much less options.


Bottom line is your argument is one-sided and has limited options. I'm done arguing with you.
 
Last edited by a moderator:
Back
Top