What is used to tell the function to run on myself in clientsided lua? Example: self:EyePos( )

i dont think self is right but what is it? ply? what_do_i_put_here?:EyePos( )

It doesnt have to be for eyepos it’s just an example.

ply:DoSomething() is the right usage, check the wiki to see how it’s used (must be used in functions that have been given ply in the arguments)

Thank You! :smiley:

its not ply its LocalPlayer()

Ply should point to LocalPlayer().

It should be the same thing, but to use ply you’d need to include it as an argument in your function.

IE function Mah_func( ply )

“self”, i believe, is used when you wish to run a command on the entity tied to the script.
I’m not entirely sure, I’m still learning lua…

Yes, self is for example when you’re making a sENT and you want to set something, like self.Class = stuff you set the entity’s class

Self is used in metatables. When you make a scripted entity and you do stuff like ENT:Initialize you are adding to that entity’s metatable, and therefore self is automatically passed as that entity.

I.E. I make a function for my sEnt called ENT:DoStuff() I don’t need to pass the entity, because the syntax is:

And it is automatically passing ent_object as self since it is a metatable function.

In proper answer to maxterchief’s question, however, you would use LocalPlayer(), which returns the player object of the client running the script.



[lua]Client = LocalPlayer() – This way you have the variable as the object handle instead of calling LocalPlayer() again and again.