• Usermessage troubles
    6 replies, posted
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 end local function ReadUMSG(um) ENT:DrawAmount(um:ReadVector(), um:ReadShort()) -- Line 20 end usermessage.Hook("DrawPickedUp", ReadUMSG)[/lua] Could anyone tell me how to do this properly?
Replace ENT with the name of your entity.
[QUOTE=yakahughes;17871621]Replace ENT with the name of your entity.[/QUOTE] Oh right, pass the ent index. It just seemed really weird that I can't access an entity it it's own method.
[QUOTE=Crazy Quebec;17871895]Oh right, pass the ent index. It just seemed really weird that I can't access an entity it it's own method.[/QUOTE] 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 :.
[QUOTE=yakahughes;17871937]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 :.[/QUOTE] 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:
[QUOTE=Lexic;17874037]um:ReadEntity():DrawAmount(um:ReadVector(), um:ReadShort()) :3:[/QUOTE] 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.
Sorry, you need to Log In to post a reply to this thread.