NpcKilled addfrag to player

Hello,

I need a little bit help for GM:OnNPCKilled( NPC npc, Entity attacker, Entity inflictor ) function



function GM:OnNPCKilled(npc, killer, weapon)
	if killer && killer:IsValid() && killer:IsVehicle() && killer:GetDriver():IsPlayer() then
		killer = killer:GetDriver()
	end

 if killer && killer:IsValid() && killer:IsPlayer() && npc && npc:IsValid() then

  if NPC_POINT_VALUES[npc:GetClass()] then
	killer:AddFrags(NPC_POINT_VALUES[npc:GetClass()])
	killer:AddXP(NPC_POINT_VALUES[npc:GetClass()])
	killer:PrintMessage( HUD_PRINTCONSOLE, "You received: "..NPC_POINT_VALUES[npc:GetClass()].. " Xp" )
  else
	killer:AddFrags(1)
  end

 end

end


Here I create the tables



NPC_POINT_VALUES = {
	["npc_antlionguard"] = 50,
	["npc_antlion"] = 2,
	["npc_citizen"] = 0,
	["npc_cscanner"] = 1,
	["npc_crabsynth"] = 1,
	["npc_stalker"] = 3,
	["npc_combinedropship"] = 10,
	["npc_combinegunship"] = 50,
	["npc_crow"] = 0,
	["npc_helicopter"] = 1000,
	["npc_ministrider"] = 2,
	["npc_pigeon"] = 0,
	["npc_strider"] = 50,
	["npc_metropolice"] = 1,
	["npc_combine_s"] = 1,
	["npc_hunter"] = 10,
	["npc_manhack"] = 1,
	["npc_turret_ceiling"] = 3,
	["npc_turret_floor"] = 3,
	["npc_turret_ground"] = 3,
	["npc_sniper"] = 5,
	["npc_zombie"] = 1,
	["npc_poisonzombie"] = 3,
	["npc_zombine"] = 2,
	["npc_fastzombie"] = 2,
	["npc_zombie_torso"] = 1,
	["npc_headcrab"] = 1,
	["npc_headcrab_fast"] = 1,
	["npc_headcrab_black"] = 1
}


My question is why npc_sniper , npc_combinegunship , npc_helicopter not give any points? and it is never notified.

Are you sure the hook is called for those NPCs? Are you sure “killer” variable for those NPCs is set in the hook?

Also you should totally change “npc && npc:IsValid()” to “IsValid( npc )” for all your entity variables. It just makes the code more readable & shorter for yourself.

I will check thanks.

It isnt working I added a print on console but it never says killed any npc_combinegunship or npc_sniper or npc_helicopter but the class name is the same but it isnt tracking it.
Maybe the npc not die just removed?

here is the full code



// Called when an NPC dies
function GM:OnNPCKilled(npc, killer, weapon)
	if killer && killer:IsValid() && killer:IsVehicle() && killer:GetDriver():IsPlayer() then
		killer = killer:GetDriver()
	end
	
	// If the killer is a player then decide what to do with their points
	--if !HL2MP_IS_COOP_MAP then
	if killer && killer:IsValid() && killer:IsPlayer() && IsValid( npc ) then
		if table.HasValue(GODLIKE_NPCS, npc:GetClass()) || npc:GetName() == "rocketman" then
			if !game.SinglePlayer() then -- This should only end up being used in multiplayer.
				if !HL2MP_IS_COOP_MAP then
				game.ConsoleCommand("kickid "..killer:UserID().." \"Killed an important NPC actor!\"
")
				GAMEMODE:RestartMap()
				end
			end
		elseif NPC_POINT_VALUES[npc:GetClass()] then
			killer:AddFrags(NPC_POINT_VALUES[npc:GetClass()])
			killer:AddXP(NPC_POINT_VALUES[npc:GetClass()])
			killer:PrintMessage( HUD_PRINTCONSOLE, "You received: "..NPC_POINT_VALUES[npc:GetClass()].. " Xp by killing "..npc:GetClass() )
		else
			killer:AddFrags(1)
		end
	end
	--end

	
	// Convert the inflictor to the weapon that they're holding if we can. 
 	if weapon && weapon != NULL && killer == weapon && (weapon:IsPlayer() || weapon:IsNPC()) then 
 		weapon = weapon:GetActiveWeapon() 
 		if killer == NULL then weapon = killer end 
 	end 
 	
	// Defaults
 	local weaponClass = "World" 
 	local killerClass = "World" 
 	
	// Change to actual values if not default
 	if weapon && weapon != NULL then weaponClass = weapon:GetClass() end 
 	if killer && killer != NULL then killerClass = killer:GetClass() end 
	
	// Play a random taunt sound
	if GetConVarNumber("hl2c_additions") >= 1 then
		if killer && killer != NULL && killer:IsPlayer() then
			if (table.HasValue(FRIENDLY_NPCS, npc:GetClass()) || table.HasValue(GODLIKE_NPCS, npc:GetClass())) then
				return
			end
		
			if (math.random(1, 6) <= 3) then
				PlayerTaunt(killer)
			end
		end
	end
	
	// Send a message
 	if killer && killer != NULL && killer:IsPlayer() then 
		net.Start("PlayerKilledNPC")
			net.WriteString(npc:GetClass())
			net.WriteString(weaponClass)
			net.WriteEntity(killer)
		net.Broadcast()
 	end
end


can I use the npc_helicopter entity ? or it will override all functions of the entity? like I create a lua file on my entities folder as npc_helicopter?


AddCSLuaFile()
function ENT:OnRemove(self)
print( "hi" )
hook.Call("OnNPCKilled",GAMEMODE,self,attacker)
print( "hi" )

end

I have tried this to call something when the ENT is removed like npc_combinegunship nothing happened

Because you’re not defining ent anywhere, or are you?

Not really I think but thats so annoying npc_barnacle, npc_helicopter, npc_combinegunship, npc_sniper not calling OnNpcKilled .