Is there a way to store the last entity the player pressed 'E' on?
hook.Add("PlayerUse", "StorePlayerUse", function( ply, ent )
--Make sure the player and entity is valid.
if !ply:IsValid() or !ent:IsValid() then return end
--Set the value.
ply.LastEntityUsed = ent
end)
Make sure to check so ply.LastEntityUsed is not nil before using it. Also, this is serverside.
Alright, thank you!
Actually, one more thing, you put "!ply:IsValid()", but to check if it's valid shouldn't just be "IsValid(ply)", and the same for the ent?
they're both acceptable, but the gmod wiki recommends you use the global IsValid() instead
Entity/IsValid
I see, thank you for explaining!
Sorry, you need to Log In to post a reply to this thread.