Help, please!
I'm trying to check if owner of entity presses USE on it, but this doesn't work. Everytime the answer is "Error."..
Why? Help me please! Thanks.
[CODE]
function ENT:Use(activator)
if activator == self.Owner then
activator:ChatPrint("Done!")
else
activator:ChatPrint("Error.")
end
end
[/CODE]
(P.S. Sorry for my bad englsh)
Did you actually assign the field "Owner" to anything?
Without seeing the rest of the code...I can only assume self.Owner is not what you expected it to be. How are you creating the entity? Are you using ent:SetOwner or anything (if so, use ent:GetOwner())?
You can test this:
[code]
function ENT:Use(activator)
MsgN(activator:Nick())
MsgN(self.Owner:Nick())
end
[/code]
I'd be willing to bet the second line within the function will fail, something along the lines of self.Owner being null or not a player object. But yes, post the full code
[QUOTE=Trumple;41732779]Without seeing the rest of the code...I can only assume self.Owner is not what you expected it to be. How are you creating the entity? Are you using ent:SetOwner or anything (if so, use ent:GetOwner())?
You can test this:
[code]
function ENT:Use(activator)
MsgN(activator:Nick())
MsgN(self.Owner:Nick())
end
[/code]
I'd be willing to bet the second line within the function will fail, something along the lines of self.Owner being null or not a player object. But yes, post the full code[/QUOTE]
He shouldn't use Get/SetOwner, they're for something entirely different AFAIK.
[QUOTE=EvacX;41732837]He shouldn't use Get/SetOwner, they're for something entirely different AFAIK.[/QUOTE]
I think you're right, but we have no idea what he's trying to do here :v:
[QUOTE=Trumple;41732925]I think you're right, but we have no idea what he's trying to do here :v:[/QUOTE]
I trying to edit the Money Pot script: Only owner can pickup money from Money Pot.
[QUOTE=EvacX;41732837]He shouldn't use Get/SetOwner, they're for something entirely different AFAIK.[/QUOTE]
I remember garry adding a function to entities during one of his streams, it's called :SetOwner or something similar. I asked him whether it's okay to use it for propprotection and similar stuff, he said yes.
[QUOTE=Co2;41733090]I remember garry adding a function to entities during one of his streams, it's called :SetOwner or something similar. I asked him whether it's okay to use it for propprotection and similar stuff, he said yes.[/QUOTE]
Except for the fact that it will make player nocollide will all his props then and won't be able to +use them.
[QUOTE=Co2;41733090]I remember garry adding a function to entities during one of his streams, it's called :SetOwner or something similar. I asked him whether it's okay to use it for propprotection and similar stuff, he said yes.[/QUOTE]
That's just what the wiki says [b][url=http://gmodwiki.net/Lua/Classes/Entity/SetOwner]Lua/Classes/Entity/SetOwner[img]http://gmodwiki.net/favicon.ico[/img][/url][/b] and [url=http://wiki.garrysmod.com/page/Entity/SetOwner]Official Wiki[/url].
I searched through GMod's lua files and couldn't find anything regarding Get/SetOwner, however I found this:
[lua]
if ( SERVER ) then
function meta:SetCreator( ply )
self.m_PlayerCreator = ply
end
function meta:GetCreator()
return self.m_PlayerCreator;
end
end[/lua]
Possibly use Set/GetCreator, since they're already there?
Since DarkRP is using FPP the owner should be assigned with CPPI.
Get the owner of the entity with
[lua]
self:CPPIGetOwner()
[/lua]
[QUOTE=ms333;41734871]Since DarkRP is using FPP the owner should be assigned with CPPI.
Get the owner of the entity with
[lua]
self:CPPIGetOwner()
[/lua][/QUOTE]
Nobody mentioned DarkRP before you.
Isn't the money pot script for darkrp?
(S/G)etOwner shouldn't be used, IIRC it's used on weapons that someone is holding.
For example :
[img]http://puu.sh/3Vr1E.png[/img]
It causes weird physics oddities when used on entities, as Robotboy said, one of the side effects is having them no-collide with the owner (like weapons do).
[QUOTE=EvacX;41733302]Set/GetCreator[/QUOTE]
That's what I was talking about.
[QUOTE=Co2;41739580]That's what I was talking about.[/QUOTE]
Well there's a big difference between Get/SetCreator and Get/SetOwner.
Get/SetCreator are quite useless to be honest, they're just direct wrappers for the field "m_PlayerCreator" on any entity and the creator isn't set automatically, you have to do that yourself too.
Sorry, you need to Log In to post a reply to this thread.