I have a addon that i need help allowing the player who bought the entity (DarkRP) to be able to move it with a physgun, i would like this entity to be picked up only by the player who spawned it and can use the physgun on it. I have tried multiple tricks im a okay dev but when it comes to this one small thing, i have no idea.
[lua]function ENT:PhysgunPickup(ply, ent)
return IsValid(ent) and ply == ent:Getowning_ent()
If you ask, in which file this code goes in, then your likely not a good developer.
Most prop protection addons implement something called the Common Prop Protection Interface. Basically, your PP addon of choice defines the global functions and variables specified here and then any other compatible addon may use them as well. In fact, DarkRP itself uses CPPI internally to check for ownership, etc.
If you use FPP (included by default in DarkRP AFAIK), you can add a function to the entity called PhysgunPickup, and that will be called to test if a player can pick up the entity.
function ENTITY:PhysgunPickup(ply, ent)
return ent:CPPIGetOwner() == ply
The following snippet should, in principle, allow only the owner of the entity to pick it up, even excluding whatever players they added to their friends list.
Alternatively, you could use
[lua] return ent:CPPICanPhysgun(ply) [/lua]
if you want to use FPP’s physgun permissions (which might be disabled) or some other combination.
this is great but still didnt help i spawn the entity in through the F4 menu and it says it is a world Prop not “Gunz Blazzinn” or my name so i cant move it with a physgun still.
Also if you would like to know the addon name please reply yes and i will give you it untill then idk if im allowed to post it
I actually gave you the code which would work that way.
Then i must be a bad developer cus i put it in the lua for the Entity and all it does is play a error when i pick it up through the spawn entity menu not the F4 menu ( Still cant pick it up when spawned from F4 menu )
Error in hook PhysgunPickup: addons/mediaplayer/lua/entities/mediaplayer_base/shared.lua:46: attempt to index local 'ent' (a nil value) stack traceback: addons/mediaplayer/lua/entities/mediaplayer_base/shared.lua:46: in function <addons/mediaplayer/lua/entities/mediaplayer_base/shared.lua:45> [C]: in function '••' [ERROR] 1. unknown - [C]:-1
This was also pasted in 3 other locations just to test ( Init.lua, Cl_Init.lua, and shared.lua in another folder seperate )
Because you dont put the function like ENTITY: but rather like ENT:
Still isn’t working i tried it on two other entities as well.