1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-09 12:00:17 +01:00
server-nalc/mods/areas/hud.lua

47 lines
1.2 KiB
Lua
Raw Normal View History

2014-10-28 18:01:32 +01:00
-- 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())
2015-01-08 22:28:47 +01:00
local areaStrings = {}
2014-10-28 18:01:32 +01:00
for id, area in pairs(areas:getAreasAtPos(pos)) do
2015-01-08 22:28:47 +01:00
table.insert(areaStrings, ("%s [%u] (%s%s)")
2014-10-28 18:01:32 +01:00
:format(area.name, id, area.owner,
area.open and ":open" or area.openfarming and ":open to farming" or ""))
2014-10-28 18:01:32 +01:00
end
2015-01-08 22:28:47 +01:00
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",
2014-10-28 18:01:32 +01:00
name = "Areas",
number = 0xFFFFFF,
position = {x=0, y=1},
2015-01-08 22:28:47 +01:00
offset = {x=8, y=-8},
text = areaString,
2014-10-28 18:01:32 +01:00
scale = {x=200, y=60},
2015-01-08 22:28:47 +01:00
alignment = {x=1, y=-1},
2014-10-28 18:01:32 +01:00
})
2015-01-08 22:28:47 +01:00
hud.oldAreas = areaString
2014-10-28 18:01:32 +01:00
return
2015-01-08 22:28:47 +01:00
elseif hud.oldAreas ~= areaString then
player:hud_change(hud.areasId, "text", areaString)
hud.oldAreas = areaString
2014-10-28 18:01:32 +01:00
end
end
end)
minetest.register_on_leaveplayer(function(player)
areas.hud[player:get_player_name()] = nil
end)