Best way to stop players from physgunning an entity

[lua]function physgunPickup( ply, ent )
if ent:GetClass() == “player” then
return false // Don’t allow them to pick up players!!
else
return true // If not a player, allow them to pick up the item.
end
end

hook.Add( “PhysgunPickup”, “physgunPickup”, physgunPickup );[/lua]

Is this the best way to stop a player from physgunning an entity? I want to stop them from picking up a single entity and was wondering if this was the best possible way.

function DatPhysgun()
for k,v in pairs (player.GetAll()) do
if v:HasWeapon(“weapon_physgun”) then
v:StripWeapon(“weapon_physgun”)
end
end
end
hook.Add(“Tick”, “RAWRARAWRARRAWRAWRW”, DatPhysgun)

Not sure if thats what you want but an entity is a prop and or sent. so… Just strip it? :stuck_out_tongue:

Im just saying, if they cant pick anything up with it, then why have it.

How are you going to identify this “single entity”? You could do with being a bit more specific.

Thats what i want to know aswell :stuck_out_tongue:

Could try this.



function GM:PhysgunPickup( ply, ent )

	if ( ent:GetClass() == "player" ) then return false end
	if ( ent:GetClass() == "myentity" ) then return false end -- PRUNE JUICE! :3

	return true
end


I got it. Thanks a lot though guys.

Prune juice is gross, Wizey.

If this is for Sandbox or for a Sandbox derived gamemode that hasn’t mutilated it’s PhysgunPickup hook like that, then you simply need to set PhysgunDisabled = true on the entity.
For instance:
[lua]function ENT:Initialize()
self:SetModel(“models/props_wasteland/prison_padlock001a.mdl”);
self:SetMoveType(MOVETYPE_VPHYSICS);
self:PhysicsInit(SOLID_VPHYSICS);
self:SetSolid(SOLID_VPHYSICS);
self:SetUseType(SIMPLE_USE);
self:SetCollisionGroup(COLLISION_GROUP_WORLD)
self.PhysgunDisabled = true
self.m_tblToolsAllowed = {}

-- Get the physics object of the entity.
local physicsObject = self:GetPhysicsObject();

-- Check if the physics object is a valid entity.
if ( ValidEntity(physicsObject) ) then
	physicsObject:Wake();
	physicsObject:EnableMotion(true);
end

end[/lua]
or if you have spawned the entity yourself
[lua]local ent = ents.Create(“prop_physics”);
if (not IsValid(ent)) then return end
ent:SetModel (tab[1]);
ent:SetAngles(tab[2]);
ent:SetPos (tab[3]);
ent.PhysgunDisabled = true;
ent.m_tblToolsAllowed = {};
ent:Spawn();[/lua]

If it’s not for Sandbox, then just add this:
[lua]hook.Add(“PhysgunPickup”, “CheckCanPhysgunPickup”, function(pl, ent)
if ent.PhysgunDisabled then return false end
end)[/lua]

I got it all running how I like.
Thanks for all your help guys. However, if you’d help me in this thread. I’d really appreciate it.