Hey guys, I have been making an auto turret SWEP. It spawns the NPC but I was wandering, how would I make it so the kills that the turret gets are credited to the owner? I am not even sure if this is possible. I have thought of some hacky solutions but I would like to know if there is a proper way.
Here is a snippet of code:
turret = ents.Create( "npc_turret_floor" )
local tr = util.TraceLine({start=ply:GetShootPos(), endpos=ply:GetShootPos() + ply:GetAimVector() * 230, filter={ply, self.Entity}, mask=MASK_SOLID})
if tr.HitNonWorld then return end
if tr.HitWorld then
turret:SetHealth(55)
turret:SetPos(tr.HitPos)
turret:DropToFloor()
turret:SetAngles(Angle(0,self.Owner:EyeAngles().y,self.Owner:EyeAngles().r))
self.Owner:EmitSound(placesound)
That would work, but that means I would have to spend forever making my own auto turret :P.
I might be able to make the turret out of ammo so it doesn’t fire but it still aims at people, then parent the firebullet to its muzzle. But how would I do that?