mirror of
https://github.com/minetest-mods/gauges.git
synced 2024-12-23 01:10:23 +01:00
Clean up code
This commit is contained in:
parent
ec67519af6
commit
ff8bdf1167
39
init.lua
39
init.lua
@ -12,32 +12,35 @@ local hp_bar = {
|
|||||||
|
|
||||||
function hp_bar:on_step(dtime)
|
function hp_bar:on_step(dtime)
|
||||||
local wielder = self.wielder
|
local wielder = self.wielder
|
||||||
if wielder == nil then
|
if wielder == nil or
|
||||||
self.object:remove()
|
minetest.get_player_by_name(wielder:get_player_name()) == nil then
|
||||||
return
|
|
||||||
elseif minetest.env:get_player_by_name(wielder:get_player_name()) == nil then
|
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
hp = wielder:get_hp()
|
|
||||||
breath = wielder:get_breath()
|
local hp = wielder:get_hp()
|
||||||
self.object:set_properties({textures = {"health_" .. tostring(hp) .. ".png^breath_" .. tostring(breath) .. ".png",},}
|
local breath = wielder:get_breath()
|
||||||
)
|
self.object:set_properties({
|
||||||
|
textures = {
|
||||||
|
"health_" .. tostring(hp) .. ".png^breath_" .. tostring(breath) .. ".png",
|
||||||
|
},
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_entity("gauges:hp_bar", hp_bar)
|
minetest.register_entity("gauges:hp_bar", hp_bar)
|
||||||
|
|
||||||
function add_HP_gauge(pl)
|
local function add_HP_gauge(player)
|
||||||
local pos = pl:getpos()
|
local pos = player:get_pos()
|
||||||
local ent = minetest.env:add_entity(pos, "gauges:hp_bar")
|
local ent = minetest.add_entity(pos, "gauges:hp_bar")
|
||||||
if ent ~= nil then
|
if ent ~= nil then
|
||||||
ent:set_attach(pl, "", {x = 0, y = 10, z = 0}, {x = 0, y = 0, z = 0})
|
ent:set_attach(player, "", {x = 0, y = 10, z = 0}, {x = 0, y = 0, z = 0})
|
||||||
ent = ent:get_luaentity()
|
ent = ent:get_luaentity()
|
||||||
ent.wielder = pl
|
ent.wielder = player
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.setting_getbool("health_bars") ~= false -- “If not defined or set to true then”
|
-- If health_bars not defined or set to true
|
||||||
and minetest.setting_getbool("enable_damage") then -- Health bars only display when damage is enabled.
|
if minetest.setting_getbool("health_bars") ~= false and
|
||||||
|
minetest.setting_getbool("enable_damage") then
|
||||||
minetest.register_on_joinplayer(add_HP_gauge)
|
minetest.register_on_joinplayer(add_HP_gauge)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user