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

Support TFS 1.2 Nostalrius 7.7 Check if player position is < or >

froy

Active Member
Joined
Sep 30, 2009
Messages
151
Solutions
3
Reaction score
36
Hi!
Im creating a script where a player would use a saw on the fallen tree and gets teleported 2 squares east.

Lua:
function onUse(player, item, fromPosition, target, toPosition)
    if not target:isItem() then
        return false
    end
    
    if target:getId() == 5100 then   
        doRelocate(item:getPosition(),{x = item:getPosition().x + 2, y = item:getPosition().y, z = 07})
        Game.sendMagicEffect(item:getPosition(), 13)
        return true
    
    end
    return
end

Now to the problem, if the player would use the saw from eastern side it still would get teleported 2 squares to the east.
Im wondering who I would check if the players position is < or > then X:31930 to decide where the player would teleport.
Any suggestions?

Feel free to use the script that I made for now!
1641737093470.png
 
Solution
Hi!
Im creating a script where a player would use a saw on the fallen tree and gets teleported 2 squares east.

Lua:
function onUse(player, item, fromPosition, target, toPosition)
    if not target:isItem() then
        return false
    end
 
    if target:getId() == 5100 then
        doRelocate(item:getPosition(),{x = item:getPosition().x + 2, y = item:getPosition().y, z = 07})
        Game.sendMagicEffect(item:getPosition(), 13)
        return true
 
    end
    return
end

Now to the problem, if the player would use the saw from eastern side it still would get teleported 2 squares to the east.
Im wondering who I would check if the players position is < or > then X:31930 to decide where the player would teleport.
Any suggestions...
Hi!
Im creating a script where a player would use a saw on the fallen tree and gets teleported 2 squares east.

Lua:
function onUse(player, item, fromPosition, target, toPosition)
    if not target:isItem() then
        return false
    end
 
    if target:getId() == 5100 then
        doRelocate(item:getPosition(),{x = item:getPosition().x + 2, y = item:getPosition().y, z = 07})
        Game.sendMagicEffect(item:getPosition(), 13)
        return true
 
    end
    return
end

Now to the problem, if the player would use the saw from eastern side it still would get teleported 2 squares to the east.
Im wondering who I would check if the players position is < or > then X:31930 to decide where the player would teleport.
Any suggestions?

Feel free to use the script that I made for now!
View attachment 64547
I think I understand what you need. Try this out, its untested so let me know how it goes.

Lua:
function onUse(player, item, fromPosition, target, toPosition)
    if target and target:getId() == 5100 then
        local position = player:getPosition()
        position:getNextPosition(position.x < toPosition.x and DIRECTION_EAST or DIRECTION_WEST, 2)

        local playerPosition = player:getPosition()
        doRelocate(playerPosition, position)
        Game.sendMagicEffect(playerPosition, 13)
    end
    return true
end
 
Last edited:
Solution
I think I understand what you need. Try this out, its untested so let me know how it goes.

Lua:
function onUse(player, item, fromPosition, target, toPosition)
    if target and target:getId() == 5100 then
        local position = player:getPosition()
        position:getNextPosition(position.x < toPosition.x and DIRECTION_EAST or DIRECTION_WEST, 2)

        local playerPosition = player:getPosition()
        doRelocate(playerPosition, position)
        Game.sendMagicEffect(playerPosition, 13)
    end
    return true
end
Thanks!
Indeed it worked as intended!
Thanks for the information.
 
Back
Top