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

Help me with a solution for my script 1.2

gubbo123

New Member
Joined
Aug 15, 2017
Messages
151
Solutions
1
Reaction score
3
Distribution: The forgotten server 1.2

Hello
i'm looking for help with my rope script, this script is simulating the old rope 7.4...
the script is working, but my problem with this script is the part "allowed_items_inway"...
{2886, 2887, 2889, 2890, 2891, 2895, 2896, 2897, 2898, 2899, 2890} this is pool ids... ok my rope just work with pool ids in hole.

The problem is, if have a pool of blood, wine, etc... in hole, and i put other item "not allowed" on pool my rope is working too...

How can i find a solution for this?

My rope script
LUA:
local OPENED_HOLE = {293, 294, 385, 476, 435, 482, 483, 594, 595, 607, 609, 610, 615, 385, 387, 394}
local OPENED_TRAP = {462, 435}
local DOWN_LADDER = {369, 370, 408, 409, 427, 428, 3135, 3136, 5545, 5763, 412, 432, 433, 435}
local ROPE_SPOT = {386, 421}
local allowed_items_inway = {2886, 2887, 2889, 2890, 2891, 2895, 2896, 2897, 2898, 2899, 2890}
function onUse(cid, item, frompos, item2, topos)
    newPos = {x = topos.x, y = topos.y, z = topos.z, stackpos = 0}
    groundItem = getThingfromPos(newPos)
    blockingItem = getThingfromPos({x = topos.x, y = topos.y, z = topos.z, stackpos = 1})
    if(isInArray(ROPE_SPOT, groundItem.itemid) == TRUE) then
        newPos.y = newPos.y + 1
        newPos.z = newPos.z - 1
        if((blockingItem.itemid > 0 and not isInArray(allowed_items_inway, blockingItem.itemid)) or isCreature(groundItem.uid)) then
           doPlayerSendCancel(cid, "You cannot use this object.")
       else
           doTeleportThing(cid, newPos)
        end
    elseif(isInArray(OPENED_HOLE, groundItem.itemid) == TRUE or isInArray(OPENED_HOLE, item2.itemid) == TRUE or isInArray(OPENED_TRAP, groundItem.itemid) == TRUE or isInArray(DOWN_LADDER, groundItem.itemid) == TRUE) then
        newPos.y = newPos.y + 1
        downPos = {x = topos.x, y = topos.y, z = topos.z + 1, stackpos = 255}
        downItem = getThingfromPos(downPos)
        if(downItem.itemid > 0) then
            doTeleportThing(downItem.uid, newPos)
        else
        end
    end
    return true
end

thanks so much :)
 
Solution
you're using an outdated script
the array in table.contains doesn't exist, ropeSpots is never defined. however, ROPE_SPOTS is (same thing with "notAllowedItems")
try this out:
LUA:
local holeId = {
    294, 369, 370, 383, 392, 408, 409, 410, 427, 428, 429, 430, 462, 469, 470, 482,
    484, 485, 489, 924, 1369, 3135, 3136, 4835, 4837, 7933, 7938, 8170, 8249, 8250,
    8251, 8252, 8254, 8255, 8256, 8276, 8277, 8279, 8281, 8284, 8285, 8286, 8323,
    8567, 8585, 8595, 8596, 8972, 9606, 9625, 13190, 14461, 19519, 21536
}

local allowedItems = {2886, 2887, 2889, 2890, 2891, 2895, 2896, 2897, 2898, 2899, 2890}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local tile = Tile(toPosition)
    if not tile then...
You can check for items in tile, because rope spot is always ground tile.

Code:
local tile = Tile(pos)
if tile then
    if table.contains(ropeSpots, tile:getGround():getId()) then
        local tileItems = tile:getItems()
        if tileItems then
            for _, tileItem in pairs(tileItems) do
                if table.contains(notAllowedItems, tileItem) then
                    return false
                end
            end
        end
        -- here do rope action
    end
end

Something like this should work, it will check every item on tile comparing with not allowed items. You have to declare "notAllowedItems" as table with item ids.
Not tested.
 
i got error on console with this
[Warning - Event::checkScript] Event onUse not found. scripts/misc/rope.lua

LUA:
local tile = Tile(pos)
if tile then
    if table.contains(ropeSpots, tile:getGround():getId()) then
        local tileItems = tile:getItems()
        if tileItems then
            for _, tileItem in pairs(tileItems) do
                if table.contains(notAllowedItems, tileItem) then
                    return false
                end
            end
        end
local OPENED_HOLE = {293, 294, 385, 476, 435, 482, 483, 594, 595, 607, 609, 610, 615, 385, 387, 394}
local OPENED_TRAP = {462, 435}
local DOWN_LADDER = {369, 370, 408, 409, 427, 428, 3135, 3136, 5545, 5763, 412, 432, 433, 435}
local ROPE_SPOT = {386, 421}
local allowed_items_inway = {2886, 2887, 2889, 2890, 2891, 2895, 2896, 2897, 2898, 2899, 2890}
function onUse(cid, item, frompos, item2, topos)
    newPos = {x = topos.x, y = topos.y, z = topos.z, stackpos = 0}
    groundItem = getThingfromPos(newPos)
    blockingItem = getThingfromPos({x = topos.x, y = topos.y, z = topos.z, stackpos = 1})
    if(isInArray(ROPE_SPOT, groundItem.itemid) == TRUE) then
        newPos.y = newPos.y + 1
        newPos.z = newPos.z - 1
        if((blockingItem.itemid > 0 and not isInArray(allowed_items_inway, blockingItem.itemid)) or isCreature(groundItem.uid)) then
           doPlayerSendCancel(cid, "You cannot use this object.")
       else
           doTeleportThing(cid, newPos)
        end
    elseif(isInArray(OPENED_HOLE, groundItem.itemid) == TRUE or isInArray(OPENED_HOLE, item2.itemid) == TRUE or isInArray(OPENED_TRAP, groundItem.itemid) == TRUE or isInArray(DOWN_LADDER, groundItem.itemid) == TRUE) then
        newPos.y = newPos.y + 1
        downPos = {x = topos.x, y = topos.y, z = topos.z + 1, stackpos = 255}
        downItem = getThingfromPos(downPos)
        if(downItem.itemid > 0) then
            doTeleportThing(downItem.uid, newPos)
        else
        end
    end
    return true
end
    end
end

Up
 
Last edited by a moderator:
i got error on console with this
[Warning - Event::checkScript] Event onUse not found. scripts/misc/rope.lua

LUA:
local tile = Tile(pos)
if tile then
    if table.contains(ropeSpots, tile:getGround():getId()) then
        local tileItems = tile:getItems()
        if tileItems then
            for _, tileItem in pairs(tileItems) do
                if table.contains(notAllowedItems, tileItem) then
                    return false
                end
            end
        end
local OPENED_HOLE = {293, 294, 385, 476, 435, 482, 483, 594, 595, 607, 609, 610, 615, 385, 387, 394}
local OPENED_TRAP = {462, 435}
local DOWN_LADDER = {369, 370, 408, 409, 427, 428, 3135, 3136, 5545, 5763, 412, 432, 433, 435}
local ROPE_SPOT = {386, 421}
local allowed_items_inway = {2886, 2887, 2889, 2890, 2891, 2895, 2896, 2897, 2898, 2899, 2890}
function onUse(cid, item, frompos, item2, topos)
    newPos = {x = topos.x, y = topos.y, z = topos.z, stackpos = 0}
    groundItem = getThingfromPos(newPos)
    blockingItem = getThingfromPos({x = topos.x, y = topos.y, z = topos.z, stackpos = 1})
    if(isInArray(ROPE_SPOT, groundItem.itemid) == TRUE) then
        newPos.y = newPos.y + 1
        newPos.z = newPos.z - 1
        if((blockingItem.itemid > 0 and not isInArray(allowed_items_inway, blockingItem.itemid)) or isCreature(groundItem.uid)) then
           doPlayerSendCancel(cid, "You cannot use this object.")
       else
           doTeleportThing(cid, newPos)
        end
    elseif(isInArray(OPENED_HOLE, groundItem.itemid) == TRUE or isInArray(OPENED_HOLE, item2.itemid) == TRUE or isInArray(OPENED_TRAP, groundItem.itemid) == TRUE or isInArray(DOWN_LADDER, groundItem.itemid) == TRUE) then
        newPos.y = newPos.y + 1
        downPos = {x = topos.x, y = topos.y, z = topos.z + 1, stackpos = 255}
        downItem = getThingfromPos(downPos)
        if(downItem.itemid > 0) then
            doTeleportThing(downItem.uid, newPos)
        else
        end
    end
    return true
end
    end
end

Up

Because the code is "out of scope", in other words you need to have the code in the function (onUse(...))
So move it and try again.

You might have to fix some variable names aswell, pos etc
 
where i add this function (onUse ? in actions.xml? or in this script?

It's already in your script?
Check line 18 in the code you posted above.

The code you pasted above (line 2-12) is above onUse = out of scope.
Paste it below and you also removed an "end" at line 13~
 
right now? i'm testing no error in console, but when i use the rope in hole i got this msg You cannot use this object.
LUA:
local OPENED_HOLE = {293, 294, 385, 476, 435, 482, 483, 594, 595, 607, 609, 610, 615, 385, 387, 394}
local OPENED_TRAP = {462, 435}
local DOWN_LADDER = {369, 370, 408, 409, 427, 428, 3135, 3136, 5545, 5763, 412, 432, 433, 435}
local ROPE_SPOT = {386, 421}
local allowed_items_inway = {2886, 2887, 2889, 2890, 2891, 2895, 2896, 2897, 2898, 2899, 2890}
function onUse(cid, item, frompos, item2, topos)
    local tile = Tile(pos)
if tile then
    if table.contains(ropeSpots, tile:getGround():getId()) then
        local tileItems = tile:getItems()
        if tileItems then
            for _, tileItem in pairs(tileItems) do
                if table.contains(notAllowedItems, tileItem) then
                    return false
                end
            end
        end
    newPos = {x = topos.x, y = topos.y, z = topos.z, stackpos = 0}
    groundItem = getThingfromPos(newPos)
    blockingItem = getThingfromPos({x = topos.x, y = topos.y, z = topos.z, stackpos = 1})
    if(isInArray(ROPE_SPOT, groundItem.itemid) == TRUE) then
        newPos.y = newPos.y + 1
        newPos.z = newPos.z - 1
        if((blockingItem.itemid > 0 and not isInArray(allowed_items_inway, blockingItem.itemid)) or isCreature(groundItem.uid)) then
           doPlayerSendCancel(cid, "You cannot use this object.")
       else
           doTeleportThing(cid, newPos)
        end
    elseif(isInArray(OPENED_HOLE, groundItem.itemid) == TRUE or isInArray(OPENED_HOLE, item2.itemid) == TRUE or isInArray(OPENED_TRAP, groundItem.itemid) == TRUE or isInArray(DOWN_LADDER, groundItem.itemid) == TRUE) then
        newPos.y = newPos.y + 1
        downPos = {x = topos.x, y = topos.y, z = topos.z + 1, stackpos = 255}
        downItem = getThingfromPos(downPos)
        if(downItem.itemid > 0) then
            doTeleportThing(downItem.uid, newPos)
        else
        end
    end
    return true
end
    end
end
 
right now? i'm testing no error in console, but when i use the rope in hole i got this msg You cannot use this object.
LUA:
local OPENED_HOLE = {293, 294, 385, 476, 435, 482, 483, 594, 595, 607, 609, 610, 615, 385, 387, 394}
local OPENED_TRAP = {462, 435}
local DOWN_LADDER = {369, 370, 408, 409, 427, 428, 3135, 3136, 5545, 5763, 412, 432, 433, 435}
local ROPE_SPOT = {386, 421}
local allowed_items_inway = {2886, 2887, 2889, 2890, 2891, 2895, 2896, 2897, 2898, 2899, 2890}
function onUse(cid, item, frompos, item2, topos)
    local tile = Tile(pos)
if tile then
    if table.contains(ropeSpots, tile:getGround():getId()) then
        local tileItems = tile:getItems()
        if tileItems then
            for _, tileItem in pairs(tileItems) do
                if table.contains(notAllowedItems, tileItem) then
                    return false
                end
            end
        end
    newPos = {x = topos.x, y = topos.y, z = topos.z, stackpos = 0}
    groundItem = getThingfromPos(newPos)
    blockingItem = getThingfromPos({x = topos.x, y = topos.y, z = topos.z, stackpos = 1})
    if(isInArray(ROPE_SPOT, groundItem.itemid) == TRUE) then
        newPos.y = newPos.y + 1
        newPos.z = newPos.z - 1
        if((blockingItem.itemid > 0 and not isInArray(allowed_items_inway, blockingItem.itemid)) or isCreature(groundItem.uid)) then
           doPlayerSendCancel(cid, "You cannot use this object.")
       else
           doTeleportThing(cid, newPos)
        end
    elseif(isInArray(OPENED_HOLE, groundItem.itemid) == TRUE or isInArray(OPENED_HOLE, item2.itemid) == TRUE or isInArray(OPENED_TRAP, groundItem.itemid) == TRUE or isInArray(DOWN_LADDER, groundItem.itemid) == TRUE) then
        newPos.y = newPos.y + 1
        downPos = {x = topos.x, y = topos.y, z = topos.z + 1, stackpos = 255}
        downItem = getThingfromPos(downPos)
        if(downItem.itemid > 0) then
            doTeleportThing(downItem.uid, newPos)
        else
        end
    end
    return true
end
    end
end

Then the script is returning false, maybe here?
LUA:
if table.contains(notAllowedItems, tileItem) then
You can add this to make sure it's the correct id;
LUA:
print(tileItem, table.contains(table.contains(notAllowedItems, tileItem)))

Should print the itemid and true.
If it prints false the itemid isn't in the array.
 
in line 14 i need replace it ?
LUA:
 print(tileItem, table.contains(table.contains(notAllowedItems, tileItem)))
or add below?
 
LUA:
local OPENED_HOLE = {293, 294, 385, 476, 435, 482, 483, 594, 595, 607, 609, 610, 615, 385, 387, 394}
local OPENED_TRAP = {462, 435}
local DOWN_LADDER = {369, 370, 408, 409, 427, 428, 3135, 3136, 5545, 5763, 412, 432, 433, 435}
local ROPE_SPOT = {386, 421}
local allowed_items_inway = {2886, 2887, 2889, 2890, 2891, 2895, 2896, 2897, 2898, 2899, 2890}
function onUse(cid, item, frompos, item2, topos)
    local tile = Tile(pos)
if tile then
    if table.contains(ropeSpots, tile:getGround():getId()) then
        local tileItems = tile:getItems()
        if tileItems then
            for _, tileItem in pairs(tileItems) do
                if table.contains(notAllowedItems, tileItem) then
                  print(tileItem, table.contains(table.contains(notAllowedItems, tileItem)))
                       return false
                   end
            end
        end
    newPos = {x = topos.x, y = topos.y, z = topos.z, stackpos = 0}
    groundItem = getThingfromPos(newPos)
    blockingItem = getThingfromPos({x = topos.x, y = topos.y, z = topos.z, stackpos = 1})
    if(isInArray(ROPE_SPOT, groundItem.itemid) == TRUE) then
        newPos.y = newPos.y + 1
        newPos.z = newPos.z - 1
        if((blockingItem.itemid > 0 and not isInArray(allowed_items_inway, blockingItem.itemid)) or isCreature(groundItem.uid)) then
           doPlayerSendCancel(cid, "You cannot use this object.")
       else
           doTeleportThing(cid, newPos)
        end
    elseif(isInArray(OPENED_HOLE, groundItem.itemid) == TRUE or isInArray(OPENED_HOLE, item2.itemid) == TRUE or isInArray(OPENED_TRAP, groundItem.itemid) == TRUE or isInArray(DOWN_LADDER, groundItem.itemid) == TRUE) then
        newPos.y = newPos.y + 1
        downPos = {x = topos.x, y = topos.y, z = topos.z + 1, stackpos = 255}
        downItem = getThingfromPos(downPos)
        if(downItem.itemid > 0) then
            doTeleportThing(downItem.uid, newPos)
        else
        end
    end
    return true
end
    end
end

I added but no show any msg in console and my rope don't work
 
Last edited by a moderator:
you're using an outdated script
the array in table.contains doesn't exist, ropeSpots is never defined. however, ROPE_SPOTS is (same thing with "notAllowedItems")
try this out:
LUA:
local holeId = {
    294, 369, 370, 383, 392, 408, 409, 410, 427, 428, 429, 430, 462, 469, 470, 482,
    484, 485, 489, 924, 1369, 3135, 3136, 4835, 4837, 7933, 7938, 8170, 8249, 8250,
    8251, 8252, 8254, 8255, 8256, 8276, 8277, 8279, 8281, 8284, 8285, 8286, 8323,
    8567, 8585, 8595, 8596, 8972, 9606, 9625, 13190, 14461, 19519, 21536
}

local allowedItems = {2886, 2887, 2889, 2890, 2891, 2895, 2896, 2897, 2898, 2899, 2890}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local tile = Tile(toPosition)
    if not tile then
        return false
    end

    local hasAllowedItem = false
    for i = 1, #allowedItems do
        if tile:getItemById(allowedItems[i]) then
            hasAllowedItem = true
            break
        end
    end

    if isInArray(ropeSpots, tile:getGround():getId()) or tile:getItemById(14435) or hasAllowedItem then
        if Tile(toPosition:moveUpstairs()):hasFlag(TILESTATE_PROTECTIONZONE) and player:isPzLocked() then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_PLAYERISPZLOCKED))
            return true
        end
        player:teleportTo(toPosition, false)
        return true
    elseif isInArray(holeId, target.itemid) then
        toPosition.z = toPosition.z + 1
        tile = Tile(toPosition)
        if tile then
            local thing = tile:getTopVisibleThing()
            if thing:isPlayer() then
                if Tile(toPosition:moveUpstairs()):hasFlag(TILESTATE_PROTECTIONZONE) and thing:isPzLocked() then
                    return false
                end
                return thing:teleportTo(toPosition, false)
            end
            if thing:isItem() and thing:getType():isMovable() then
                return thing:moveTo(toPosition:moveUpstairs())
            end
        end
        player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return true
    end
    return false
end
 
Solution
Back
Top