summaryrefslogtreecommitdiff
path: root/hud.lua
diff options
context:
space:
mode:
authorTenPlus1 <kinsellaja@yahoo.com>2017-11-11 12:50:50 +0000
committerTenPlus1 <kinsellaja@yahoo.com>2017-11-11 12:50:50 +0000
commit974a024171529ec14d08e5d6b87bb995627a978f (patch)
treebc2b829e501dd3cccf820b7e6bc4a012d609ef1a /hud.lua
parent8f02711af43c1b438fea56a270e67985220d394e (diff)
Added HUD text to show protected areas
Diffstat (limited to 'hud.lua')
-rw-r--r--hud.lua60
1 files changed, 60 insertions, 0 deletions
diff --git a/hud.lua b/hud.lua
new file mode 100644
index 0000000..cbf1bd2
--- /dev/null
+++ b/hud.lua
@@ -0,0 +1,60 @@
+
+local radius = (tonumber(minetest.setting_get("protector_radius")) or 5)
+local hud = {}
+local hud_timer = 0
+
+minetest.register_globalstep(function(dtime)
+
+ hud_timer = hud_timer + dtime
+ if hud_timer < 5 then
+ return
+ end
+ hud_timer = 0
+
+ for _, player in pairs(minetest.get_connected_players()) do
+
+ local name = player:get_player_name()
+ local pos = vector.round(player:getpos())
+ local hud_text = "You can build here"
+
+ 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"})
+
+ if #protectors > 0 then
+ local npos = protectors[1]
+ local meta = minetest.get_meta(npos)
+ local nodeowner = meta:get_string("owner")
+
+ hud_text = "Owned by: " .. nodeowner
+ end
+
+ if not hud[name] then
+
+ hud[name] = {}
+
+ hud[name].id = player:hud_add({
+ hud_elem_type = "text",
+ name = "Protector Area",
+ number = 0xFFFF22,
+ position = {x=0, y=0.95},
+ offset = {x=8, y=-8},
+ text = hud_text,
+ scale = {x=200, y=60},
+ alignment = {x=1, y=-1},
+ })
+
+ 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)
+