1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-26 02:30:38 +01:00
server-nalc/mods/gauges/init.lua

50 lines
1.5 KiB
Lua
Raw Normal View History

2014-10-28 18:01:32 +01:00
-- Adds health bars above players.
-- Code by 4aiman, textures by Calinou. Licensed under CC0.
local hp_bar = {
physical = false,
collisionbox = {x = 0, y = 0, z = 0},
visual = "sprite",
textures = {"20.png"}, -- The texture is changed later in the code.
visual_size = {x = 1.5, y = 0.09375, z = 1.5}, -- Y value is (1 / 16) * 1.5.
wielder = nil,
2016-03-05 19:00:37 +01:00
on_activate = function(self)
self.object:set_armor_groups({immortal = 1})
end,
2014-10-28 18:01:32 +01:00
}
function hp_bar:on_step(dtime)
local wielder = self.wielder
2015-06-10 17:14:58 +02:00
if wielder == nil then
2014-10-28 18:01:32 +01:00
self.object:remove()
return
elseif minetest.get_player_by_name(wielder:get_player_name()) == nil then
2014-10-28 18:01:32 +01:00
self.object:remove()
return
end
local hp = wielder:get_hp()
local breath = wielder:get_breath()
2014-10-28 18:01:32 +01:00
self.object:set_properties({textures = {"health_" .. tostring(hp) .. ".png^breath_" .. tostring(breath) .. ".png"}})
end
minetest.register_entity("gauges:hp_bar", hp_bar)
function add_HP_gauge(pl)
local pos = pl:getpos()
local ent = minetest.add_entity(pos, "gauges:hp_bar")
2014-10-28 18:01:32 +01:00
if ent ~= nil then
ent:set_attach(pl, "", {x = 0, y = 10, z = 0}, {x = 0, y = 0, z = 0})
ent = ent:get_luaentity()
ent.wielder = pl
end
end
if minetest.setting_getbool("health_bars") ~= false -- “If not defined or set to true then”
and minetest.setting_getbool("enable_damage") then -- Health bars only display when damage is enabled.
minetest.register_on_joinplayer(add_HP_gauge)
end
if minetest.setting_getbool("log_mods") then
minetest.log("action", "Carbone: [gauges] loaded.")
end