• 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:
in items.xml u can use duration and decayTo, it will count as long as it exists. (think of decaying bodies and fire fields, same concept)

i am not sure what will happen if the player logs out. will it pause the timer or will it keep going.
 
in items.xml u can use duration and decayTo, it will count as long as it exists. (think of decaying bodies and fire fields, same concept)

i am not sure what will happen if the player logs out. will it pause the timer or will it keep going.

You are right about that, it worked but like you said just only when player is online, when player logout pause the timer. Another way to do that?

bump
 
Last edited by a moderator:
What is that for? Maybe you can do it other way.

I'm trying to put 30 days of duration in some vip items. I was reading this thread, summ has posted a login script, but I need that remove the item no matter if player is online or not. Do you know another way to do that? I really need this.
 
Im not sure what does this enum stand for: ITEM_ATTRIBUTE_DECAYSTATE
But if it shows the duration.
then on logout you can save the item duration to database or on player on global table and when player relogs, compare the os.time() and do the calculating.
 
Im not sure what does this enum stand for: ITEM_ATTRIBUTE_DECAYSTATE
But if it shows the duration.
then on logout you can save the item duration to database or on player on global table and when player relogs, compare the os.time() and do the calculating.

With this tag in xml
Code:
 <attribute key="duration" value="xxx" />
I have a limit of seconds to put. I've tested with 24 hours (86400 seconds), but I need that the item be removed in 30 days, it will be 2592000 fuc** seconds. With this number in xml the item can't be created. So I think is easiest do that with another way, to use this method first need resolve the seconds limit and then do like you said and calculate the time.
 
I'm trying to put 30 days of duration in some vip items. I was reading this thread, summ has posted a login script, but I need that remove the item no matter if player is online or not. Do you know another way to do that? I really need this.
Isn't better to make vip items only for vip players (vip system) so it will be possible to use only for 30 days?
You will have alot of work if you want offline duration for each item and probably you will need to create table in database or change source code.

Counter that update duration in database every day at one specified hour and onlogin check to delete item if duration expired.
But this wont work if player will drop item etc. so..
 
Isn't better to make vip items only for vip players (vip system) so it will be possible to use only for 30 days?
You will have alot of work if you want offline duration for each item and probably you will need to create table in database or change source code.

Counter that update duration in database every day at one specified hour and onlogin check to delete item if duration expired.
But this wont work if player will drop item etc. so..

I need that for free players, if need changes in db or sources I can make it. My ot is a War Server, so don't drop anything. Someone please?
 
Sorry i don't know anything about war servers, can't help you. On war serwers you can login, die and respawn with starting lvl etc? Whats the point of making items for war serwers?
 
idea nr: 2

if you create duration item registrate it on db with query. you can hide the creation time in itemattribute(TEXT)
Then once per day or whenever you do global server save, update these queries.
Also each serversave or once per day update global LUA table where is list of these items and starting os.time()

When new duration item is added to game, registrate it to db and global table.

Make global event what checks all the items in global table every minute.

Boom legshot.
 
Just throwing this out there :)
I don't have a server to test it on.
Code:
function createItemWithTime(cid, itemid, subType, time_, ignoreCap)
   local item = doCreateItemEx(itemid, subType)
   item:setAttribute(ITEM_ATTRIBUTE_DECAYSTATE, true) -- not sure of the value for this
   item:setAttribute(ITEM_ATTRIBUTE_DURATION, time_)
   if doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR then
     return true
   end
   return false
end
 
Last edited:
Just throwing this out there :)
I don't have a server to test it on.
Code:
function createItemWithTime(cid, itemid, subType, time_, ignoreCap)
   local item = doCreateItemEx(itemid, subType)
   item:setAttribute(ITEM_ATTRIBUTE_DECAYSTATE, true) -- not sure of the value for this
   item:setAttribute(ITEM_ATTRIBUTE_DURATION, time_)
   if doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR then
     return true
   end
   return false
end
but he said limit is 24 hours on duration.
 
but he said limit is 24 hours on duration.
ok how about this :)
Code:
function createItemWithTime(cid, itemid, subType, ignoreCap)
    local item = doCreateItemEx(itemid, subType)
    item:setAttribute(ITEM_ATTRIBUTE_ACTIONID, generateItemSerial())
    if doPlayerAddItemEx(cid, item, true) ~= RETURNVALUE_NOERROR then
        return true
    end
    return false
end

-- generate serial so you can track the item
function generateItemSerial()
    local expires = 30
    local itemInfo = {}
    local serial = ''

    for key, value in pairs(os.date("*t")) do
        itemInfo[key] = tonumber(value)
    end

    for iKey, iValue in pairs(itemInfo) do
        if iKey ~= "yday" then
            serial = serial .. iValue
        end
    end
    serial = serial .. (itemInfo['yday'] + expires)
    return serial
end

Then you can track the item by its actionid and check the database for items with values less then the current using a similar formula.
The return value is a big number but you can edit the table to generate a unique serial per item rather than just using os.time()

The table generated by os.date() is
Code:
hour   number
min     number
wday   number
year   number
yday   number
month   number
sec     number
day     number
isdst   bool
 
Last edited:
item:setAttribute(ITEM_ATTRIBUTE_TEXT, os.time())
much easier.
It might be easier to apply as a text but when the player views the item they are only going to see a bunch of numbers which doesn't mean much of anything to them.

You will need to format it to something much more legible, and then convert it back to milliseconds so that it can be used for comparison.
 
It might be easier to apply as a text but when the player views the item they are only going to see a bunch of numbers which doesn't mean much of anything to them.

You will need to format it to something much more legible, and then convert it back to milliseconds so that it can be used for comparison.
they dont see ITEM_ATTRIBUTE_TEXT unless its Book or letter. and even if it is, the text can be replaced just for that instance.
 
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:
 

Similar threads

Back
Top