mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-11-05 10:00:26 +01:00
50 lines
1.2 KiB
Lua
Executable File
50 lines
1.2 KiB
Lua
Executable File
-- This is inspired by the landrush mod by Bremaweb
|
|
|
|
areas.hud = {}
|
|
|
|
local function tick()
|
|
minetest.after(1, tick)
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
|
local name = player:get_player_name()
|
|
local pos = vector.round(player:getpos())
|
|
local areaStrings = {}
|
|
for id, area in pairs(areas:getAreasAtPos(pos)) do
|
|
table.insert(areaStrings, ("%s [%u] (%s%s)")
|
|
:format(area.name, id, area.owner,
|
|
area.open and ":open" or area.openfarming and ":open to farming" or ""))
|
|
end
|
|
local areaString = "Areas:"
|
|
if #areaStrings > 0 then
|
|
areaString = areaString.."\n"..
|
|
table.concat(areaStrings, "\n")
|
|
end
|
|
local hud = areas.hud[name]
|
|
if not hud then
|
|
hud = {}
|
|
areas.hud[name] = hud
|
|
hud.areasId = player:hud_add({
|
|
hud_elem_type = "text",
|
|
name = "Areas",
|
|
number = 0xFFFFFF,
|
|
position = {x=0, y=1},
|
|
offset = {x=8, y=-8},
|
|
text = areaString,
|
|
scale = {x=200, y=60},
|
|
alignment = {x=1, y=-1},
|
|
})
|
|
hud.oldAreas = areaString
|
|
return
|
|
elseif hud.oldAreas ~= areaString then
|
|
player:hud_change(hud.areasId, "text", areaString)
|
|
hud.oldAreas = areaString
|
|
end
|
|
end
|
|
end
|
|
|
|
tick()
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
areas.hud[player:get_player_name()] = nil
|
|
end)
|
|
|