• Best way to stop players from physgunning an entity
    8 replies, posted
[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? :P 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.
[QUOTE=MegaJohnny;20441025]How are you going to identify this "single entity"? You could do with being a bit more specific.[/QUOTE] Thats what i want to know aswell :P Could try this. [code] 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 [/code]
I got it. Thanks a lot though guys.
[QUOTE=Wizey!;20441044]Thats what i want to know aswell :P Could try this. [code] 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 [/code][/QUOTE] 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]
[QUOTE=Lexic;20452676]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.[/QUOTE] 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 [url=http://www.facepunch.com/showthread.php?t=901040]thread[/url]. I'd really appreciate it.
Sorry, you need to Log In to post a reply to this thread.