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

Lua Teleport character if the bodies are in the correct places.

MorganaSacani

Active Member
Joined
Sep 20, 2022
Messages
87
Solutions
1
Reaction score
32
I need help shortening the script.
I know that there is a possibility to do it by loop, but I don't know how.
I need this algorithm to scan three bodies at three specific positions.
If all three bodies are in the correct position, the script will work.

Lua:
local config = {
    goToPosition = { x = 100, y = 100, z = 7 },
    corpseId = 2821,
    corpse1 = { x = 100, y = 100, z = 7 },
    corpse2 = { x = 100, y = 100, z = 7 },
    corpse3 = { x = 100, y = 100, z = 7 },
}

local check, c1, c2, c3 = 0, 0, 0, 0
function onStepIn(creature, item, position, fromPosition)
    local player = Player(creature)
    if not player:isPlayer() then return false end

    local corpse1Item = Tile(config.corpse1):getItemById(config.corpseId)
    if corpse1Item then c1 = 1 end

    local corpse2Item = Tile(config.corpse2):getItemById(config.corpseId)
    if corpse2Item then c2 = 1 end

    local corpse3Item = Tile(config.corpse3):getItemById(config.corpseId)
    if corpse3Item then c3 = 1 end

    check = c1 + c2 + c3
    if check == 3 then
        player:teleportTo(config.goToPosition)
        corpse1Item:remove()
        corpse2Item:remove()
        corpse3Item:remove()
    end
    check = 0

    return true
end
 
Lua:
local config = {
    ["itemId"] = 2821, -- corpse
    ["tp"] = Position(100,100,7),
    ["positions"] = {
        Position(100,100,7),
        Position(100,100,7),
        Position(100,100,7)
    }
}

function onStepIn(creature, item, pos, fromPosition)
    if not creature:isPlayer() then
        return false
    end

    for _, position in pairs(config.positions) do
        local tile = Tile(position)
        if not tile then
            return false
        end

        if not tile:getItemById(config.itemId) then
            return false
        end
    end

    creature:teleportTo(config.tp, true)
    creature:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    return true
end
 
Back
Top