• 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 Check if the player is in an area

Kaivan

New Member
Joined
Apr 29, 2021
Messages
13
Reaction score
1
Hello,

I'm trying to check the players area, and run a script, but it's not working. I made this function to check the player's position, but it doesn't return anything.
Lua:
function isInArea(player)
  local pos = player:getPosition()
  if pos.z == 9 then
    if pos.x >= 2039 and pos.y >= 2005 then
      if pos.x <= 2045 and pos.y <= 2012 then
      return true
      end
    end
  end
return false
end

I would like to understand how can I do this. I'm using TFS 1.4.
 
Solution

Position:isInRange(from, to)

Lua:
local playerPosition = player:getPosition()
local topLeftCorner = Position(2005, 2012, 9)
local bottomRightCorner = Position(2039, 2045, 9)

if playerPosition:isInRange(topLeftCorner, bottomRightCorner) then
    print("Player is within the area.")
else
    print("Player is outside of the specified area.")
end

Position:isInRange(from, to)

Lua:
local playerPosition = player:getPosition()
local topLeftCorner = Position(2005, 2012, 9)
local bottomRightCorner = Position(2039, 2045, 9)

if playerPosition:isInRange(topLeftCorner, bottomRightCorner) then
    print("Player is within the area.")
else
    print("Player is outside of the specified area.")
end
 
Solution
Back
Top