More glow
[Pixture.git] / mods / headbars / init.lua
bloba09b112f09328c9dcaa26d03047787dad42add1c
1 --
2 -- Headbars mod
3 -- By Kaadmy, for Pixture
4 --
6 headbars = {}
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"
18 if amt < max then
19 for i = 0, max / 2 do
20 img = img .. "^[combine:16x16:0,0=ui_null.png:" .. (i * 16) .. ",0=" .. background
21 end
22 end
24 img = img .. "^([combine:" .. (max * 8) .. "x16:0,0=ui_null.png:0,0=ui_null.png"
26 for i = 0, max / 2 do
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"
32 end
33 end
35 img = img .. "^[makealpha:255,0,255)"
37 return img
38 end
40 minetest.register_entity(
41 "headbars:hpbar",
43 visual = "sprite",
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)},
47 glow = 5,
49 physical = false,
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
56 self.object:remove()
57 return
58 end
60 local hp = ent:get_hp()
62 self.object:set_properties({textures = {headbars.get_sprite("heart.png", "headbars_heart_bg.png", 20, hp)}})
63 end,
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()
80 bar.wielder = to
81 end
83 minetest.register_on_joinplayer(headbars.attach_hpbar)
84 default.log("mod:headbars", "loaded")