I want to make the player’s screen redder when it is below 20 hp for a short time every time he takes a damage.
I don’t understand, I just made a red screen
hook.Add( "HUDPaint", "HUDPaint_DrawABox", function()
hud_health = ply:Health()
if ( hud_health <= 20 ) then
draw.RoundedBox( 0, 0, 0, ScrW(), ScrH(), Color( 255, 0, 0, 155 ) )
end
end )
Where did you get draw.RoundedBox from? Why are you trying to draw a rectangle with 0 rounded corners? It’s a bit slower than surface.DrawRect.
Anyway, I didn’t really explain enough before. I just gave some basic example functions that you’ll need. This might help:
local fade = 0
local prevHealth = 100
hook.Add( "HUDPaint", "DrawRed", function()
local health = LocalPlayer():Health()
surface.SetDrawColor( 255, 0, 0, fade )
surface.DrawRect( 0, 0, ScrW(), ScrH() )
if health <= 20 and prevHealth > health then
fade = 150
end
fade = math.Clamp( fade - 1, 0, 255 )
prevHealth = health
end )
This code is pretty messy but I can’t think of a better way to do it. At least it works.
Ok, it’s a bit slower though so I changed it