• 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
360
Solutions
1
Reaction score
76
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
 
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
@Xikini
LOL
1.png
Post automatically merged:

@Xikini I found other code is working the way I would like. But there's only one problem... see the image below, the player doesn't go up 2 stairs


Lua:
local UP_FLOORS = {1386, 3678, 5543, 8599, 10035, 13010}
local FIELDS = {1497, 1499, 11095, 11096}
local DRAW_WELL = 1369
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
if(item.itemid == DRAW_WELL and item.actionid ~= 100) then
return false
end
 
local check = false
fromPosition.stackpos = STACKPOS_GROUND
if(isInArray(UP_FLOORS, item.itemid)) then
fromPosition.z = fromPosition.z - 1
fromPosition.y = fromPosition.y + 1
if(doTileQueryAdd(cid, fromPosition, 38) ~= RETURNVALUE_NOERROR) then
local field = getTileItemByType(fromPosition, ITEM_TYPE_MAGICFIELD)
if(field.uid == 0 or not isInArray(FIELDS, field.itemid)) then
fromPosition.y = fromPosition.y - 2
else
check = true
end
end
else
fromPosition.z = fromPosition.z + 1
end
 
if(not check and doTileQueryAdd(cid, fromPosition, 38) ~= RETURNVALUE_NOERROR) then
local field = getTileItemByType(fromPosition, ITEM_TYPE_MAGICFIELD)
if(field.uid == 0 or not isInArray(FIELDS, field.itemid)) then
return false
end
end
 
local pos, dir = getCreaturePosition(cid), SOUTH
if(pos.x < fromPosition.x) then
dir = EAST
elseif(pos.x == fromPosition.x) then
if(pos.y == fromPosition.y) then
dir = getCreatureLookDirection(cid)
elseif(pos.y > fromPosition.y) then
dir = NORTH
end
elseif(pos.x > fromPosition.x) then
dir = WEST
end
 
doTeleportThing(cid, fromPosition, false)
doCreatureSetLookDirection(cid, dir)
return true
end


2.png
Post automatically merged:

3.png
 
Last edited:
Back
Top