2017-11-11 13:50:50 +01:00
|
|
|
|
2018-07-10 19:59:29 +02:00
|
|
|
local S = protector.intllib
|
2021-02-11 21:00:49 +01:00
|
|
|
local radius = (tonumber(minetest.settings:get("protector_radius")) or 5)
|
2020-08-30 09:30:42 +02:00
|
|
|
|
|
|
|
-- radius limiter (minetest cannot handle node volume of more than 4096000)
|
|
|
|
if radius > 22 then radius = 22 end
|
|
|
|
|
2017-11-11 13:50:50 +01:00
|
|
|
local hud = {}
|
|
|
|
local hud_timer = 0
|
2021-02-11 21:00:49 +01:00
|
|
|
local hud_interval = (tonumber(minetest.settings:get("protector_hud_interval")) or 5)
|
2017-11-11 13:50:50 +01:00
|
|
|
|
2020-04-25 10:02:46 +02:00
|
|
|
if hud_interval > 0 then
|
2017-11-11 13:50:50 +01:00
|
|
|
minetest.register_globalstep(function(dtime)
|
|
|
|
|
2018-09-27 13:56:04 +02:00
|
|
|
-- every 5 seconds
|
2017-11-11 13:50:50 +01:00
|
|
|
hud_timer = hud_timer + dtime
|
2020-04-25 10:02:46 +02:00
|
|
|
if hud_timer < hud_interval then
|
2017-11-11 13:50:50 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
hud_timer = 0
|
|
|
|
|
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
|
|
|
|
|
|
|
local name = player:get_player_name()
|
2018-09-27 13:56:04 +02:00
|
|
|
local pos = vector.round(player:get_pos())
|
2018-01-04 12:23:41 +01:00
|
|
|
local hud_text = ""
|
2017-11-11 13:50:50 +01:00
|
|
|
|
|
|
|
local protectors = minetest.find_nodes_in_area(
|
2018-09-27 13:56:04 +02:00
|
|
|
{x = pos.x - radius , y = pos.y - radius , z = pos.z - radius},
|
|
|
|
{x = pos.x + radius , y = pos.y + radius , z = pos.z + radius},
|
2020-06-12 12:41:33 +02:00
|
|
|
{"protector:protect","protector:protect2", "protector:protect_hidden"})
|
2017-11-11 13:50:50 +01:00
|
|
|
|
|
|
|
if #protectors > 0 then
|
|
|
|
local npos = protectors[1]
|
|
|
|
local meta = minetest.get_meta(npos)
|
|
|
|
local nodeowner = meta:get_string("owner")
|
|
|
|
|
2018-07-10 19:59:29 +02:00
|
|
|
hud_text = S("Owner: @1", nodeowner)
|
2017-11-11 13:50:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if not hud[name] then
|
|
|
|
|
|
|
|
hud[name] = {}
|
|
|
|
|
|
|
|
hud[name].id = player:hud_add({
|
|
|
|
hud_elem_type = "text",
|
|
|
|
name = "Protector Area",
|
|
|
|
number = 0xFFFF22,
|
2019-07-19 13:53:04 +02:00
|
|
|
position = {x = 0, y = 0.95},
|
|
|
|
offset = {x = 8, y = -8},
|
2017-11-11 13:50:50 +01:00
|
|
|
text = hud_text,
|
2019-07-19 13:53:04 +02:00
|
|
|
scale = {x = 200, y = 60},
|
|
|
|
alignment = {x = 1, y = -1},
|
2017-11-11 13:50:50 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
else
|
|
|
|
player:hud_change(hud[name].id, "text", hud_text)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
hud[player:get_player_name()] = nil
|
|
|
|
end)
|
2020-04-25 10:02:46 +02:00
|
|
|
|
|
|
|
end
|