diff options
author | ShadowNinja <shadowninja@minetest.net> | 2014-01-15 20:10:24 -0500 |
---|---|---|
committer | ShadowNinja <shadowninja@minetest.net> | 2014-01-15 20:10:24 -0500 |
commit | ed7f57bf2f21af64039f07ac547ff676167b0ede (patch) | |
tree | eeb2fc52fd96b06979d45ea70fbd151fb6a5404e /api.lua | |
parent | f7f4c2ddb567ef01bad299ac0c093300909d950c (diff) |
Add IDs to HUD and areas:getAreasAtPos(pos)
Diffstat (limited to 'api.lua')
-rw-r--r-- | api.lua | 38 |
1 files changed, 22 insertions, 16 deletions
@@ -1,20 +1,30 @@ +-- Returns a list of areas that include the provided position +function areas:getAreasAtPos(pos) + local a = {} + local px, py, pz = pos.x, pos.y, pos.z + for id, area in pairs(self.areas) do + local ap1, ap2 = area.pos1, area.pos2 + if px >= ap1.x and px <= ap2.x and + py >= ap1.y and py <= ap2.y and + pz >= ap1.z and pz <= ap2.z then + a[id] = area + end + end + return a +end + -- Checks if the area is unprotected or owned by you function areas:canInteract(pos, name) if minetest.check_player_privs(name, {areas=true}) then return true end local owned = false - for _, area in pairs(self.areas) do - p1, p2 = area.pos1, area.pos2 - if pos.x >= p1.x and pos.x <= p2.x and - pos.y >= p1.y and pos.y <= p2.y and - pos.z >= p1.z and pos.z <= p2.z then - if area.owner == name then - return true - else - owned = true - end + for _, area in pairs(self:getAreasAtPos(pos)) do + if area.owner == name then + return true + else + owned = true end end return not owned @@ -23,12 +33,8 @@ end -- Returns a table (list) of all players that own an area function areas:getNodeOwners(pos) local owners = {} - for _, area in pairs(self.areas) do - if pos.x >= area.pos1.x and pos.x <= area.pos2.x and - pos.y >= area.pos1.y and pos.y <= area.pos2.y and - pos.z >= area.pos1.z and pos.z <= area.pos2.z then - table.insert(owners, area.owner) - end + for _, area in pairs(self:getAreasAtPos(pos)) do + table.insert(owners, area.owner) end return owners end |