Sending entity data to client

I have a cash entity, and the self.Entity.Cash need’s to be assessable from clients in cl_init.lua, for using cam.Start3D2D() to allow the entity’s cash to just hover above it. It is assessable easily from init.lua, but it just returns nil and throws a ton of errors upon attempting to call from client.

Code extract:
[lua]
function ENT:Use(activator, caller)
if ValidEntity(activator) then
if activator:IsPlayer() and activator:Alive() then
activator:AddCash(tonumber(self.Entity.Cash))
if activator == self.Entity.Owner then
evolve:Notify(self.Entity.Owner, evolve.colors.white, “You picked up your own dropped money!”)
else
evolve:Notify(activator, evolve.colors.white, "You have picked up ", team.GetColor(self.Entity.Owner:Team()), self.Entity.Owner:Nick(), evolve.colors.white, "'s Cash: “, evolve.colors.blue, “$”… tostring(self.Entity.Cash), evolve.colors.white, “!”)
evolve:Notify(self.Entity.Owner, evolve.colors.blue, activator:Nick(), evolve.colors.white, " picked up your dropped money!”)
end
self.Entity:Remove()
end
end
end
[/lua]

(Friendly Bump)

Isn’t ‘Use’ a server side only function?

Yeah, that extract is from init.lua, to show how the self.Entity.Cash is implemented.

So you’re trying to draw the amount of money in the entity on a Cam2d3d?

I think you’d want to do something like this in the Draw function.

It is, Here:

[lua]
function ENT:Draw()
self.Entity:DrawModel()
local pos = self.Entity:GetPos()
local ang = self.Entity:GetAngles()
local right = ang:Right()
local dir = ang:Forward():Angle()
local fwd = ang:Forward()

dir:RotateAroundAxis(dir:Right(), -90)
dir:RotateAroundAxis(dir:Up(), 90)

cam.Start3D2D(pos + Vector(0, 0, 100) + fwd, dir, 0.7 )
	draw.DrawText("$".. self.Cash, "TabLarge", 0, 0, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER ) // This is line 22
cam.End3D2D()

end
[/lua]

But the self.Entity.Cash is coming up as invalid.

Store your cash as a networked integer, using Entity.SetNetworkedInt to store the value on the entity.

Then on the client side, use Entity.GetNetworkedInt to get the value on the client end.

[editline]5th January 2012[/editline]

You don’t need to use ‘.Entity’ in your self calls.

In your case, ‘self’ substitutes as ‘entity’.

Replace every instance of ‘self.entity.’ with ‘self.’

[entities\rp_cash\cl_init.lua:22] attempt to concatenate field ‘Cash’ (a nil value)

Updated code to newest in above code…

[editline]5th January 2012[/editline]

Sorry my mistake, didn’t see your entire post…

[editline]5th January 2012[/editline]

Ah that did it, thanks!