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

RevScripts How to use table with position to register the script?

mano368

Senior Support Team Member
Staff member
Support Team
Joined
Sep 2, 2011
Messages
646
Solutions
46
Reaction score
296
Location
Brazil
How to make a large script with position and not aid or uid?

something like:
Lua:
local ispos = {
    [Position(32479, 31904, 2)] = Position(32478, 31908, 7),
    [Position(32479, 32905, 2)] = Position(32478, 31908, 7)
}
-------------------------------- TELEPORT FOR ITEMS ----------------------------------------
local normalTeleportsItem = MoveEvent()
function normalTeleportsItem.onAddItem(moveitem, tileitem, position)
    local config = ispos[position]
        moveitem:moveTo(config)
        position:sendMagicEffect(CONST_ME_TELEPORT)
  
    return true
end
for i, v in pairs(ispos) do
    normalTeleportsItem:position(i)
end
normalTeleportsItem:register()

And the same with UID and AID, I tried but don't work with aid or uid.

Thanks for the help!
 
Solution
How to make a large script with position and not aid or uid?

something like:
Lua:
local ispos = {
    [Position(32479, 31904, 2)] = Position(32478, 31908, 7),
    [Position(32479, 32905, 2)] = Position(32478, 31908, 7)
}
-------------------------------- TELEPORT FOR ITEMS ----------------------------------------
local normalTeleportsItem = MoveEvent()
function normalTeleportsItem.onAddItem(moveitem, tileitem, position)
    local config = ispos[position]
        moveitem:moveTo(config)
        position:sendMagicEffect(CONST_ME_TELEPORT)
 
    return true
end
for i, v in pairs(ispos) do
    normalTeleportsItem:position(i)
end
normalTeleportsItem:register()

And the same with UID and AID, I tried but don't work with aid or uid....
How to make a large script with position and not aid or uid?

something like:
Lua:
local ispos = {
    [Position(32479, 31904, 2)] = Position(32478, 31908, 7),
    [Position(32479, 32905, 2)] = Position(32478, 31908, 7)
}
-------------------------------- TELEPORT FOR ITEMS ----------------------------------------
local normalTeleportsItem = MoveEvent()
function normalTeleportsItem.onAddItem(moveitem, tileitem, position)
    local config = ispos[position]
        moveitem:moveTo(config)
        position:sendMagicEffect(CONST_ME_TELEPORT)
 
    return true
end
for i, v in pairs(ispos) do
    normalTeleportsItem:position(i)
end
normalTeleportsItem:register()

And the same with UID and AID, I tried but don't work with aid or uid.

Thanks for the help!
Lua:
local ispos = {
    [{x=32479, y=31904, z=2, stackpos=1, uid=1, aid=1}] = {x=32478, y=31908, z=7, stackpos=1, uid=1, aid=1},
    [{x=32479, y=32905, z=2, stackpos=1, uid=1, aid=1}] = {x=32478, y=31908, z=7, stackpos=1, uid=1, aid=1}
}

local normalTeleportsItem = MoveEvent()
function normalTeleportsItem.onAddItem(moveitem, tileitem, position)
    local config = ispos[position]
    if config then
        moveitem:moveTo(config)
        position:sendMagicEffect(CONST_ME_TELEPORT)
    end
    return true
end

for i, v in pairs(ispos) do
    normalTeleportsItem:position(i)
end
normalTeleportsItem:register()
This script defines a table called ispos that maps positions (specified as tables containing X, Y, Z, stack position, UID, and AID values and I guess you can change 1 thou to whatever you have) to other positions. The normalTeleportsItem move event is registered to trigger the onAddItem function when an item is added to one of the specified positions. The onAddItem function then moves the item to the corresponding position in the ispos table and sends a magic effect to the original position to indicate that the item has been teleported.
 
Last edited:
How to make a large script with position and not aid or uid?

something like:
Lua:
local ispos = {
    [Position(32479, 31904, 2)] = Position(32478, 31908, 7),
    [Position(32479, 32905, 2)] = Position(32478, 31908, 7)
}
-------------------------------- TELEPORT FOR ITEMS ----------------------------------------
local normalTeleportsItem = MoveEvent()
function normalTeleportsItem.onAddItem(moveitem, tileitem, position)
    local config = ispos[position]
        moveitem:moveTo(config)
        position:sendMagicEffect(CONST_ME_TELEPORT)
 
    return true
end
for i, v in pairs(ispos) do
    normalTeleportsItem:position(i)
end
normalTeleportsItem:register()

And the same with UID and AID, I tried but don't work with aid or uid.

Thanks for the help!
This would be a way to do it correctly:
Lua:
local config = {
    { fromPos = Position(32479, 31904, 2), toPos = Position(32478, 31908, 7) },
    { fromPos = Position(32479, 32905, 2), toPos = Position(32478, 31908, 7) }
}

local moveEvent = MoveEvent()

function moveEvent.onAddItem(moveItem, tileItem, pos)
    for _, info in pairs(config) do
        if info.fromPos == pos then
            moveItem:moveTo(info.toPos)
            pos:sendDistanceEffect(info.toPos, CONST_ANI_ENERGY)
            info.toPos:sendMagicEffect(CONST_ME_TELEPORT)
            break
        end
    end
    return true
end

for _, info in pairs(config) do
    moveEvent:position(info.fromPos)
end
moveEvent:register()

Note: Just because a table has exactly the same values doesn't mean it's the same table, so adding tables as keys is a bad idea if you're trying to find it with another table with the same properties.
1671844496403.png
They are two completely different objects.

Although in TFS you can compare positions this is nothing more than a trick with the help of a metamethod.
 
Solution
This would be a way to do it correctly:
Lua:
local config = {
    { fromPos = Position(32479, 31904, 2), toPos = Position(32478, 31908, 7) },
    { fromPos = Position(32479, 32905, 2), toPos = Position(32478, 31908, 7) }
}

local moveEvent = MoveEvent()

function moveEvent.onAddItem(moveItem, tileItem, pos)
    for _, info in pairs(config) do
        if info.fromPos == pos then
            moveItem:moveTo(info.toPos)
            pos:sendDistanceEffect(info.toPos, CONST_ANI_ENERGY)
            info.toPos:sendMagicEffect(CONST_ME_TELEPORT)
            break
        end
    end
    return true
end

for _, info in pairs(config) do
    moveEvent:position(info.fromPos)
end
moveEvent:register()

Thank u,
but for aid or uid? how to do? Why the script below work for "onstepin/onstepout" and for "onadditem" don't?

Lua:
local normalSetup = {
    [16500] = {newPos = Position(32187, 31625, 4), newDir = 2},
    [16501] = {newPos = Position(32108, 31567, 9), newDir = 2}
}

local normalTeleports = MoveEvent()
function normalTeleports.onStepIn(creature, item, position, fromPosition)
    local tpConfig = normalSetup[item.actionid]
    local player = creature:getPlayer()

    if not player then
        return true
    end

    position:sendMagicEffect(CONST_ME_TELEPORT)
    player:teleportTo(tpConfig.newPos)
    player:setDirection(tpConfig.newDir)
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)

    return true
end

for i, v in pairs(normalSetup) do
    normalTeleports:aid(i)
end
normalTeleports:register()
 
Back
Top