Hi everybody. Here is the question - how can I set the owner of every single spawned item on the SANDBOX map?
Right now code is based on hooks and looks like [CODE]hook.Add ("PlayerSpawnedProp", "SU_SetOwner", function (ply, mdl, ent)
ent.SU_Owner = ply
end)
hook.Add ("PlayerSpawnedRagdoll", "SU_SetOwner", function (ply, mdl, ent)
ent.SU_Owner = ply
end)[/CODE] and does so for vehicles, effects, npcs, sents and sweps, but I believe that there is much more intelligent way.
Also this script doesn't cover spawn of tool-based entities - like lamps, hoverballs etc. - any clues to find hook connected with these? Is there an universal hook like GM:OnEntityCreated, but with ply argument?
I'll appreciate any help and thanks for um... visiting the page c:
You mean set the owner in prop protection?
[QUOTE=YoutoYokodera;51630869]You mean set the owner in prop protection?[/QUOTE]
Yes, sort of.
Not sure if it will work correctly, but after spawning the entity, you could try using ENT:GetCreator()
[QUOTE=Gmod4phun;51630917]Not sure if it will work correctly, but after spawning the entity, you could try using ENT:GetCreator()[/QUOTE]
Doesn't work, outputs error "attempt to call method 'GetCreator' (a nil value)". Thanks for reply though.
ENT:CPPISetOwner(ply)
This will do with most prop protection
[QUOTE=YoutoYokodera;51631067]ENT:CPPISetOwner(ply)
This will do with most prop protection[/QUOTE]
Yeah, but I have no prop protection - I'm trying to make my own.
Still, you should make ur prop protection use CPPI, its named Common Prop Protection Interface for a reason.
[QUOTE=YoutoYokodera;51630869]You mean set the owner in prop protection?[/QUOTE]
[QUOTE=Klaes4Zaugen;51631211]Still, you should make ur prop protection use CPPI, its named Common Prop Protection Interface for a reason.[/QUOTE]
I understand and I will, but CPPI manual does not tell HOW to set entity's owner. And yeah, there is no connection with my question.
Something related to restrict all interaction to the spawner
[QUOTE=MediCat;51630786]
Also this script doesn't cover spawn of tool-based entities - like lamps, hoverballs etc. - any clues to find hook connected with these? Is there an universal hook like GM:OnEntityCreated, but with ply argument?
I'll appreciate any help and thanks for um... visiting the page c:[/QUOTE]
There is no universal hook as things being spawned by players are a sandbox concept, not a game one. Also if you would've taken a few seconds to search the wiki you could've found the related hooks to cover all your needs.
[t]http://puu.sh/tdf84/1d7c8e9516.jpg[/t]
If you're going to be handling all related code that goes along with this, set a networked variable on the entity using your hooks.
[code]
hook.Add ("PlayerSpawnedRagdoll", "SU_SetOwner", function (ply, mdl, ent)
ent:SetNetworkedEntity("owner", ply)
end)
[/code]
Later, when you want to get the owner, you may just use GetNetworkedEntity (look up the Wiki reference). It will work clientside and serverside. You could even write a simple function to get the owner of an entity.
[code]
local meta = FindMetaTable("Entity")
function meta:GetOwner()
return self:GetNetworkedEntity("owner", nil)
end
[/code]
[QUOTE=pqbrown;51634113]If you're going to be handling all related code that goes along with this, set a networked variable on the entity using your hooks.
[code]
hook.Add ("PlayerSpawnedRagdoll", "SU_SetOwner", function (ply, mdl, ent)
ent:SetNetworkedEntity("owner", ply)
end)
[/code]
Later, when you want to get the owner, you may just use GetNetworkedEntity (look up the Wiki reference). It will work clientside and serverside. You could even write a simple function to get the owner of an entity.
[code]
local meta = FindMetaTable("Entity")
function meta:GetOwner()
return self:GetNetworkedEntity("owner", nil)
end
[/code][/QUOTE]
There is already a function called GetOwner so you best not override this function, call it GetCreator.
[QUOTE=Zeh Matt;51634237]There is already a function called GetOwner so you best not override this function, call it GetCreator.[/QUOTE]
Yeah, you're completely right. My bad.
[QUOTE=bigdogmat;51632240]There is no universal hook as things being spawned by players are a sandbox concept, not a game one. Also if you would've taken a few seconds to search the wiki you could've found the related hooks to cover all your needs.
[t]http://puu.sh/tdf84/1d7c8e9516.jpg[/t][/QUOTE]
You ain't absolutely right. I've got all these hooks used [CODE]hook.Add ("PlayerSpawnedProp", "SU_SetOwner", function (ply, mdl, ent)
ent.SU_Owner = ply
end)
hook.Add ("PlayerSpawnedRagdoll", "SU_SetOwner", function (ply, mdl, ent)
ent.SU_Owner = ply
end)
hook.Add ("PlayerSpawnedVehicle", "SU_SetOwner", function (ply, ent)
ent.SU_Owner = ply
end)
hook.Add ("PlayerSpawnedEffect", "SU_SetOwner", function (ply, ent)
ent.SU_Owner = ply
end)
hook.Add ("PlayerSpawnedNPC", "SU_SetOwner", function (ply, ent)
ent.SU_Owner = ply
end)
hook.Add ("PlayerSpawnedSENT", "SU_SetOwner", function (ply, ent)
ent.SU_Owner = ply
end)
hook.Add ("PlayerSpawnedSWEP", "SU_SetOwner", function (ply, ent)
ent.SU_Owner = ply
end)[/CODE] - you can check it, and still I can't get .SU_Owner variable from lamps, hoverballs etc. Thanks for reply, anyway :)
[editline]7th January 2017[/editline]
[QUOTE=pqbrown;51634113]If you're going to be handling all related code that goes along with this, set a networked variable on the entity using your hooks.
[code]
hook.Add ("PlayerSpawnedRagdoll", "SU_SetOwner", function (ply, mdl, ent)
ent:SetNetworkedEntity("owner", ply)
end)
[/code]
Later, when you want to get the owner, you may just use GetNetworkedEntity (look up the Wiki reference). It will work clientside and serverside. You could even write a simple function to get the owner of an entity.
[code]
local meta = FindMetaTable("Entity")
function meta:GetOwner()
return self:GetNetworkedEntity("owner", nil)
end
[/code][/QUOTE]
Thank you for the idea, looks better than .net library (for this purpose) :)
[QUOTE=MediCat;51635134]You ain't absolutely right. I've got all these hooks used :snip:[/QUOTE]
Hmm, strange there's no hook for that. After looking at 2 prop protections they both go down the route of detouring `cleanup.Add` and `plyMeta.AddCount`, e.g. [URL="https://github.com/FPtje/Falcos-Prop-protection/blob/42e54a55fd701c907d80a41ef93151e88b7f1fae/lua/fpp/server/core.lua#L52-L92"]fpp[/URL].
[QUOTE=bigdogmat;51635193]Hmm, strange there's no hook for that. After looking at 2 prop protections they both go down the route of detouring `cleanup.Add` and `plyMeta.AddCount`, e.g. [URL="https://github.com/FPtje/Falcos-Prop-protection/blob/42e54a55fd701c907d80a41ef93151e88b7f1fae/lua/fpp/server/core.lua#L52-L92"]fpp[/URL].[/QUOTE]
Absolutely agreed with you, and I noticed there are no prop protection addons that set owners of entities with hooks :(
Sorry, you need to Log In to post a reply to this thread.