1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
--[[ Configuration ]]--
local barHeight = 5;
local barWidth = 50;
local barPosX = 40;	-- for HUD
local barPosY = 435; -- for HUD
local drawBarAsHUD = false;
local draw_npc_bars = true;
--[[ ---------------------------- ]]--
dofile("sys/lua/graphics.lua");
local hpBarImg = {};
local hpBarImg_npc = {}
function draw_npc_bars() end
if ( draw_npc_bars ) then
	function draw_npc_bars()
		for _, id in pairs( object(0, "table") ) do
			-- check if NPC
			if ( object(id, "type") == 30 ) then
				x = object(id, "x") - (barWidth/2);
				y = object(id, "y") - 25;
				
				local hp = object(id, "health");
				hp = ((hp > 100) and 100 or hp)
				r, g, b = (hp*-255+255)/100,hp*255/100,0;
				hp = hp/100;
				hp = ((hp > 1.0) and 1.0 or hp)
				
				if ( hpBarImg_npc[id] == nil ) then
					hpBarImg_npc[id] = {DrawRect(x-1, y-1, barWidth+2, barHeight+2, 0, {200, 200, 200},1),
										DrawRect(x, y, barWidth*hp, barHeight, 0, {r,g,b},1)}
				else
					UpdateRect(hpBarImg_npc[id][1], x-1, y-1, barWidth+2, barHeight+2,{200, 200, 200})
					UpdateRect(hpBarImg_npc[id][2], x, y, barWidth*hp, barHeight, {r,g,b})				
				end
			end
		end
	end
end
if ( drawBarAsHUD ) then
	for i = 1, 32 do	-- Initialization
		hpBarImg[i] = {0, 0};
		hpBarImg[i][1] = DrawRect(0, 0, 0, 0, i, {0, 0, 0}, 2);
		hpBarImg[i][2] = DrawRect(0, 0, 0, 0, i, {0, 0, 0}, 2);
		imagealpha(hpBarImg[i][1], 0.4);
	end
	
	function DrawBar(id)
		if ( player(id, "exists") ) then
			local r, g, b;
			
			local hp = player(id, "health");
			r, g, b = (hp*-255+255)/100,hp*255/100,0;
			
			hp = hp/100;
			hp = ((hp > 1.0) and 1.0 or hp)
			
			UpdateRect(hpBarImg[id][1], barPosX-1, barPosY-1, barWidth+2, barHeight+2, {200, 200, 200});
			UpdateRect(hpBarImg[id][2], barPosX, barPosY, hp*barWidth, barHeight, {r, g, b});
		end
	end
else
	for i = 1, 32 do	-- Initialization
		hpBarImg[i] = {0, 0};
		hpBarImg[i][1] = DrawRect(0, 0, 0, 0, 0, {0, 0, 0}, 1);
		hpBarImg[i][2] = DrawRect(0, 0, 0, 0, 0, {0, 0, 0}, 1);
		imagealpha(hpBarImg[i][1], 0.4);
	end
	
	function DrawBar(id)
		if ( player(id, "exists") ) then
			if ( player(id, "health") > 0 ) then
				local x, y, r, g, b;
				
				local hp = player(id, "health");
				r, g, b = (hp*-255+255)/100,hp*255/100,0;
				
				x = player(id, "x") - (barWidth/2);
				y = player(id, "y") - 25;
				
				r, g, b = (hp*-255+255)/100,hp*255/100,0;
				hp = hp/100;
				hp = ((hp > 1.0) and 1.0 or hp)
				
				UpdateRect(hpBarImg[id][1], x-1, y-1, barWidth+2, barHeight+2, {200, 200, 200});
				UpdateRect(hpBarImg[id][2], x, y, hp*barWidth, barHeight, {r, g, b});
				
				imagealpha(hpBarImg[id][1], 0.4);
				imagealpha(hpBarImg[id][2], 1.0);
			else
				imagealpha(hpBarImg[id][1], 0.0);
				imagealpha(hpBarImg[id][2], 0.0);
			end
		else
			imagealpha(hpBarImg[id][1], 0.0);
			imagealpha(hpBarImg[id][2], 0.0);
		end
	end
end
function hook_objkill(id)
	if ( hpBarImg_npc[id] ~= nil ) then
		freeimage(hpBarImg_npc[id][1])
		freeimage(hpBarImg_npc[id][2])
		hpBarImg_npc[id] = nil
	end
end
addhook("objectkill", "hook_objkill")
		
addhook("always", "DrawHPBars");
function DrawHPBars()
	for i = 1, 32 do
		DrawBar(i);
	end
	draw_npc_bars()
end