• Is there a difference between self:GetOwner() and LocalPlayer() on CL swep hooks
    3 replies, posted
Are these two situations functionally identical? function SWEP:PrimaryAttack() if (CLIENT) then print(LocalPlayer()) end end function SWEP:PrimaryAttack() if (CLIENT) then print(self:GetOwner()) end end Is there any reason why I should prefer to use GetOwner over LocalPlayer?
GetOwner - Returns the owner entity of this entity. - To get the owner, there needs to be a SetOwner() in the entity in order for GetOwner to return information. Example: Smith spawned a money printer < -- SetOwner (smith's printer) - An admin wants to see whos entity, so they run a GetOwner() on the money printer to return the owner of the entity. Entity.GetOwner ^ LocalPlayer - Returns the player object of the current client.
Yes, thank you for the wiki copypasta but it definitely does not answer my question. I didn't ask what GetOwner and LocalPlayer were respectively, as I am proficient enough at coding to know that, I asked whether the two situations presented were functionally equivalent in clientside SWEP hooks, and what the preferred method of getting a swep's user was and why. (Is there an advantage to :GetOwner() instead of LocalPlayer() in this scenario?)
If I'm Player 2 looking at Player 1 holding SWEP, SWEP.GetOwner() is Player 1. LocalPlayer() is Player 2. If I'm Player 2 holding SWEP, SWEP.GetOwner() and LocalPlayer() are both Player 2.
Sorry, you need to Log In to post a reply to this thread.