Skip to content

GetNearestDoor

The door nearest to a point, within a radius.

“The door I stand at”: the mode’s command on the nearest door, a rule set by standing next to it, with no key in sight (/objectinfo shows the keys to an admin in the game). Every door the tables export lists for the level is considered; nil when none is within the radius.

GetNearestDoor(x, y, z [, radius])
Parameter Type
x number the point, metres
y number
z number
radius number metres; 0 or none = no limit (optional)

string, number - the door’s key and its distance in metres; nil when none

-- /perm 3: the leader stands at the door; rank 3 or above of their faction may open it
function OnPlayerCommandText(pid, cmd, args)
if cmd == "perm" then
local x, y, z = GetPlayerPos(pid)
local key = GetNearestDoor(x, y, z, 3)
if not key then SendClientMessage(pid, COLOR_SERVER, "Stand next to the door.") return true end
perms[key] = { faction = factionOf[pid], rank = tonumber(args) }
db:Execute("REPLACE INTO perms (object_key, faction, min_rank) VALUES (@k, @f, @r)", { k = key, f = perms[key].faction, r = perms[key].rank })
return true
end
end

GetDoorPosition · GetNearestContainer · GetNearestWorldItem · OnPlayerUseDoor · the Doors and containers group of the index