Client-Side HUDPaint issues.

Here’s the code to the HUD that is clientside.



function DrawHealthDisplay()
	local ply = LocalPlayer()
	
	if ply:Alive() == true then
		if ply.nextheal == nil then
			ply.nextheal = 0
		end
	
		local scw, sch
		scw = ScrW()
		sch = ScrH()
		
		local bwdith = scw / 8.5
		local bheight = 23
		
		if ply.nextheal > CurTime() then
			draw.RoundedBox( 6, 30, sch - 120, bwdith, bheight, Color( 255, 0, 0, 25 ) )
		else
			draw.RoundedBox( 6, 30, sch - 120, bwdith, bheight, Color( 0, 255, 0, 25 ) )
		end
		
		local struc = {}
		struc.pos = {}
		struc.pos[1] = 125
		struc.pos[2] = sch - 109 -- y pos
		
		if ply.nextheal > CurTime() then
			struc.color = Color(255,0,0,255)
			struc.text = "Next heal in: " .. math.Round(ply.nextheal - CurTime())
		else
			struc.color = Color(0, 255,0,255)
			struc.text = "You can heal now."
		end
		
		struc.font = "Trebuchet18"
		struc.xalign = TEXT_ALIGN_CENTER
		struc.yalign = TEXT_ALIGN_CENTER
		draw.Text( struc )
	end
end
hook.Add("HUDPaint", "DrawHealingBar", DrawHealthDisplay)


ply.nextheal is modified from outside this script as well. It runs perfectly on my side, however, I’m also the host of the server. In the other script, I have added to it:


AddCSLuaFile("client/cl_Healing_test.lua")

As these scripts are located in my: “Garrysmod\Garrysmod\Lua\Autorun” folder.

The main script is: “Autorun/Healing_test.lua”
The secondary script is: “Autorun/client/cl_Healing_test.lua”

The hud is being painted on the client, since I’ve added “ADDCSLuaFile” however, it’s not being changed when the ply.nextheal variable is modified. Like I said, it works perfectly on my side, just not on the client’s side.

Read about Usermessages They will let you send a value from the server to the client to update the ply.nextheal variable.

Thanks, I just read up about them, and implemented a usermessage hook into my code. It works flawlessly now. Thanks again.

[editline]27th March 2011[/editline]

Now I have another error that I didn’t notice:


attempt to call global 'RecipientFilter' (a nil value)

and my current code to send from server to client is:



                local filter = RecipientFilter()
		filter:AddPlayer(ply)
		
		umsg.Start("nextheal", filter)
			umsg.Float(ply.nextheal)
		umsg.End()


Don’t bother using recipientfilter if you are only sending it to one player, just use the player as the argument instead of filter in umsg.Start

When switching to that, now I get the error:


attempt to index global 'umsg' (a nil value)

And everything still works though. and again, the error is a onetime error, doesn’t repeat everytime.

Are you doing umsg: or umsg.

umsg. not umsg:

Are you calling it on the server? (Like you should do)

I am now, and there are no errors, thanks.