NPC XP

Hello I am trying to allow the FREE DarkRP levelling script to allow gaining different amounts of XP Depending on what NPC is killed.
I know it has something to do with this function



function NPCDeath(npc, killer,weapon)
	if(LevelSystemConfiguration.NPCXP) then
		if(npc != killer) then // Not a suicide? Somehow.
			if(killer:IsPlayer()) then
				killer:addXP(LevelSystemConfiguration.NPCXPAmount, true)
				DarkRP.notify(killer, 0,4,'You got '..LevelSystemConfiguration.NPCXPAmount..'XP for killing an NPC.')				
			end
		end
	end
end

hook.Add( "OnNPCKilled", "enpcded123", NPCDeath )

This code gives 10XP per kill and calls to config.lua where it has the general settings. I am just looking to add a separate one but with different XP
I have tried numerous things, and there isn’t much documentation on the subject.
Any help is appreciated!
Thanks!

Hmm I suggest doing this (writing from phone so might make an error):

In the config add:



NPCXPAmountsPerClass = {
 ["insertnpchere"] = 50,
 ["Insertsecondnpc"] = 20
}


The insertnpchere would be the class of the NPC so it might be “human_npc”. Make sure you leave the quotes in too, don’t remove the quotes, the number it equals would be the amount of XP you get for the kill.

Then I would change that code you posted to this.


function NPCDeath(npc, killer,weapon)
	if(LevelSystemConfiguration.NPCXP) then
		if(npc != killer) then // Not a suicide? Somehow.
			if(killer:IsPlayer()) then
                            if LevelSystemConfiguration.NPCXPAmountsPerClass[npc:GetClass()] then
killer:addXP(LevelSystemConfiguration.NPCXPAmountsPerClass[npc:GetClass()], true)
				DarkRP.notify(killer, 0,4,'You got '..LevelSystemConfiguration.NPCXPAmountsPerClass[npc:GetClass()]..'XP for killing an NPC.')				                             else				
killer:addXP(LevelSystemConfiguration.NPCXPAmount, true)
				DarkRP.notify(killer, 0,4,'You got '..LevelSystemConfiguration.NPCXPAmount..'XP for killing an NPC.')				
                            end
			end
		end
	end
end

hook.Add( "OnNPCKilled", "enpcded123", NPCDeath )


Sorry if I made mistakes or bad indentation.
I wrote all of this in the quick reply box on my phone

You also would probably be better of localizing the value of LevelSystemConfiguration.NPCXPAmountsPerClass[npc:GetClass()]

Okay thanks for the response!
I tried this out in the config.lua


LevelSystemConfiguration.NPCXP = true // Give XP when an NPC is killed?
LevelSystemConfiguration.NPCXPAmount = 10 // Amount of XP to give when an NPC is killed

NPCXPAmountsPerClass = {
 ["npc_alyx"] = 50,
 ["Insertsecondnpc"] = 20
}

then in addways.lua I changed the original code with the one your provided.


function NPCDeath(npc, killer,weapon)
	if(LevelSystemConfiguration.NPCXP) then
		if(npc != killer) then // Not a suicide? Somehow.
			if(killer:IsPlayer()) then
                            if LevelSystemConfiguration.NPCXPAmountsPerClass[npc:GetClass()] then
killer:addXP(LevelSystemConfiguration.NPCXPAmountsPerClass[npc:GetClass()], true)
				DarkRP.notify(killer, 0,4,'You got '..LevelSystemConfiguration.NPCXPAmountsPerClass[npc:GetClass()]..'XP for killing an NPC.')				                             else				
killer:addXP(LevelSystemConfiguration.NPCXPAmount, true)
				DarkRP.notify(killer, 0,4,'You got '..LevelSystemConfiguration.NPCXPAmount..'XP for killing an NPC.')				
                            end
			end
		end
	end
end

hook.Add( "OnNPCKilled", "enpcded123", NPCDeath )

The outcome was I didn’t get any XP for killing any NPC’s or any errors, so I know the code works, just something wrong.
I’m wondering if “LevelSystemConfiguration.NPCXPAmount = 10 // Amount of XP to give when an NPC is killed” has something to do with it.

In the config change


NPCXPAmountsPerClass = {
 ["npc_alyx"] = 50,
 ["Insertsecondnpc"] = 20
}


To


LevelSystemConfiguration.NPCXPAmountsPerClass = {
 ["npc_alyx"] = 50,
 ["Insertsecondnpc"] = 20
}


Unfortunately it had the same outcome as last time. I will provide more details for you.
I am in these files, Level System

Here is what I have now

in config.lua it has these lines


LevelSystemConfiguration.NPCXP = true // Give XP when an NPC is killed?
LevelSystemConfiguration.NPCXPAmount = 10 // Amount of XP to give when an NPC is killed

LevelSystemConfiguration.NPCXPAmountsPerClass = {
 ["npc_alyx"] = 50,
 ["Insertsecondnpc"] = 20
}

Then in addways.lua I exchanged


function NPCDeath(npc, killer,weapon)
if(LevelSystemConfiguration.NPCXP) then
if(npc != killer) then // Not a suicide? Somehow.
if(killer:IsPlayer()) then
local XP = killer:addXP(LevelSystemConfiguration.NPCXPAmount, true)
if(XP) then
DarkRP.notify(killer, 0,4,'You got '..XP..'XP for killing an NPC.')
end
end
end
end
end
hook.Add( "OnNPCKilled", "manolis:MVLevels:OnNPCKilledBC", NPCDeath )

To what you provided here


function NPCDeath(npc, killer,weapon)
	if(LevelSystemConfiguration.NPCXP) then
		if(npc != killer) then // Not a suicide? Somehow.
			if(killer:IsPlayer()) then
                            if LevelSystemConfiguration.NPCXPAmountsPerClass[npc:GetClass()] then
killer:addXP(LevelSystemConfiguration.NPCXPAmountsPerClass[npc:GetClass()], true)
				DarkRP.notify(killer, 0,4,'You got '..LevelSystemConfiguration.NPCXPAmountsPerClass[npc:GetClass()]..'XP for killing an NPC.')				                             else				
killer:addXP(LevelSystemConfiguration.NPCXPAmount, true)
				DarkRP.notify(killer, 0,4,'You got '..LevelSystemConfiguration.NPCXPAmount..'XP for killing an NPC.')				
                            end
			end
		end
	end
end

hook.Add( "OnNPCKilled", "enpcded123", NPCDeath )


That was to give a check of what I have done.
I also tried this code on a paid version of a leveling script and it did the exact same thing.
Thanks for your time!

Are you sure the NPC class is npc_alex?

Put print(npc:GetClass())
At the start of the npcdeath function, read what it prints

Same outcome, I’m likely doing it wrong.