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

Life crystals to life rings : Issue with multiple items TFS 1.3

krafttomten

Well-Known Member
Joined
Jul 23, 2017
Messages
103
Solutions
1
Reaction score
75
Location
Sweden
Okay so here's the thing. I have made an altar that turns life crystals into life rings when the crystal is moved onto the altar. Problem is that even if I add more than one life crystal, I will only get one life ring in return.


XML:
<movevent event="AddItem" tileitem="1" actionid="10003" script="lifecrystal.lua" />

Lua:
 -- This is the broken lifecrystal code
function onAddItem(moveitem, tileitem, position)
    if moveitem:getId() == 2177 then
        moveitem:transform(2168)
        position:sendMagicEffect(CONST_ME_MAGIC_GREEN)
        position:sendMagicEffect(CONST_ME_BUBBLES)
    return true
    end
end

Now, I know that I have no code to count items visible here, but that is because I have no idea how to do that. I have compared the code to the dough into bread code that can turn X dough into X bread with no problem. Here is that code, just for reference:

Lua:
 -- This is the working bread code
function onAddItem(moveitem, tileitem, position)
    if moveitem:getId() == 2693 then
        moveitem:transform(2689)
        position:sendMagicEffect(CONST_ME_HITBYFIRE)
    elseif moveitem:getId() == 6277 then
        moveitem:transform(2687, 12)
        position:sendMagicEffect(CONST_ME_HITBYFIRE)
    end
    return true
end

As you can see, that code does not seem to count the items. So the counting must happen somewhere else, right? I can't find it though. I'm thinking the "moveitem" variable contains an amount but I do not know how to access it. Like, moveitem:count() or whatever..

So.. if anyone can help me out I'd appreciate it a lot!
 
Solution
Life rings aren't stackable, so you gotta do it different.
Lua:
function onAddItem(moveitem, tileitem, position)
    if moveitem:getId() == 2177 then
        local amount = moveitem:getCount()
        for i = 1, amount do
            Game.createItem(2168, 1, position)
        end
        moveitem:remove()
        position:sendMagicEffect(CONST_ME_MAGIC_GREEN)
        position:sendMagicEffect(CONST_ME_BUBBLES)
    return true
    end
end
Life rings aren't stackable, so you gotta do it different.
Lua:
function onAddItem(moveitem, tileitem, position)
    if moveitem:getId() == 2177 then
        local amount = moveitem:getCount()
        for i = 1, amount do
            Game.createItem(2168, 1, position)
        end
        moveitem:remove()
        position:sendMagicEffect(CONST_ME_MAGIC_GREEN)
        position:sendMagicEffect(CONST_ME_BUBBLES)
    return true
    end
end
 
Solution
Yes! Thank you so much!

On a side note, how can I find all the references to each object in TFS? Like, moveitem:[this stuff]? My current method is horrible, I simply search around the forums and the game files for any used reference but that cannot be the easiest way to find them
 
Yes! Thank you so much!

On a side note, how can I find all the references to each object in TFS? Like, moveitem:[this stuff]? My current method is horrible, I simply search around the forums and the game files for any used reference but that cannot be the easiest way to find them
luascript.cpp for all your functions.
const.h for effects and messages.
enums.h for combat and conditions.

Those 3 files will have 99% of everything you'll ever need
 
Back
Top