• 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+ addevent for lever

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
922
Location
Chile
Hello guys, i have tfs 1.3, and im trying to add an addevent so lever goes back to it's original position and also the floor (this is from lighthouse quest) but i can't make it work, anyone knows why im failing??

LUA:
if item.itemid == 1945 then
                laddertile:getItemById(9021):transform(8280)
                item:transform(1946)
                addEvent(function(laddertile, Tile)
            laddertile:getItemById(8280):transform(9021)      -- Create pillar
            laddertile:sendMagicEffect(CONST_ME_POFF) -- Send POFF effect
            item:transform(1945)                    -- Flip lever to the left
        end, 3000, laddertile:getPosition(), Tile(toPosition):getItemById(1946))
            else
                laddertile:getItemById(8280):transform(9021)
                item:transform(1945)
            end

and the error is

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/quests/thaislighthouselever.lua:onUse
luaAddEvent(). Argument #4 is unsafe
stack traceback:
        [C]: in function 'addEvent'
        data/actions/scripts/quests/thaislighthouselever.lua:8: in function <data/actions/scripts/quests/thaislighthouselever.lua:1>

Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/actions/scripts/quests/thaislighthouselever.lua:9: attempt to call method 'getItemById' (a nil value)
stack traceback:
        [C]: in function 'getItemById'
        data/actions/scripts/quests/thaislighthouselever.lua:9: in function <data/actions/scripts/quests/thaislighthouselever.lua:8>
 
Solution
LUA:
if item:getId() == 1945 then
    laddertile:getItemById(9021):transform(8280)
    item:transform(1946)
    addEvent(function(leverPos, pillarPos)
        local tile = Tile(pillarPos)
        if tile then
            tile:getItemById(8280):transform(9021)
            pillarPos:sendMagicEffect(CONST_ME_POFF)
            Tile(leverPos):getItemById(1946):transform(1945) 
        end
    end, 3000, fromPosition, laddertile:getPosition())
else
    laddertile:getItemById(8280):transform(9021)
    item:transform(1945)
end
you need to pass the position and get the item again instead of passing the item userdata (which is unsafe)
LUA:
if item:getId() == 1945 then
    laddertile:getItemById(9021):transform(8280)
    item:transform(1946)
    addEvent(function(leverPos, pillarPos)
        local tile = Tile(pillarPos)
        if tile then
            tile:getItemById(8280):transform(9021)
            tile:sendMagicEffect(CONST_ME_POFF)
            Tile(leverPos):getItemById(1946):transform(1945) 
        end
    end, 1000, fromPosition, laddertile:getPosition())
else
    laddertile:getItemById(8280):transform(9021)
    item:transform(1945)
end
 
you need to pass the position and get the item again instead of passing the item userdata (which is unsafe)
LUA:
if item:getId() == 1945 then
    laddertile:getItemById(9021):transform(8280)
    item:transform(1946)
    addEvent(function(leverPos, pillarPos)
        local tile = Tile(pillarPos)
        if tile then
            tile:getItemById(8280):transform(9021)
            tile:sendMagicEffect(CONST_ME_POFF)
            Tile(leverPos):getItemById(1946):transform(1945)
        end
    end, 1000, fromPosition, laddertile:getPosition())
else
    laddertile:getItemById(8280):transform(9021)
    item:transform(1945)
end
hey thanks for the reply!

look this is what happens now, i right click the lever, the stais appears, and removed in 1 second, but the lever doesnt go back to it's original position and i get this error after i use the lever, oh also no Poff effect

Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/actions/scripts/quests/thaislighthouselever.lua:12: attempt to call method 'sendMagicEffect' (a nil value)
stack traceback:
        [C]: in function 'sendMagicEffect'
        data/actions/scripts/quests/thaislighthouselever.lua:12: in function <data/actions/scripts/quests/thaislighthouselever.lua:8>
 
LUA:
if item:getId() == 1945 then
    laddertile:getItemById(9021):transform(8280)
    item:transform(1946)
    addEvent(function(leverPos, pillarPos)
        local tile = Tile(pillarPos)
        if tile then
            tile:getItemById(8280):transform(9021)
            pillarPos:sendMagicEffect(CONST_ME_POFF)
            Tile(leverPos):getItemById(1946):transform(1945) 
        end
    end, 3000, fromPosition, laddertile:getPosition())
else
    laddertile:getItemById(8280):transform(9021)
    item:transform(1945)
end
 
Solution
Back
Top