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

Item with duration

Way20

Well-Known Member
Joined
Sep 29, 2014
Messages
227
Solutions
3
Reaction score
91
I've seen some thread asking for some way to put duration in some items but I didn't find a solution, how to make a item that have only 30 days of duration, after this time it will disappear. I talk about a item that will disappear with or without use, I think that put tag in Items.xml will just spend in moments of use. (correct me if I'm wrong) Someone know a way to do that?
 
Last edited:
looks like whitevo beat me to it. set the text with os.time(), it's definitely the best way to do it. Only issue is how to check remaining time. You wouldn't want to query all items a player has on them, in their depot, in their house, cause it'd absolutely kill everything until it finishes running. So you'd want something more like an onThink() on the individual player, but then it runs every second per player which is also no good. And if they do relog, the item's userdata changes so it can't be tracked in a global table, (correct me if I'm wrong) and if the server restarts, it loses those global storages anyways. The setting is easy, the retrieving upon onLook is easy. The actual checking will be a pain. If the userdata resets and the item isn't on the player, how would you find it? you'd have to query player depots and houses to find items with one of these decay timers in its text. If it's only one type of item, it might be a little cleaner but it still sounds messy to me. Maybe I'm just overthinking it o:
it will only activate when player look the item.

it will be perfect trigger.
you want to see how much time left?

sure let me take the starting time. and item end time from database.
query takes time, but it only does it once per look trigger on special item with duration.

then it will compare it with os time written on item. and ask when was the item first created. what was os time then. and what is now os time and what is the end time in database when item was first created.
 
it will only activate when player look the item.

it will be perfect trigger.
you want to see how much time left?

sure let me take the starting time. and item end time from database.
query takes time, but it only does it once per look trigger on special item with duration.

then it will compare it with os time written on item. and ask when was the item first created. what was os time then. and what is now os time and what is the end time in database when item was first created.
No, no I mean, checking the value in order to actually decay the item after the time is up. If it was onLook, it would work cleanly, except for the part where the player could just never look at it and it would never decay.
 
No, no I mean, checking the value in order to actually decay the item after the time is up. If it was onLook, it would work cleanly, except for the part where the player could just never look at it and it would never decay.
that happens once per minute in globalevents. but it doesnt have to check database or player items.

because we registrated the same item in LUA table too.
 
that happens once per minute in globalevents. but it doesnt have to check database or player items.

because we registrated the same item in LUA table too.
if the player logs out, the userdata of that item changes I believe (not 100% sure. I think a server restart or crash would also change the userdata, but again, not sure). also, if the server restarts (as many servers do at server save once per day) that lua table disappears
 
if the player logs out, the userdata of that item changes I believe (not 100% sure. I think a server restart or crash would also change the userdata, but again, not sure). also, if the server restarts (as many servers do at server save once per day) that lua table disappears
yes that is why we record update it on database once in a while.

And when it comes down to removing item and userdata is gone. it will first try to backtrack where was item last seen and compare the text. if starting time matches it deletes it.
 
You don't need to query the items of the player you only need to query the database if your giving an item a actionid as a storage value.
If a column doesn't exist for said item to assign it a value then you add one to the items storage and when the item is created you populate that field.

Then every server save or whenever, using os.time() you query the database searching all the items that have a value that is less then the current time.
 

Similar threads

Back
Top