Hello, I’ve been trying to make my own RPG in Gmod, and the whole learning experience has been going steady for the most part. The problem I’m having is using global variables executed in init.lua and incorporating them into a HUDPaint Hook done in cl_init.lua. Apparently you can’t do that as far as I’ve read.
I just want to be able to add things to a players HUD, and give them information on their stats, warrior class, health, movement, speed, and etc in there. Also, I plan on putting another mini HUD on top of the screen that shows their party members brief stats.
So far I experimented with this tutorial found here http://wiki.garrysmod.com/?title=Creating_a_HUD
[lua]Hook ‘PlayerHud’ Failed: [gamemodes\warhammer_quest\gamemode\cl_init.lua:143] attempt to call method ‘GetMaxHealth’ (a nil value)[/lua]
client = client or LocalPlayer( ); if( !client:Alive( ) ) then return; end local hpcur = client:Health() local hpmax = client:GetMaxHealth() --This is line 143 local _, th = good_hud:TextSize( "TEXT", vars.font ); local i = 2; local width = vars.width * ScrW( ); local bar_width = width - ( vars.padding * i ); local height = ( vars.padding * i ) + ( th * i ) + ( vars.text_spacing * i ) + ( vars.bar_height * i ) + vars.bar_spacing; local x = vars.margin; local y = ScrH( ) - vars.margin - height; local cx = x + vars.padding; local cy = y + vars.padding; good_hud:PaintPanel( x, y, width, height, colors.background ); local by = th + vars.text_spacing; local healthtext = string.format( "Health: %i HP", hpcur ) good_hud:PaintText( cx, cy, healthtext, vars.font, colors.text ); good_hud:PaintBar( cx, cy + by, bar_width, vars.bar_height, colors.health_bar, hpcur / hpmax );
hook.Add(“HUDPaint”, “PlayerHud”, PlayerHud)[/lua]
It looks like GetMaxHealth() can only be used on the Serverside and not on the Clientside of the script. I just want to be able to get their max health (and any other information that I create), and be able to display it on their hud. Is there any way to bridge them over to the Clientside or am I doing this incorrectly?