Auto Turret credit kills to owner?

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)

You could create the turret manually and use FireBullets( bullet table )

Then, in your bullet structure you could do

[LUA]bullet.Attacker = self.Owner[/LUA]

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?

You should be able to:: PLAYER:AddFrags( 1 ); where PLAYER is the owner of the turret when a player is killed and the attacker/entity is a turret.

The only problem is that it is in TTT, I have a script that shows who killed you and it wouldn’t show up on that.

Why not? Set the Frags in PlayerDeath. Now, the thing that shows who kills you would see the entity right? Add something like this to that ::

[lua]// If the killer was a turret
if ( killer:GetClass == “turret” ) then
// Show the killer name as the entity owner.
end[/lua]

Edit : Changed how it was written but forgot to remove the !

Wow, I didn’t think of that. I’ll go try it out and let you know if it worked.

[editline]30th September 2013[/editline]

Hey thanks, it worked. It took a bit of fiddeling but it is working now :slight_smile:

Thanks guys.