It’s my first try giving Lua a go so i decided to do something i hoped to be simple, but once i got a working health bar going i realized that it was a little small, so i tried doing a calculation:
function MGSHud()
local health = LocalPlayer():Health()
surface.SetDrawColor( 120, 120, 255, 50 )
surface.DrawRect( 40, 40, 350, 20 )
surface.SetDrawColor( 100, 255, 100, 180 )
surface.DrawRect( 40, 40, Health * 3.5, 20 )
end
hook.Add( "HUDPaint", "MGSLife", MGSHud )
Somehow, i managed to screw up real bad and now a health bar no longer displays, and when ever i go into Garry’s Mod with it on i get this Lua error:
Hook 'MGSLife' Failed: [addons\mgshud\lua\autorun\client\mgshud.lua:9] attempt to perform arithmetic on global 'Health' (a nil value)
Well for some reason your health is buggered up and it reads health as nil. Im still learning, but is the health variable buggered up somewhere, it says the error is on line 9, so post that up
To refresh the hud, since I am editing it while still playing, do i need to disconnect and start another single player game or do i need to restart Gmod for Hud changes to take effect?