Cuberite Forum

Full Version: Get player coords with no decimals
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need to compare 2 position variables, and they are always diferent because they are X.135369.. Or Z.168375
Any way to solve this?
This should work:
local Pos1 = Vector3i(Player1:GetPosition())
local Pos2 = Vector3i(Player2:GetPosition())
return Pos1:Equals(Pos2)
Either that, or use Lua's built-in math.floor() or math.ceil() functions.
Do they work with Vectors?
No, they only work with individual coords.
And anyway, what is it that you're trying to do? Wouldn't it be eaiser to check if the distance between the two positions, if it's below a threshold?
local Pos1 = Player1:GetPosition()
local Pos2 = Player2:GetPosition()
if ((Pos1 - Pos2):Length() < 1) then
  -- The positions are less than 1 block apart
end
I need to compare a variable to the players position, and if its the same , teleport to another position (in a variable)
The code STR said worked fine, would your code be less performance-heavy doing it every tick as I do now?
Doesn't really matter, they perform roughly the same.
Oh this should also work btw:
local Pos1 = Player1:GetPosition():Floor()
local Pos2 = Player2:GetPosition():Floor()
if (Pos1 == Pos2) then
   -- Do stuff
end