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

Lua Tomb onAddItem

Sigoles

Discord: @sigoles
Joined
Nov 20, 2015
Messages
1,209
Solutions
2
Reaction score
154
code:
LUA:
function onAddItem(moveitem, tileitem, pos, cid)
    local coins = {
            [9033] = {frompos = {x= 33097,y= 32816,z = 13}, topos = {x= 33093,y= 32824,z = 13}},
            [9034] = {frompos = {x= 33293,y= 32742,z = 13}, topos = {x= 33299,y= 32742,z = 13}},
            [9035] = {frompos = {x= 33073,y= 32590,z = 13}, topos = {x= 33080,y= 32588,z = 13}},
            [9036] = {frompos = {x= 33240,y= 32856,z = 13}, topos = {x= 33246,y= 32850,z = 13}},
            [9037] = {frompos = {x= 33276,y= 32553,z = 14}, topos = {x= 33271,y= 32553,z = 14}},
            [9038] = {frompos = {x= 33234,y= 32692,z = 13}, topos = {x= 33234,y= 32687,z = 13}},
            [9039] = {frompos = {x= 33135,y= 32683,z = 12}, topos = {x= 33130,y= 32683,z = 12}},
            [9040] = {frompos = {x= 33162,y= 32831,z = 10}, topos = {x= 33158,y= 32832,z = 10}}
          
            }
   
    if moveitem.itemid == 2159 then
        doRemoveItem(moveitem.uid)
        doSendMagicEffect(pos, CONST_ME_HITBYFIRE)
        doSendMagicEffect(coins[tileitem.uid].frompos, CONST_ME_TELEPORT)       
        doRelocate(coins[tileitem.uid].frompos,coins[tileitem.uid].topos)
        doSendMagicEffect(coins[tileitem.uid].topos, CONST_ME_TELEPORT)
    end
    return true
end


error:
Code:
Lua Script Error: [MoveEvents Interface]
data/movements/scripts/others/tombCoalBasin.lua:onAddItem
data/movements/scripts/others/tombCoalBasin.lua:17: attempt to index a nil value
stack traceback:
    [C]: in function '__index'
    data/movements/scripts/others/tombCoalBasin.lua:17: in function <data/movements/scripts/others/tombCoalBasin.lua:1>

tfs 1.3
 
a tip for using repetitive indexed variables is saving it in another local variable :)
another tip is using print to view values in the console
print("a comment if you wish", variable)

not sure if this works but instead of .uid getting uniqueid by tileitem:getUniqueId()
Code:
function onAddItem(moveitem, tileitem, pos, cid)
    local coins = {
            [9033] = {frompos = {x= 33097,y= 32816,z = 13}, topos = {x= 33093,y= 32824,z = 13}},
            [9034] = {frompos = {x= 33293,y= 32742,z = 13}, topos = {x= 33299,y= 32742,z = 13}},
            [9035] = {frompos = {x= 33073,y= 32590,z = 13}, topos = {x= 33080,y= 32588,z = 13}},
            [9036] = {frompos = {x= 33240,y= 32856,z = 13}, topos = {x= 33246,y= 32850,z = 13}},
            [9037] = {frompos = {x= 33276,y= 32553,z = 14}, topos = {x= 33271,y= 32553,z = 14}},
            [9038] = {frompos = {x= 33234,y= 32692,z = 13}, topos = {x= 33234,y= 32687,z = 13}},
            [9039] = {frompos = {x= 33135,y= 32683,z = 12}, topos = {x= 33130,y= 32683,z = 12}},
            [9040] = {frompos = {x= 33162,y= 32831,z = 10}, topos = {x= 33158,y= 32832,z = 10}}
   
            }
 
    if moveitem.itemid == 2159 then
        local coin = coins[tileitem:getUniqueId()]
        if coin then
          doRemoveItem(moveitem.uid)
          doSendMagicEffect(pos, CONST_ME_HITBYFIRE)
          doSendMagicEffect(coin.frompos, CONST_ME_TELEPORT)
          doRelocate(coin.frompos, coin.topos)
          doSendMagicEffect(coin.topos, CONST_ME_TELEPORT)
        end
    end
    return true
end

Make sure the item you put the coin on has a unique id
 
Last edited:
Back
Top