Usermessage troubles

Basically I want to use an usermessage to set some properties clientside. And it’s not working. :smile:

At the moment I get the following error :

cl_init.lua:20: attempt to index global ‘ENT’ (a nil value)
[lua]function ENT:DrawAmount(pos, amount)
self.PickedUp = true
self.pos, self.amount = pos, amount

local function ReadUMSG(um)
ENT:DrawAmount(um:ReadVector(), um:ReadShort()) – Line 20

usermessage.Hook(“DrawPickedUp”, ReadUMSG)[/lua]
Could anyone tell me how to do this properly?

Replace ENT with the name of your entity.

Oh right, pass the ent index. It just seemed really weird that I can’t access an entity it it’s own method.

No, the name of the entity.

If you do

lol = ent.Create(‘lol_ent’) (idk if this is the right syntax)

then you do

function lol:DrawAmount() …

You can do the ent index if you want, but this is easier if it’s an ent you’ve created. Just put a variable that holds the ent in front of the :.

The entity is not named and I imagine there could be anywhere up to 30-40 of these at once (or more) so I’d have to create a global table to index them all so I can reference them per their unique index in the table. And that would require an index, so I’m better off sending an EntIndex. Or I could give the entity a unique name but then I’d have to pass that too. I have no way of knowing in advance to which entity I will need to send that. So again it’s either finding a way to access the entity from one of it’s methods or passing an ent index.

um:ReadEntity():DrawAmount(um:ReadVector(), um:ReadShort()) :3:

That won’t work if you immediately send the usermessage when the entity is initialized serverside, at least not for me, because the client usually receives the message before the concerned entity even exists clientside.

Now, if you intend to set your properties later, it’s not a problem.