3 -- By Kaadmy, for Pixture
8 local enable_damage
= minetest
.settings
:get_bool("enable_damage")
10 local enable_headbars
= minetest
.settings
:get_bool("headbars_enable")
11 if enable_headbars
== nil then enable_headbars
= true end
13 local headbars_scale
= tonumber(minetest
.settings
:get("headbars_scale")) or 1.0
15 function headbars
.get_sprite(icon
, background
, max, amt
)
16 local img
= "[combine:" .. (max * 8) .. "x16:0,0=ui_null.png:0,0=ui_null.png"
20 img
= img
.. "^[combine:16x16:0,0=ui_null.png:" .. (i
* 16) .. ",0=" .. background
24 img
= img
.. "^([combine:" .. (max * 8) .. "x16:0,0=ui_null.png:0,0=ui_null.png"
27 if i
< (amt
- 1) / 2 then
28 img
= img
.. "^[combine:" .. (max * 8) .. "x16:0,0=ui_null.png:" .. (i
* 16) .. ",0=" .. icon
29 elseif i
< amt
/ 2 then
30 img
= img
.. "^[combine:" .. (max * 8) .. "x16:0,0=ui_null.png:" .. (i
* 16) .. ",0=" .. icon
31 img
= img
.. "^[combine:" .. (max * 8) .. "x16:0,0=ui_null.png:" .. (i
* 16) .. ",0=headbars_half.png"
35 img
= img
.. "^[makealpha:255,0,255)"
40 minetest
.register_entity(
44 visual_size
= {x
= 1 * headbars_scale
, y
= 0.1 * headbars_scale
, z
= 1},
45 textures
= {headbars
.get_sprite("heart.png", "ui_null.png", 20, 20)},
50 collisionbox
= {0, 0, 0, 0, 0, 0},
52 on_step
= function(self
, dtime
)
53 local ent
= self
.wielder
55 if ent
== nil or (minetest
.get_player_by_name(ent
:get_player_name(0)) == nil) then
60 local hp
= ent
:get_hp()
62 self
.object
:set_properties({textures
= {headbars
.get_sprite("heart.png", "headbars_heart_bg.png", 20, hp
)}})
66 function headbars
.attach_hpbar(to
)
67 if not enable_damage
then return end
68 if not enable_headbars
then return end
70 local pos
= to
:getpos()
71 local bar
= minetest
.add_entity(pos
, "headbars:hpbar")
73 if bar
== nil then return end
75 -- local attach_pos = {x = 0, y = 0, z = 0}
76 local attach_pos
= {x
= 0, y
= 9, z
= 0}
78 bar
:set_attach(to
, "", attach_pos
, {x
= 0, y
= 0, z
= 0})
79 bar
= bar
:get_luaentity()
83 minetest
.register_on_joinplayer(headbars
.attach_hpbar
)
84 default
.log("mod:headbars", "loaded")