I’m currently working on a SWEP that fires entities, doing 5 damage to everything but not to the player that fired it.
function ENT:PhysicsCollide( data, physobj ) local hitent = data.HitEntity --Entity that is hit = HitEnt if hitent == self.Entity:GetOwner() then return 1 elseif hitent:IsPlayer() and hitent != self.Entity:GetOwner() then --Cannot hit Owner hitent:TakeDamage( 5, self.Entity:GetOwner() ) --Damage player hitent:ViewPunch( Angle( math.random(-1, 1), math.random(-1,1), math.random(-1,1) ) ) --Throw their aim self.Entity:Remove() --Remove shot elseif hitent:IsWorld() then self.Entity:Remove() --Remove if hits world elseif hitent:IsNPC() then hitent:TakeDamage( 7, self.Entity:GetOwner() ) --Damages NPCs self.Entity:Remove() else hitent:TakeDamage( 5, self.Entity:GetOwner() ) --Damages props, etc. self.Entity:Remove() end end
However, when the entity is frozen with the physgun and comes into contact with the owner it does damage. This damage is obviously as a result of the IsPlayer section as it also causes a view punch.
Any help on this problem would be appreciated. Also, is there any way to prevent the ability to physgun the entity? And on an unrelated note, the entities occasionally bounce off each something when rapidly firing at an NPC. Any suggestions as to what this may be?