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

Add decay/duration to normal item.

pink_panther

Excellent OT User
Joined
Sep 10, 2016
Messages
1,171
Solutions
13
Reaction score
613
Location
Kazordoon
Wondering how/if possible to be able to create an item with a command like /i that will decay/disappear after a set time.

For example, if I wanted to spawn an item that doesn't normally decay, like a steel helmet. But I want the item to decay to 0 (be removed) after a set time.

Is it possible to do this without having to create a copy of the item with a decayTo and duration value in the items.xml?

In theory, wanted to be able to spawn any item and have it disappear after a set time.

I've tried something like this, but doesn't seem to work, though I don't get any errors.

Lua:
    local result = Game.createItem(1234, 1, player:getPosition())
    if result then
        result:decay()
        result:setAttribute(ITEM_ATTRIBUTE_DECAYTO, 0)
        result:setAttribute(ITEM_ATTRIBUTE_DURATION, 60)
        result:setAttribute(ITEM_ATTRIBUTE_DECAYSTATE, true)
    end

I'm aware of how it could be done with an addEvent callback to find and remove the item from its uid or something, but wondering if it can be done this way instead.
 
 
Whot
 
Is it possible to do this without having to create a copy of the item with a decayTo and duration value in the items.xml?
Short answer, not with the proper tweaks on the source code

However that does not mean its not possible with the default system but just FYI it will be way more cleaner to do a copy of the item
 
How about you try moving :decay() after u set attributes?
tried before and after and both.
Short answer, not with the proper tweaks on the source code

However that does not mean its not possible with the default system but just FYI it will be way more cleaner to do a copy of the item
Yeah, but then it will need to have the same duration on it every time, as well as needing to duplicate every item you wanted to do it for.
 
Yeah, but then it will need to have the same duration on it every time, as well as needing to duplicate every item you wanted to do it for.
Aha, well if thats the case... the source tweak is your option
I assume you are not using TFS 1.5 because on that version is currently possible

For TFS 1.4

https://github.com/otland/forgottenserver/blob/1.4/src/game.cpp#L4526
Replace that line with
C++:
if (item->getDecayTo() > 0) {

https://github.com/otland/forgottenserver/blob/1.4/src/item.cpp#L1633
Replace that line with
C++:
if (getDecayTo() < 0 || (it.decayTime == 0 && getDuration() == 0)) {

On TFS 1.2, getDecayTo() method and the attribute itself is missing, so just copy/paste from 1.4 code or you can use TFS 1.5 code aswell

It doesnt matter, you only need to edit those two lines of the code
Also you dont need to use result:setAttribute(ITEM_ATTRIBUTE_DECAYSTATE, true), in fact, that will make the decay to never work
 
Back
Top