Forum

> > CS2D > Scripts > Hud Health
Forums overviewCS2D overview Scripts overviewLog in to reply

English Hud Health

13 replies
To the start Previous 1 Next To the start

old Hud Health

- cILiMeend3R -
User Off Offline

Quote
Hello guys.

I made script, i found problem
Not working. Why? Can say me???

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
addhook("spawn","critHealth")

--

function critHealth(id)

local phc

    if player(id,"health") < 100 then
	
            phc = "\169000255000GOOD"

    elseif player(id,"health") < 75 then
	
            phc = "\169000255000NOT GOOD"

	
    elseif player(id,"health") < 50 then
	
	         phc  = "\169000255000BAD"
			 
			 

parse("hudtxt2 "..id.." 0 \"\169255255255Your Health:"..phc.." \" 300 310 1")

end
end

old Re: Hud Health

Cebra
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
addhook("spawn","critHealth")
function critHealth(id)
	local phc
	if player(id,"health") < 100 then
		phc = "\169000255000GOOD"
	elseif player(id,"health") < 75 then
		phc = "\169000255000NOT GOOD"
	elseif player(id,"health") < 50 then
		phc  = "\169000255000BAD"
		parse("hudtxt2 "..id.." 0 \"\169255255255Your Health:"..phc.." \" 300 310 1")
	end
end

1.) The cs2d cmd hudtxt2 is only executed if the player spawns with less than 50 hp.

2.) You have to assign phc a value in case no if-code is executed.

fixed version:
1
2
3
4
5
6
7
8
9
10
11
12
addhook("spawn","critHealth")
function critHealth(id)
	local phc = ""
	if player(id,"health") < 100 then
		phc = "\169000255000GOOD"
	elseif player(id,"health") < 75 then
		phc = "\169000255000NOT GOOD"
	elseif player(id,"health") < 50 then
		phc  = "\169000255000BAD"
		parse("hudtxt2 "..id.." 0 \"\169255255255Your Health:"..phc.." \" 300 310 1")
	end
end

ps: i don't think that the spawn hook is the right one

old Re: Hud Health

Mami Tomoe
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function _update_hp_hud(victim)
	local hp = player(victim, 'health')
	local phc
	
	if hp <= 50 then
		phc  = '\1692551921920BAD'
	elseif hp <= 75 then
		phc = '\169255255192NOT GOOD'
	else
		phc = '\169192255192GOOD'
	end
	
	parse('hudtxt2 ' .. victim .. ' 1 "\169255255255Your Health: ' .. phc .. '" 300 310 1')
end

addhook('hit', '_update_hp_hud')
addhook('spawn', '_update_hp_hud')
addhook('die', '_update_hp_hud')

old Re: Hud Health

Mami Tomoe
User Off Offline

Quote
I don't get it, do you want it to appear to everyone? That wouldn't work well unless you want a specific player to have his health displayed (like a boss).

old Re: Hud Health

Mami Tomoe
User Off Offline

Quote
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
function _update_hp_hud(victim)
	local id = 1 -- Used for HUDTXT ID.
	local hp = player(victim, 'health')
	local state
	
	if hp == 0 then -- Dead, remove HUDTXT.
		parse('hudtxt2 ' .. victim .. ' ' .. id .. ' ""')
		
		return
	elseif hp <= 50 then
		state  = '\169255192192BAD'
	elseif hp <= 75 then
		state = '\169255255192NOT GOOD'
	else
		state = '\169192255192GOOD'
	end
	
	parse('hudtxt2 ' .. victim .. ' ' .. id .. ' "\169255255255Your Health: ' .. state .. '" 425 464 1 1')
end

addhook('hit', '_update_hp_hud')
addhook('spawn', '_update_hp_hud')
addhook('die', '_update_hp_hud')

parse('mp_hudscale 1') -- Avoid changing.

I fixed a couple things, but I'm unsure what is your problem.
This code works flawlessly.

Do you want it to appear on TOP of the player? Visible to everyone? I'm confused.

old Re: Hud Health

Mami Tomoe
User Off Offline

Quote
No what? The script works perfectly for me.
Do you have any other HUD Text IDs in use by other scripts?
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview