mirror of
https://notabug.org/TenPlus1/protector.git
synced 2025-01-10 09:07:30 +01:00
Added HUD text to show protected areas
This commit is contained in:
parent
8f02711af4
commit
974a024171
@ -52,6 +52,7 @@ Change log:
|
|||||||
It can also place vertically (up and down) as well. New protector recipe added.
|
It can also place vertically (up and down) as well. New protector recipe added.
|
||||||
- 2.3 - Localise many of the protector functions and tidy code.
|
- 2.3 - Localise many of the protector functions and tidy code.
|
||||||
- 2.4 - Update to newer functions, Minetest 0.4.16 needed to run now.
|
- 2.4 - Update to newer functions, Minetest 0.4.16 needed to run now.
|
||||||
|
- 2.5 - Added HUD text to show when player is inside a protected area (updates every 5 seconds)
|
||||||
|
|
||||||
Lucky Blocks: 10
|
Lucky Blocks: 10
|
||||||
|
|
||||||
|
60
hud.lua
Normal file
60
hud.lua
Normal file
@ -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)
|
||||||
|
|
1
init.lua
1
init.lua
@ -624,6 +624,7 @@ dofile(path .. "/doors_chest.lua")
|
|||||||
dofile(path .. "/pvp.lua")
|
dofile(path .. "/pvp.lua")
|
||||||
dofile(path .. "/admin.lua")
|
dofile(path .. "/admin.lua")
|
||||||
dofile(path .. "/tool.lua")
|
dofile(path .. "/tool.lua")
|
||||||
|
dofile(path .. "/hud.lua")
|
||||||
dofile(path .. "/lucky_block.lua")
|
dofile(path .. "/lucky_block.lua")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user