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

TFS 1.X+ Looking for decay function.

Udun

Well-Known Member
Joined
Jan 5, 2012
Messages
192
Solutions
1
Reaction score
67
Hello guys I'm trying to implement a crafting system based on mill and decay items.
TFS 1.2

I was looking on the forum if there was a post with the same problem but I didn't find anything.
I'm getting some problems:

When the item is generated via map editor the decay works fine but when is generated by code it doesn't work.
I was looking that I need "activate" the decay when the item is generated via code but I don't know how to do it right. I did some test with some functions of other posts but with no success. Probably is an easy fix.

My mill code:
Lua:
local liquidContainers = {1775, 2005, 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2023, 2031, 2032, 2033}
local millstones = {28369}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    if itemId == 28395 then --tin dust
        if target.type == 1 and isInArray(liquidContainers, target.itemid) then
            item:remove(1)
            player:addItem(28395, 1)
            target:transform(target.itemid, 0)
            return true
        end
    elseif isInArray(millstones, target.itemid) then
        item:remove(1)
        player:addItem(28395, 1)
        return true
    end
    return false
end

The item on items.xml
XML:
    <item id="28395" article="a" name="tin dust">
        <attribute key="weight" value="400" />
        <attribute key="decayTo" value="28398" />
        <attribute key="duration" value="2" />
    </item>

Thanks in advance!
 
Solution
hey xikini how are you :)
this is how it works on this case:
the script is for the mill to process
tin ore is --> that's converted in tin dust (item id 28395), once is created after 2 seconds it has to be transformed by decaying in the item id 28398 (that also is tin dust with the same sprite but different id (but identical copy of the first)) why do I need this? because after convert the tin ore in tin dust I need to use the tin dust in a NEW MILL (this time is an oven sprite) to converted it in a tin ingot, if I use the same id in the 2 mill scripts the scripts enter in conflict and dosen't work, so that's why.

Also I need to achieve this to the next step of the tin ingot when is created because it will be a "blazing tin ingot"...
target:decay()
well im trying but it doesn't work xD
sorry i'm still noob on this, I have done some tests in different ways but the last time I placed it like this (not working so far):


Lua:
local liquidContainers = {1775, 2005, 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2023, 2031, 2032, 2033}
local millstones = {28369}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    if itemId == 28395 then --tin dust
        if target.type == 1 and isInArray(liquidContainers, target.itemid) then
            item:remove(1)
            player:addItem(28395, 1)
            target:transform(target.itemid, 0)
            target:decay(target.itemid, 0)
            return true
        end
    elseif isInArray(millstones, target.itemid) then
        item:remove(1)
        player:addItem(28395, 1)
        target:decay(target.itemid, 0)
        return true
    end
    return false
end
 
item:decay(decayId)

the required parameter is the itemid where it will decay, not the same ID and not more parameters
in case you want it to disappear, just use: target:decay(0)
 
it need to be used after the transform, look this:
Correct, passing it an extra parameter alters its decay ItemId
C++:
int LuaScriptInterface::luaItemDecay(lua_State* L)
{
    // item:decay(decayId)
    Item* item = getUserdata<Item>(L, 1);
    if (item) {
        if (isNumber(L, 2)) {
            item->setDecayTo(getNumber<int32_t>(L, 2));
        }

        g_game.startDecay(item);
        pushBoolean(L, true);
    }
    else {
        lua_pushnil(L);
    }
    return 1;
}
 
@Sarah Wesker @Evil Puncker

So as you said I did it like this:
Lua:
local liquidContainers = {1775, 2005, 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2023, 2031, 2032, 2033}
local millstones = {28369}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    if itemId == 28395 then --tin dust
        if target.type == 1 and isInArray(liquidContainers, target.itemid) then
            item:remove(1)
            player:addItem(28395, 1)
            target:transform(target.itemid, 0)
            target:decay(28398)
            return true
        end
    elseif isInArray(millstones, target.itemid) then
        item:remove(1)
        player:addItem(28395, 1)
        return true
    end
    return false
end

Sitll not working but I noticed something when I relog with the char the item appear decayed, but not at the moment of the transform in the mill (that's what I need)

@Sarah Wesker do I have to place that code somewhere? and the decay should be to another item, not to 0
 
Last edited:
Lua:
local liquidContainers = {1775, 2005, 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2023, 2031, 2032, 2033}
local millstones = {28369}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    if itemId == 28395 then --tin dust
        if target.type == 1 and isInArray(liquidContainers, target.itemid) then
            item:remove(1)
            player:addItem(28395, 1)
            target:transform(target.itemid, 0)
            target:decay()
            return true
        end
    elseif isInArray(millstones, target.itemid) then
        item:remove(1)
        player:addItem(28395, 1)
        return true
    end
    return false
end
 
Lua:
local liquidContainers = {1775, 2005, 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2023, 2031, 2032, 2033}
local millstones = {28369}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    if itemId == 28395 then --tin dust
        if target.type == 1 and isInArray(liquidContainers, target.itemid) then
            item:remove(1)
            player:addItem(28395, 1)
            target:transform(target.itemid, 0)
            target:decay()
            return true
        end
    elseif isInArray(millstones, target.itemid) then
        item:remove(1)
        player:addItem(28395, 1)
        return true
    end
    return false
end
already tried that :U
 
What item is supposed to be decaying?

or rather, what is supposed to happen in this script, from start to finish?
I don't understand the system.
hey xikini how are you :)
this is how it works on this case:
the script is for the mill to process
tin ore is --> that's converted in tin dust (item id 28395), once is created after 2 seconds it has to be transformed by decaying in the item id 28398 (that also is tin dust with the same sprite but different id (but identical copy of the first)) why do I need this? because after convert the tin ore in tin dust I need to use the tin dust in a NEW MILL (this time is an oven sprite) to converted it in a tin ingot, if I use the same id in the 2 mill scripts the scripts enter in conflict and dosen't work, so that's why.

Also I need to achieve this to the next step of the tin ingot when is created because it will be a "blazing tin ingot" has to decay after few seconds to a cooled tin ingot.
 
hey xikini how are you :)
this is how it works on this case:
the script is for the mill to process
tin ore is --> that's converted in tin dust (item id 28395), once is created after 2 seconds it has to be transformed by decaying in the item id 28398 (that also is tin dust with the same sprite but different id (but identical copy of the first)) why do I need this? because after convert the tin ore in tin dust I need to use the tin dust in a NEW MILL (this time is an oven sprite) to converted it in a tin ingot, if I use the same id in the 2 mill scripts the scripts enter in conflict and dosen't work, so that's why.

Also I need to achieve this to the next step of the tin ingot when is created because it will be a "blazing tin ingot" has to decay after few seconds to a cooled tin ingot.
There's no reason why you need the new sprite, because you can just verify what item it's being used on.

But regardless, this is what you'll want to do.

Lua:
local liquidContainers = {1775, 2005, 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2023, 2031, 2032, 2033}
local millstones = {28369}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
	
	local itemId = item:getId() -- not required, because you're only using it once. Just put item:getId() into the if statement directly.
	
	-- you didn't explain what liquid is used for, so I'm not touching this part.
	if itemId == 28395 then -- tin dust
		if target.type == 1 and isInArray(liquidContainers, target.itemid) then
			item:remove(1)
			player:addItem(28395, 1) -- why are you removing tin dust, then adding the same item back to the player?
			target:transform(target.itemid, 0) -- instead of removing the entire object, you should just remove the liquid from the container
			return true
		end
		
	-- the actual part you're trying to convert tin ore into tin dust
	elseif isInArray(millstones, target.itemid) then
		item:remove(1) -- removing tin ore
		local tinDust = player:addItem(28395, 1) -- adding the tin dust
		tinDust:decay() -- start decay of item
		return true
	end
	
	return false
end
 
Solution
There's no reason why you need the new sprite, because you can just verify what item it's being used on.

But regardless, this is what you'll want to do.

Lua:
local liquidContainers = {1775, 2005, 2006, 2007, 2008, 2009, 2011, 2012, 2013, 2014, 2015, 2023, 2031, 2032, 2033}
local millstones = {28369}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
   
    local itemId = item:getId() -- not required, because you're only using it once. Just put item:getId() into the if statement directly.
   
    -- you didn't explain what liquid is used for, so I'm not touching this part.
    if itemId == 28395 then -- tin dust
        if target.type == 1 and isInArray(liquidContainers, target.itemid) then
            item:remove(1)
            player:addItem(28395, 1) -- why are you removing tin dust, then adding the same item back to the player?
            target:transform(target.itemid, 0) -- instead of removing the entire object, you should just remove the liquid from the container
            return true
        end
       
    -- the actual part you're trying to convert tin ore into tin dust
    elseif isInArray(millstones, target.itemid) then
        item:remove(1) -- removing tin ore
        local tinDust = player:addItem(28395, 1) -- adding the tin dust
        tinDust:decay() -- start decay of item
        return true
    end
   
    return false
end
OMG this worked as a charm! :D
thank you very much!
btw the liquid part is for just in case I want to create new item with liquid (for example water) but is not used on this case

thankss all:
@Xikini @Sarah Wesker @Evil Puncker for the help! Are the bests!
 
OMG this worked as a charm! :D
thank you very much!
btw the liquid part is for just in case I want to create new item with liquid (for example water) but is not used on this case

thankss all:
@Xikini @Sarah Wesker @Evil Puncker for the help! Are the bests!
it was nothing we just tried to answer your main question!
 
@Udun

Is this a private "mill" system, or are you using something already in the game?
oh no is just the classic mill of bread system (maybe is in all ots by default), but all the items are custom
Post automatically merged:

it was nothing we just tried to answer your main question!
well, the intention is important, I'm always grateful with the people that try to help me :)
so thank you
 
Last edited:
Back
Top