CastorFlynn
Member
- Joined
- Aug 29, 2021
- Messages
- 88
- Reaction score
- 8
I can't rope players and monsters that are with invisible condition.
We need to account for unmoveable items like the ground it returns.
function onUseRope(player, item, fromPosition, target, toPosition, isHotkey)
if toPosition.x == CONTAINER_POSITION then
return false
end
local tile = Tile(toPosition)
if not tile then
return false
end
local ground = tile:getGround()
if ground and isInArray(ropeSpots, ground.itemid) or tile:getItemById(14435) then
player:teleportTo(toPosition:moveUpstairs())
return true
end
if not isInArray(holeId, target.itemid) then
return false
end
toPosition.z = toPosition.z + 1
tile =...
can you post your rope script?data/actions/lib/actions.lua
and let us know your specific server version?
function onUseRope(player, item, fromPosition, target, toPosition, isHotkey)
if toPosition.x == CONTAINER_POSITION then
return false
end
local targetId = target.itemid
local tile = Tile(toPosition)
local ground = tile:getGround()
if ground and isInArray(ropeSpots, ground.itemid) or tile:getItemById(14435) then
player:teleportTo(toPosition:moveUpstairs())
return true
elseif isInArray(holeId, targetId) then
toPosition.z = toPosition.z + 1
tile = Tile(toPosition)
if tile then
local thing = tile:getTopVisibleThing()
if thing:isItem() and thing:getType():isMovable() then
return thing:moveTo(toPosition:moveUpstairs())
elseif thing:isCreature() then
if thing:isPlayer() then
local playerId = thing:getId()
if not ropeExhaust[playerId] or ropeExhaust[playerId] < os.time() then
if thing:teleportTo(toPosition:moveUpstairs()) then
ropeExhaust[playerId] = os.time() + 1
return true
end
else
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
end
else
return thing:teleportTo(toPosition:moveUpstairs())
end
end
end
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return true
end
return false
end
isInArray
instead of table.contains
function onUseRope(player, item, fromPosition, target, toPosition, isHotkey)
if toPosition.x == CONTAINER_POSITION then
return false
end
local tile = Tile(toPosition)
if not tile then
return false
end
local ground = tile:getGround()
if ground and isInArray(ropeSpots, ground.itemid) or tile:getItemById(14435) then
player:teleportTo(toPosition:moveUpstairs())
return true
end
if not isInArray(holeId, target.itemid) then
return false
end
toPosition.z = toPosition.z + 1
tile = Tile(toPosition)
if not tile then
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return true
end
local thing = tile:getTopVisibleThing()
if thing:isItem() and thing:getType():isMovable() then
return thing:moveTo(toPosition:moveUpstairs())
end
if not thing:isCreature() then -- this section is the main edit.
thing = tile:getTopCreature() -- we try to grab Any creature on the tile
if not thing:isCreature() then
local tileCreatures = tile:getCreatures() -- the above somehow fails, we try grabbing a list of All creatures on the tile
if tileCreatures then
thing = Creature(tileCreatures[1])
end
if not thing:isCreature() then
return false
end
end
end
if not thing:isPlayer() then
return thing:teleportTo(toPosition:moveUpstairs())
end
local playerId = thing:getId()
if not ropeExhaust[playerId] or ropeExhaust[playerId] < os.time() then
if thing:teleportTo(toPosition:moveUpstairs()) then
ropeExhaust[playerId] = os.time() + 1
return true
end
else
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return true
end
return false
end
local thing = tile:getTopVisibleThing()
checks if the creature is visibleif not thing:isCreature() then
and just early return instead It's very strange to see this many nested if's in a tfs 1.3 script.
and to seeisInArray
instead oftable.contains
Anyway, here's my suggested edit
Lua:function onUseRope(player, item, fromPosition, target, toPosition, isHotkey) if toPosition.x == CONTAINER_POSITION then return false end local tile = Tile(toPosition) if not tile then return false end local ground = tile:getGround() if ground and isInArray(ropeSpots, ground.itemid) or tile:getItemById(14435) then player:teleportTo(toPosition:moveUpstairs()) return true end if not isInArray(holeId, target.itemid) then return false end toPosition.z = toPosition.z + 1 tile = Tile(toPosition) if not tile then player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) return true end local thing = tile:getTopVisibleThing() if thing:isItem() and thing:getType():isMovable() then return thing:moveTo(toPosition:moveUpstairs()) end if not thing:isCreature() then -- this section is the main edit. thing = tile:getTopCreature() -- we try to grab Any creature on the tile if not thing:isCreature() then local tileCreatures = tile:getCreatures() -- the above somehow fails, we try grabbing a list of All creatures on the tile if tileCreatures then thing = Creature(tileCreatures[1]) end if not thing:isCreature() then return false end end end if not thing:isPlayer() then return thing:teleportTo(toPosition:moveUpstairs()) end local playerId = thing:getId() if not ropeExhaust[playerId] or ropeExhaust[playerId] < os.time() then if thing:teleportTo(toPosition:moveUpstairs()) then ropeExhaust[playerId] = os.time() + 1 return true end else player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) return true end return false end
This TFS pack is quite old and also includes some additions, I believe, that came from OTBR.
It worked when roping invisible creatures, but I got this error when trying to rope with nothing underneath.
Line 260: if not thing:isCreature() then
View attachment 70413
if not thing then
thing
was nil it would error on if thing:isItem() and thing:getType():isMovable() then
oh, i see, the newly overriden
thing
is nil.function onUseRope(player, item, fromPosition, target, toPosition, isHotkey)
if toPosition.x == CONTAINER_POSITION then
return false
end
local tile = Tile(toPosition)
if not tile then
return false
end
local ground = tile:getGround()
if ground and isInArray(ropeSpots, ground.itemid) or tile:getItemById(14435) then
player:teleportTo(toPosition:moveUpstairs())
return true
end
if not isInArray(holeId, target.itemid) then
return false
end
toPosition.z = toPosition.z + 1
tile = Tile(toPosition)
if not tile then
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return true
end
local thing = tile:getTopCreature()
if not thing then
thing = tile:getTopVisibleThing()
end
if thing:isItem() and thing:getType():isMovable() then
return thing:moveTo(toPosition:moveUpstairs())
end
if not thing:isPlayer() then
return thing:teleportTo(toPosition:moveUpstairs())
end
local playerId = thing:getId()
if not ropeExhaust[playerId] or ropeExhaust[playerId] < os.time() then
if thing:teleportTo(toPosition:moveUpstairs()) then
ropeExhaust[playerId] = os.time() + 1
return true
end
else
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return true
end
return false
end
getTopVisibleThing
will return ground when the tile is empty, but getTopCreature
will return niloh, i see, the newly overridenthing
is nil.
small edit to Xikini's script, will also prioritize creatures over items
Lua:function onUseRope(player, item, fromPosition, target, toPosition, isHotkey) if toPosition.x == CONTAINER_POSITION then return false end local tile = Tile(toPosition) if not tile then return false end local ground = tile:getGround() if ground and isInArray(ropeSpots, ground.itemid) or tile:getItemById(14435) then player:teleportTo(toPosition:moveUpstairs()) return true end if not isInArray(holeId, target.itemid) then return false end toPosition.z = toPosition.z + 1 tile = Tile(toPosition) if not tile then player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) return true end local thing = tile:getTopCreature() if not thing then thing = tile:getTopVisibleThing() end if thing:isItem() and thing:getType():isMovable() then return thing:moveTo(toPosition:moveUpstairs()) end if not thing:isPlayer() then return thing:teleportTo(toPosition:moveUpstairs()) end local playerId = thing:getId() if not ropeExhaust[playerId] or ropeExhaust[playerId] < os.time() then if thing:teleportTo(toPosition:moveUpstairs()) then ropeExhaust[playerId] = os.time() + 1 return true end else player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) return true end return false end
iircgetTopVisibleThing
will return ground when the tile is empty, butgetTopCreature
will return nil
We need to account for unmoveable items like the ground it returns.
function onUseRope(player, item, fromPosition, target, toPosition, isHotkey)
if toPosition.x == CONTAINER_POSITION then
return false
end
local tile = Tile(toPosition)
if not tile then
return false
end
local ground = tile:getGround()
if ground and isInArray(ropeSpots, ground.itemid) or tile:getItemById(14435) then
player:teleportTo(toPosition:moveUpstairs())
return true
end
if not isInArray(holeId, target.itemid) then
return false
end
toPosition.z = toPosition.z + 1
tile = Tile(toPosition)
if not tile then
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return true
end
local thing = tile:getTopCreature()
if not thing then
thing = tile:getTopVisibleThing()
end
if thing:isItem() then
if not thing:getType():isMovable() then
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return true
end
return thing:moveTo(toPosition:moveUpstairs())
elseif thing:isPlayer() then
local playerId = thing:getId()
if ropeExhaust[playerId] and ropeExhaust[playerId] > os.time() then
player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
return true
end
if thing:teleportTo(toPosition:moveUpstairs()) then
ropeExhaust[playerId] = os.time() + 1
end
return true
end
//else its a creature
return thing:teleportTo(toPosition:moveUpstairs())
end
Work! Thank you! for @Xikini too!We need to account for unmoveable items like the ground it returns.
Lua:function onUseRope(player, item, fromPosition, target, toPosition, isHotkey) if toPosition.x == CONTAINER_POSITION then return false end local tile = Tile(toPosition) if not tile then return false end local ground = tile:getGround() if ground and isInArray(ropeSpots, ground.itemid) or tile:getItemById(14435) then player:teleportTo(toPosition:moveUpstairs()) return true end if not isInArray(holeId, target.itemid) then return false end toPosition.z = toPosition.z + 1 tile = Tile(toPosition) if not tile then player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) return true end local thing = tile:getTopCreature() if not thing then thing = tile:getTopVisibleThing() end if thing:isItem() then if not thing:getType():isMovable() then player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) return true end return thing:moveTo(toPosition:moveUpstairs()) end if not thing:isPlayer() then return thing:teleportTo(toPosition:moveUpstairs()) end local playerId = thing:getId() if not ropeExhaust[playerId] or ropeExhaust[playerId] < os.time() then if thing:teleportTo(toPosition:moveUpstairs()) then ropeExhaust[playerId] = os.time() + 1 return true end else player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) return true end return false end