Do something when player is killed with my swep

I want to make a gun for my cops that kick people when they are killed with it. However I cant find a hook for doing something on player death (one that I can use with ANY gamemode so I guess GM:OnPlayerDeath wont do it).

What is a good way to do something when a player dies from that gun?

GM:PlayerDeath and check if inflictor is your weapon.

I am not developing a GameMode. I cant use a Gamemode hook then, right?

Use hook.Add.

You can use a gamemode hook. It’ll look like this.

hook.Add("PlayerDeath", "HookIdentifier", function(victim, inflictor, attacker)
    --do something

Note there is no GM prepended to PlayerDeath. It doesn’t matter when you use GM hooks.

inflictor:GetClass() always returns player and not my swep class. Why?

Because you haven’t set the inflictor correctly in your weapon.

How do you do that?

I’ll say it again;

Please feel free to point out any other mistakes. I know I should set the primary delay using the approperate setting BUT it doesnt do anything. So please point out all mistakes if possible :wink:

if SERVER then // This is where the init.lua stuff goes.
	//This makes sure clients download the file
	AddCSLuaFile ("shared.lua")
	//How heavy the SWep is
	SWEP.Weight = 5
	//Allow automatic switching to/from this weapon when weapons are picked up
	SWEP.AutoSwitchTo = false
	SWEP.AutoSwitchFrom = false
	      SWEP.Primary.Damage =10
      SWEP.Primary.Delay = 10000
elseif CLIENT then // This is where the cl_init.lua stuff goes
	//The name of the SWep, as appears in the weapons tab in the spawn menu(Q Menu)
	SWEP.PrintName = "banner 5000"
	//Sets the position of the weapon in the switching menu 
	//(appears when you use the scroll wheel or keys 1-6 by default)
	SWEP.Slot = 2
	SWEP.SlotPos = 1
	//Sets drawing the ammuntion levels for this weapon
	SWEP.DrawAmmo = true
	//Sets the drawing of the crosshair when this weapon is deployed
	SWEP.DrawCrosshair = true
SWEP.Author = "MoustacheSpy"
SWEP.Contact = ""
SWEP.Purpose = "A gun that bans people for 60 minutes"
SWEP.Instructions = "shoot people"

SWEP.Category = "Cop stuff"

SWEP.Spawnable = true -- Whether regular players can see it
SWEP.AdminSpawnable = true -- Whether Admins/Super Admins can see it

SWEP.ViewModel = "models/weapons/v_Pistol.mdl" -- This is the model used for clients to see in first person.
SWEP.WorldModel = "models/weapons/w_Pistol.mdl" -- This is the model shown to all other clients and in third-person.

//This determins how big each clip/magazine for the gun is. You can 
//set it to -1 to disable the ammo system, meaning primary ammo will 
//not be displayed and will not be affected.

SWEP.Primary.ClipSize = 30
//This sets the number of rounds in the clip when you first get the gun. Again it can be set to -1.
SWEP.Primary.DefaultClip = 900
//Obvious. Determines whether the primary fire is automatic. This should be true/false
SWEP.Primary.Automatic = true

//Sets the ammunition type the gun uses, see below for a list of types.
SWEP.Primary.Ammo = "Pistol"

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"

//When the script loads, the sound ''Metal.SawbladeStick'' will be precached, 
//and a local variable with the sound name created.
local ShootSound = Sound("Weapon_Pistol.Single")

status_prim = true
status_sec = true
function resetPrim()
	status_prim = true


function resetSec()
	status_sec = true

function SWEP:PrimaryAttack()
	if status_prim==true then
		//Call the throw attack function, with the office chair model
		status_prim = false;
		timer.Simple(0.005, resetPrim);

function SWEP:SecondaryAttack()
	if status_sec == true then
		self.Owner:ViewPunch( Angle( -5, 0, 0 ) )
		status_sec = false;
		timer.Simple(0.5, resetSec);

[editline]28th September 2017[/editline]

I changed the sound thing cause it was wrong from me trying things. Sorry I forgot to change it before I posted

use attacker:GetActiveWeapon() in your hook to get the weapon.

Yeah, don’t rely on the engine to provide a weapon for the inflictor – Source is extremely inconsistent in that.