• 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 Help to implement old rope 7.4

Jhon_

Well-Known Member
Joined
May 7, 2019
Messages
58
Reaction score
61
Can anyone here help me to change this script to work like the 7.4 rope? Can't use it if there is a monster/player/items over the spot where you use the rope?
LUA:
function onUseRope(player, item, fromPosition, target, toPosition)
    local tile = Tile(toPosition)
    if not tile then
        return false
    end
    
    local itemType = ItemType(target.itemid)
    if itemType and itemType:getGroup() == ITEM_GROUP_SPLASH then
        target = tile:getGround()
    end

    if table.contains(ropeSpots, target.itemid) then
        tile = Tile(toPosition:moveUpstairs())
        if not tile then
            return false
        end

        if tile:hasFlag(TILESTATE_PROTECTIONZONE) and player:isPzLocked() then
            player:sendCancelMessage(RETURNVALUE_PLAYERISPZLOCKED)
            return true
        end

        player:teleportTo(toPosition, false)
        return true
    end

    if table.contains(holeId, target.itemid) then
        toPosition.z = toPosition.z + 1
        tile = Tile(toPosition)
        if not tile then
            return false
        end

        local thing = tile:getBottomCreature() or tile:getTopDownItem()
        if not thing then
            return true
        end

        if thing:isCreature() then
            return thing:teleportTo(toPosition:moveUpstairs(), false)
        elseif thing:isItem() and thing:getType():isMovable() then
            return thing:moveTo(toPosition:moveUpstairs())
        end

        return true
    end

    return false
end
 
Can anyone here help me to change this script to work like the 7.4 rope? Can't use it if there is a monster/player/items over the spot where you use the rope?
LUA:
function onUseRope(player, item, fromPosition, target, toPosition)
    local tile = Tile(toPosition)
    if not tile then
        return false
    end
   
    local itemType = ItemType(target.itemid)
    if itemType and itemType:getGroup() == ITEM_GROUP_SPLASH then
        target = tile:getGround()
    end

    if table.contains(ropeSpots, target.itemid) then
        tile = Tile(toPosition:moveUpstairs())
        if not tile then
            return false
        end

        if tile:hasFlag(TILESTATE_PROTECTIONZONE) and player:isPzLocked() then
            player:sendCancelMessage(RETURNVALUE_PLAYERISPZLOCKED)
            return true
        end

        player:teleportTo(toPosition, false)
        return true
    end

    if table.contains(holeId, target.itemid) then
        toPosition.z = toPosition.z + 1
        tile = Tile(toPosition)
        if not tile then
            return false
        end

        local thing = tile:getBottomCreature() or tile:getTopDownItem()
        if not thing then
            return true
        end

        if thing:isCreature() then
            return thing:teleportTo(toPosition:moveUpstairs(), false)
        elseif thing:isItem() and thing:getType():isMovable() then
            return thing:moveTo(toPosition:moveUpstairs())
        end

        return true
    end

    return false
end
LUA:
function onUseRope(player, item, fromPosition, target, toPosition)
    local tile = Tile(toPosition)
    if not tile then
        return false
    end
    
    if target and target:isCreature() then
        return false
    end
    
    local itemType = ItemType(target.itemid)
    if itemType and itemType:getGroup() == ITEM_GROUP_SPLASH then
        target = tile:getGround()
    end
    
    if table.contains(ropeSpots, target.itemid) then
        tile = Tile(toPosition:moveUpstairs())
        if not tile then
            return false
        end
    
        if tile:hasFlag(TILESTATE_PROTECTIONZONE) and player:isPzLocked() then
            player:sendCancelMessage(RETURNVALUE_PLAYERISPZLOCKED)
            return true
        end
    
        player:teleportTo(toPosition, false)
        return true
    end
    
    if table.contains(holeId, target.itemid) then
        toPosition.z = toPosition.z + 1
        tile = Tile(toPosition)
        if not tile then
            return false
        end
    
        local thing = tile:getBottomCreature() or tile:getTopDownItem()
        if not thing then
            return true
        end
    
        if thing:isCreature() then
            return thing:teleportTo(toPosition:moveUpstairs(), false)
        elseif thing:isItem() and thing:getType():isMovable() then
            return thing:moveTo(toPosition:moveUpstairs())
        end
    
        return true
    end
    
    return false
end
 
For some reason, only players and monsters are blocking use for rope, not items 🥲
I can't see an issue in the code.
Can you show us a screenshot or short video of what's happening in game?
Post automatically merged:

Ah well, here's some prints that might shed some light on the issue.

LUA:
function onUseRope(player, item, fromPosition, target, toPosition)
    print("rope triggered..")
    local tile = Tile(toPosition)
    if not tile then
        return false
    end
    
    if target and target:isCreature() then
        return false
    end
    
    local itemType = ItemType(target.itemid)
    if itemType and itemType:getGroup() == ITEM_GROUP_SPLASH then
        print("splash detected (itemid " .. target.itemid .. "), new target is ground..")
        target = tile:getGround()
    end
    
    if table.contains(ropeSpots, target.itemid) then
        tile = Tile(toPosition:moveUpstairs())
        if not tile then
            return false
        end
    
        if tile:hasFlag(TILESTATE_PROTECTIONZONE) and player:isPzLocked() then
            player:sendCancelMessage(RETURNVALUE_PLAYERISPZLOCKED)
            return true
        end
    
        player:teleportTo(toPosition, false)
        print("rope used successfully on itemid " .. target.itemid)
        return true
    end
    
    if table.contains(holeId, target.itemid) then
        toPosition.z = toPosition.z + 1
        tile = Tile(toPosition)
        if not tile then
            return false
        end
    
        local thing = tile:getBottomCreature() or tile:getTopDownItem()
        if not thing then
            return true
        end
    
        if thing:isCreature() then
            return thing:teleportTo(toPosition:moveUpstairs(), false)
        elseif thing:isItem() and thing:getType():isMovable() then
            return thing:moveTo(toPosition:moveUpstairs())
        end
    
        return true
    end
    
    return false
end
 
Last edited by a moderator:
Back
Top