tweak and tidy code

This commit is contained in:
tenplus1 2024-09-16 11:35:13 +01:00
commit ce84ac68b2
6 changed files with 363 additions and 437 deletions

21
hud.lua
View file

@ -1,23 +1,27 @@
local S = protector.intllib
-- translation and protector radius
local S = minetest.get_translator("protector")
local radius = (tonumber(minetest.settings:get("protector_radius")) or 5)
-- radius limiter (minetest cannot handle node volume of more than 4096000)
if radius > 30 then radius = 30 end
-- hud settings
local hud = {}
local hud_timer = 0
local hud_interval = (tonumber(minetest.settings:get("protector_hud_interval")) or 5)
local hud_style = minetest.has_feature("hud_def_type_field")
if hud_interval > 0 then
minetest.register_globalstep(function(dtime)
-- every 5 seconds
hud_timer = hud_timer + dtime
if hud_timer < hud_interval then
return
end
if hud_timer < hud_interval then return end
hud_timer = 0
for _, player in pairs(minetest.get_connected_players()) do
@ -27,11 +31,12 @@ minetest.register_globalstep(function(dtime)
local hud_text = ""
local protectors = minetest.find_nodes_in_area(
{x = pos.x - radius , y = pos.y - radius , z = pos.z - radius},
{x = pos.x + radius , y = pos.y + radius , z = pos.z + radius},
{"protector:protect","protector:protect2", "protector:protect_hidden"})
{x = pos.x - radius , y = pos.y - radius , z = pos.z - radius},
{x = pos.x + radius , y = pos.y + radius , z = pos.z + radius},
{"protector:protect","protector:protect2", "protector:protect_hidden"})
if #protectors > 0 then
local npos = protectors[1]
local meta = minetest.get_meta(npos)
local nodeowner = meta:get_string("owner")
@ -72,4 +77,4 @@ minetest.register_on_leaveplayer(function(player)
hud[player:get_player_name()] = nil
end)
end
end -- END hud_interval > 0