Tfs version?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?
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.Code:setPlayerStorageValue(cid, 1000, 1) addEvent(function() setPlayerStorageValue(cid, 1000, -1) end, 5000) -- 5 sec
database query is the solutionkeep in mind that you should force this function to happen on player death and stop the event too if you don't want errors.
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.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.
There are several options to reset the storage back to 0 if there is a crash, or a player dies during the duration.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.
Or just simply add to login.lua i mean hell, that's a hell of a process. Rough work.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.
been there done that.Or just simply add to login.lua i mean hell, that's a hell of a process. Rough work.
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.
player:setStorageValue(x, os.time() + 1 * 60 * 60)
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)
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.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.