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

86 lines
2.0 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 = {}
2015-07-31 15:12:46 +02:00
local function tick()
2014-10-28 18:01:32 +01:00
for _, player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local pos = vector.round(player:getpos())
2016-06-20 18:33:05 +02:00
local area_text = "No area(s)\n\n"
2016-06-18 19:12:57 +02:00
local area_owner_name = ""
local mod_owner = 0
local mod_open = 0
local mod_farming = 0
local area_name = ""
local nb_areas = 0
2014-10-28 18:01:32 +01:00
for id, area in pairs(areas:getAreasAtPos(pos)) do
2016-06-18 19:12:57 +02:00
nb_areas = nb_areas+1
if areas:isAreaOwner(id, name) then
mod_owner = 1
end
if area.open then
mod_open = 1
end
if area.openfarming then
mod_farming = 1
end
if not area.parent then
area_owner_name = area.owner
area_name = area.name
end
2014-10-28 18:01:32 +01:00
end
2016-06-18 19:12:57 +02:00
2016-06-18 22:35:38 +02:00
local icon = "areas_not_area.png"
2016-06-18 19:12:57 +02:00
if nb_areas > 0 then
2016-06-22 23:51:38 +02:00
local plural = ""
if nb_areas > 1 then
plural = "s"
end
area_text = ("%s\nOwner: %s\n%u area" .. plural):format(area_name, area_owner_name, nb_areas)
2016-06-18 19:12:57 +02:00
icon = ("areas_%u_%u_%u.png"):format(mod_owner, mod_open, mod_farming)
2015-01-08 22:28:47 +01:00
end
2016-06-18 19:12:57 +02:00
if not areas.hud[name] then
areas.hud[name] = {}
areas.hud[name].icon = player:hud_add({
hud_elem_type = "image",
position = {x=0,y=1},
scale = {x=1,y=1},
offset = {x=26,y=-60},
text = icon,
})
areas.hud[name].areas_id = player:hud_add({
hud_elem_type = "text",
2014-10-28 18:01:32 +01:00
name = "Areas",
number = 0xFFFFFF,
position = {x=0, y=1},
2016-06-18 19:12:57 +02:00
offset = {x=48, y=-40},
text = area_text,
scale = {x=1, y=1},
2015-01-08 22:28:47 +01:00
alignment = {x=1, y=-1},
2014-10-28 18:01:32 +01:00
})
2016-06-18 19:12:57 +02:00
areas.hud[name].old_area_text = area_text
areas.hud[name].old_icon = icon
else
if areas.hud[name].old_area_text ~= area_text then
player:hud_change(areas.hud[name].areas_id, "text", area_text)
areas.hud[name].old_area_text = area_text
end
if areas.hud[name].old_icon ~= icon then
player:hud_change(areas.hud[name].icon, "text", icon)
areas.hud[name].old_icon = icon
end
2014-10-28 18:01:32 +01:00
end
end
2016-06-18 19:12:57 +02:00
minetest.after(1.5, tick)
2015-07-31 15:12:46 +02:00
end
tick()
2014-10-28 18:01:32 +01:00
minetest.register_on_leaveplayer(function(player)
areas.hud[player:get_player_name()] = nil
end)