Player Health

I need help, you see when I’m trying to make a HUD and I browse through the wiki, I can’t find any means of getting player health, can someone please help?

**[Entity.Health

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Entity.Health)**

Could you be a bit more specific please? Thanks. >_>

[lua]
function PrintHealth()

local plyhealth = LocalPlayer():Health();

print( plyhealth );

end
hook.Add( “HUDPaint”, “PrintHealth”, PrintHealth );
[/lua]

A HUD hook that prints your health to your console.

…I meant as in could you put a code example? Like I’ve got this for HUD Code already, but it isn’t working.




plyHealth = player:Health()

function drawGMHUD()
	roundsChambered = Player:GetActiveWeapon():Clip1()
	bulletsRemaining = Player:GetAmmoCount(Player:GetActiveWeapon():GetPrimaryAmmoType())
	specialMunitions = Player:GetAmmoCount(Player:GetActiveWeapon():GetSecondaryAmmoType())
		draw.RoundedBox( 3, 100, 80, 200, 60, Color( 255, 0, 0, 255 ) )
		draw.SimpleText( roundsChambered, "ScoreboardText", 35, 60, Color(220,220,40,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
		draw.SimpleText( bulletsRemaining, "ScoreboardText", 55, 60, Color(220,220,40,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
		draw.SimpleText( plyHealth, "ScoreboardText", 75, 50, Color(255,0,0,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
		
end



[editline]07:08PM[/editline]

Can’t anyone help? -_-

[lua]hook.Add(“HUDPaint”,“hud”, drawGMHUD)[/lua]

Seriously? You asked for a way to get a player’s health and that’s what he gave you. Stop being lazy. You will learn more by finding it out your self than by us spoon feeding you.

Use a HUDPaint hook like everyone has said and draw ply:Health() to their screen.

I did add hook, but I think like Entoros said, I need to use LocalPlayer() instead, so I’m going to try that.


local LocalPlayer() = ply

If you wanna use ply.

[lua]local ply = LocalPlayer()[/lua]

oh, right :doh:

[editline]03:23PM[/editline]

MakeR, now fully animated!:bubblewoop:

If you are talking about my avatar, it was animated anyway. You just weren’t using Firefox. (APNG)

No, my browser havent changed. Still using Inter Net Explorer version ?

Well, until recently, your avatar has just been the red version of your monster, not moving, ofcourse.

It was animated using an animated png which (AFAIK) only firefox supports.

Anyway, lets stay on topic.

You can switch to gif now :holy:

I have switched to gif.

[lua]
hook.Add(“HUDPaint”, “MyHUD”, function() – Make the hook
if !LocalPlayer() or !LocalPlayer():Alive() then return end – If we haven’t spawned yet, our entity isn’t valid for some reason, or we’re dead, don’t do anything
draw.SimpleText( "Health: " … LocalPlayer():Health(), “ScoreboardText”, ScrW() / 2, ScrH(), Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) – Draw the text
end ) – End the function
[/lua]