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
--[[ Configuration ]]--
local barHeight = 5;
local barWidth = 50;
local barPosX = 40;	-- for HUD
local barPosY = 435; -- for HUD
local drawBarAsHUD = false;
--[[ ---------------------------- ]]--
dofile("sys/lua/hpBar/graphics.lua");
local hpBarImg = {};
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 hpRatio, r, g, b;
			
			hpRatio = player(id, "health")/player(id, "maxhealth");
			
			r, g, b = ConvertHSVtoRGB(hpRatio*120, 1, 1);
			r = r*255;
			g = g*255;
			b = b*255;
			
			UpdateRect(hpBarImg[id][1], barPosX-1, barPosY-1, barWidth+2, barHeight+2, {200, 200, 200});
			UpdateRect(hpBarImg[id][2], barPosX, barPosY, hpRatio*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, hpRatio, r, g, b;
				
				hpRatio = player(id, "health")/player(id, "maxhealth");
				
				x = player(id, "x") - (barWidth/2);
				y = player(id, "y") - 50;
				
				r, g, b = ConvertHSVtoRGB(hpRatio*120, 1, 1);
				r = r*255;
				g = g*255;
				b = b*255;
				
				UpdateRect(hpBarImg[id][1], x-1, y-1, barWidth+2, barHeight+2, {200, 200, 200});
				UpdateRect(hpBarImg[id][2], x, y, hpRatio*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
addhook("always", "DrawHPBars");
function DrawHPBars()
	for i = 1, 32 do
		DrawBar(i);
	end
end