HudPaint questions on displaying certain information

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

[lua]Hook ‘PlayerHud’ Failed: [gamemodes\warhammer_quest\gamemode\cl_init.lua:143] attempt to call method ‘GetMaxHealth’ (a nil value)[/lua]

[lua]function PlayerHud()

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?

Look at User Messages

Here’s an example:

function updateInfo()
for i, p in pairs(player.GetHumans()) do – Get’s all the players
umsg.Start(“updateInfo”, p) – Start a usermessage called update info to be sent to player p
umsg.Long(p:GetMaxHealth()) – send the player their max health

localPlayerMaxHealth = 0

function getInfo(msgData)

localPlayerMaxHealth = msgData:ReadLong() – Read the message

usermessage.Hook(“updateInfo”, getInfo)


[editline]9th March 2011[/editline]

-double snip-

Thanks again for your help ??? and Fantym420. I wasn’t looking for the right information and didn’t think User Messages was what I needed. I totally missed Datastreams too so thanks for pointing that out.

I’ll play around with it but essentially I’ll initialize all the variables I want to be displayed on one function. Then update those variables separately through the logic I have set up.