Expose methods in gauges globally
This commit is contained in:
parent
93da7d0108
commit
1c7399b2cb
1 changed files with 8 additions and 6 deletions
|
@ -1,6 +1,8 @@
|
||||||
-- Adds health bars above players.
|
-- Adds health bars above players.
|
||||||
-- Code by 4aiman, textures by Calinou. Licensed under CC0.
|
-- Code by 4aiman, textures by Calinou. Licensed under CC0.
|
||||||
|
|
||||||
|
gauges = {}
|
||||||
|
|
||||||
local hp_bar = {
|
local hp_bar = {
|
||||||
physical = false,
|
physical = false,
|
||||||
collisionbox = {x = 0, y = 0, z = 0},
|
collisionbox = {x = 0, y = 0, z = 0},
|
||||||
|
@ -42,7 +44,7 @@ end
|
||||||
|
|
||||||
minetest.register_entity("gauges:hp_bar", hp_bar)
|
minetest.register_entity("gauges:hp_bar", hp_bar)
|
||||||
|
|
||||||
local function add_HP_gauge(name)
|
function gauges.add_HP_gauge(name)
|
||||||
local player = minetest.get_player_by_name(name)
|
local player = minetest.get_player_by_name(name)
|
||||||
if player then
|
if player then
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
|
@ -59,11 +61,11 @@ end
|
||||||
if minetest.setting_getbool("health_bars") ~= false and
|
if minetest.setting_getbool("health_bars") ~= false and
|
||||||
minetest.setting_getbool("enable_damage") then
|
minetest.setting_getbool("enable_damage") then
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
minetest.after(1, add_HP_gauge, player:get_player_name())
|
minetest.after(1, gauges.add_HP_gauge, player:get_player_name())
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function check_gauges()
|
function gauges.check_gauges()
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
local found = false
|
local found = false
|
||||||
|
@ -78,9 +80,9 @@ local function check_gauges()
|
||||||
|
|
||||||
if not found then
|
if not found then
|
||||||
print("Gauge not found!")
|
print("Gauge not found!")
|
||||||
add_HP_gauge(pname)
|
gauges.add_HP_gauge(pname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
minetest.after(9.3, check_gauges)
|
minetest.after(9.3, gauges.check_gauges)
|
||||||
end
|
end
|
||||||
minetest.after(2, check_gauges)
|
minetest.after(2, gauges.check_gauges)
|
||||||
|
|
Loading…
Reference in a new issue