• 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 Ladder spawn

Forkz

Well-Known Member
Joined
Jun 29, 2020
Messages
380
Solutions
1
Reaction score
89
Hi otlanders,
my ladder spawn script is the one below
Lua:
local upFloorIds = {1386, 3678, 5543}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isInArray(upFloorIds, item.itemid) == TRUE then
        fromPosition.y = fromPosition.y + 1
        fromPosition.z = fromPosition.z - 1
    else
        fromPosition.z = fromPosition.z + 1
    end
    doTeleportThing(cid, fromPosition, FALSE)
    return TRUE
end
As the image below, I wanted that when there was some "item" disturbing the character spawn at the front of the stairs


25ec026ee319ddcec89fecf30d832ee2.png
 
Try this
Lua:
local upFloorIds = {1386, 3678, 5543}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isInArray(upFloorIds, item.itemid) == TRUE then
        fromPosition.y = fromPosition.y + 1
        fromPosition.z = fromPosition.z - 1
    elseif (isInArray(upFloorIds, item.itemid) == TRUE and Tile(fromPosition):hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID)) then
        fromPosition.y = fromPosition.y - 1
        fromPosition.z = fromPosition.z - 1
    else
        fromPosition.z = fromPosition.z + 1
    end
    doTeleportThing(cid, fromPosition, FALSE)
    return TRUE
end
Not working @M0ustafa , my source OTX2
 
Edited, Try it now
Edit : OTX2, I don't remember the functions, I can check tonight if no one helped
removed my script.
 
Last edited:
I'd try something like this...
I'm basically just assuming you're using a ladder.

Editing the code to remove the bugs based on @StreamSide 's suggestion.
Lua:
function isWalkable(cid, pos)
    pos.stackpos = 0
    if getTileThingByPos(pos).uid ~= 0 then
        local n = getTileInfo(pos)
        if n.protection == false and n.house == false and getTopCreature(pos).uid == 0 and doTileQueryAdd(cid, pos) == RETURNVALUE_NOERROR then
            return true
        end
        return false
    end
    return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local teleportPosition = {x = fromPosition.x, y = fromPosition.y + 1, z = fromPosition.z - 1}
    if not isWalkable(cid, teleportPosition) then
        teleportPosition.y = teleportPosition.y - 2
    end
    doTeleportThing(cid, teleportPosition)
    return true
end
 
Last edited:
I'd try something like this...
I'm basically just assuming you're using a ladder.

Lua:
function isWalkable(cid, pos)
    pos.stackpos = 0
    if getTileThingByPos(pos).uid ~= 0 then
        local n = getTileInfo(pos)
        if n.protection == false and n.house == false and getTopCreature(pos).uid == 0 and doTileQueryAdd(cid, pos) == RETURNVALUE_NOERROR then
            return true
        end
        return false
    end
    return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local teleportPosition = {fromPosition.x, fromPosition.y + 1, fromPosition.z + 1}
    if not isWalkable(cid, teleportPosition) then
        teleportPosition.y = teleportPosition.y - 2
    end
    doTeleportThing(cid, teleportPosition)
    return true
end
@Xikini thanks for trying to help me

1.png
 
I'd try something like this...
I'm basically just assuming you're using a ladder.

Lua:
function isWalkable(cid, pos)
    pos.stackpos = 0
    if getTileThingByPos(pos).uid ~= 0 then
        local n = getTileInfo(pos)
        if n.protection == false and n.house == false and getTopCreature(pos).uid == 0 and doTileQueryAdd(cid, pos) == RETURNVALUE_NOERROR then
            return true
        end
        return false
    end
    return false
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local teleportPosition = {fromPosition.x, fromPosition.y + 1, fromPosition.z + 1}
    if not isWalkable(cid, teleportPosition) then
        teleportPosition.y = teleportPosition.y - 2
    end
    doTeleportThing(cid, teleportPosition)
    return true
end

Lua:
local teleportPosition = { x = fromPosition.x, y = fromPosition.y + 1, z = fromPosition.z + 1}

you guys forgot its otx2 so position is a table
 
Last edited:
The character is teleported to the floor below
I mean I just corrected the position table declaration, but Z is floors so you might want to edit the Y and remove the Z

Lua:
local teleportPosition = { x = fromPosition.x, y = fromPosition.y + 1, z = fromPosition.z}
 
I mean I just corrected the position table declaration, but Z is floors so you might want to edit the Y and remove the Z

Lua:
local teleportPosition = { x = fromPosition.x, y = fromPosition.y + 1, z = fromPosition.z}
he is going up the stairs and falling automatically
 
Why doesn't this work?

Lua:
local upFloorIds = {1386, 3678, 5543}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if isInArray(upFloorIds, item.itemid) then
        fromPosition.y = fromPosition.y - 1
        fromPosition.z = fromPosition.z - 1
    else
        fromPosition.z = fromPosition.z + 1
    end
    
    if Tile(fromPosition) then
        doTeleportThing(cid, fromPosition, FALSE)
    end
    return TRUE
end
 
Back
Top