• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Position declaration

jestem pro

That is the question
Joined
Apr 20, 2013
Messages
650
Solutions
14
Reaction score
88
Hello, I cannot figure out why this line is incorrect:

LUA:
local pos = {x=1002, y=1001, z=7}
if getPlayerPosition(cid) == pos then

How to check if a player is on the position?
 
Solution
So use this method
LUA:
function comparePosition(p1, p2, includeStack)
    for k, _ in next, p1 do
        if includeStack then
            if p1["stackpos"] ~= p2["stackpos"] then
                return false
            end
        elseif p1[k] ~= p2[k] and k ~= "stackpos" then
            return false
        end
    end
    return true
end

then compare the code like this
LUA:
local pos = {x=1002, y=1001, z=7}
local playerPosition = getPlayerPosition(cid)
if comparePosition(pos, playerPosition)  then
So use this method
LUA:
function comparePosition(p1, p2, includeStack)
    for k, _ in next, p1 do
        if includeStack then
            if p1["stackpos"] ~= p2["stackpos"] then
                return false
            end
        elseif p1[k] ~= p2[k] and k ~= "stackpos" then
            return false
        end
    end
    return true
end

then compare the code like this
LUA:
local pos = {x=1002, y=1001, z=7}
local playerPosition = getPlayerPosition(cid)
if comparePosition(pos, playerPosition)  then
 
Solution
Back
Top