English Hud Health

13 replies
Goto Page
To the start Previous 1 Next To the start
12.06.19 05:01:13 pm
Up
- cILiMeend3R -
User
Offline Off
Hello guys.

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

Code:
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
12.06.19 05:33:33 pm
Up
panteon00
User
Offline Off
Code:
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:
Code:
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
loading...
12.06.19 06:50:22 pm
Up
- cILiMeend3R -
User
Offline Off
@user panteon00: i can't found hudtxt, but thank you
12.06.19 07:11:40 pm
Up
Goo
User
Offline Off
Code:
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')
13.06.19 03:12:32 pm
Up
- cILiMeend3R -
User
Offline Off
@user Goo: Work, but not work only change text in hudtxt2.
13.06.19 07:14:36 pm
Up
Goo
User
Offline Off
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).
14.06.19 11:01:23 am
Up
- cILiMeend3R -
User
Offline Off
@user Goo: I want every player with a certain health to have hudtxt2
14.06.19 12:57:07 pm
Up
Goo
User
Offline Off
Code:
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.
14.06.19 05:32:40 pm
Up
- cILiMeend3R -
User
Offline Off
@user Goo: Yea i want, every player can look only personal hud health. As so thank you.
15.06.19 07:55:02 pm
Up
Goo
User
Offline Off
That script works for me, did you try changing the hudtxt id?
15.06.19 08:37:18 pm
Up
- cILiMeend3R -
User
Offline Off
@user Goo: NO
15.06.19 09:31:59 pm
Up
Goo
User
Offline Off
No what? The script works perfectly for me.
Do you have any other HUD Text IDs in use by other scripts?
15.06.19 10:35:25 pm
Up
- cILiMeend3R -
User
Offline Off
@user Goo: I no change id hudtxt2, is work!
Thank you
15.06.19 11:04:58 pm
Up
Goo
User
Offline Off
Glad you found your way to the solution
To the start Previous 1 Next To the start