areas/hud.lua
Ciaran Gultnieks 1a5efd07f1 Allow areas to be optionally open to all other users
In other words, you can retain ownership of an area but disable and
re-enable the protection aspect at will, via the area_open chat command.

By default, nothing is any different following this commit - all
existing areas are protected, as are new ones. But you can do (for
example) "area_open 1" and if you're the owner of that area, it's
now possible for other users to interact there. "area_open 1" again to
toggle the protection back on.

Where there are sub-areas, the main owner and ALL sub-area owners at a
particulare location must have set the areas to open to disable
protection.
2014-02-07 18:07:56 -05:00

51 lines
1.3 KiB
Lua

-- This is inspired by the landrush mod by Bremaweb
areas.hud = {}
minetest.register_globalstep(function(dtime)
for _, player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local pos = vector.round(player:getpos())
local a = areas:getAreasAtPos(pos)
local areaString = ""
local first = true
for id, area in pairs(areas:getAreasAtPos(pos)) do
if not first then
areaString = areaString..", "
else
first = false
end
local ownertxt = area.owner
if area.open then
ownertxt = ownertxt.."/open"
end
areaString = areaString..id.." ("..ownertxt..")"
end
if not areas.hud[name] then
areas.hud[name] = {}
areas.hud[name].areasId = player:hud_add({
hud_elem_type = "text",
name = "Areas",
number = 0xFFFFFF,
position = {x=0, y=1},
offset = {x=5, y=-60},
direction = 0,
text = "Areas: "..areaString,
scale = {x=200, y=60},
alignment = {x=1, y=1},
})
areas.hud[name].oldAreas = areaString
return
elseif areas.hud[name].oldAreas ~= areaString then
player:hud_change(areas.hud[name].areasId, "text",
"Areas: "..areaString)
areas.hud[name].oldAreas = areaString
end
end
end)
minetest.register_on_leaveplayer(function(player)
areas.hud[player:get_player_name()] = nil
end)