• NPC XP
    6 replies, posted
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 [CODE] 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 )[/CODE] 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: [CODE] NPCXPAmountsPerClass = { ["insertnpchere"] = 50, ["Insertsecondnpc"] = 20 } [/CODE] 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. [CODE]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 ) [/CODE] 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 [CODE]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 }[/CODE] then in addways.lua I changed the original code with the one your provided. [CODE]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 )[/CODE] 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 [CODE]NPCXPAmountsPerClass = { ["npc_alyx"] = 50, ["Insertsecondnpc"] = 20 } [/CODE] To [CODE]LevelSystemConfiguration.NPCXPAmountsPerClass = { ["npc_alyx"] = 50, ["Insertsecondnpc"] = 20 } [/CODE]
Unfortunately it had the same outcome as last time. I will provide more details for you. I am in these files, [URL="https://github.com/vrondakis/DarkRP-Leveling-System/tree/master/addons/darkrpmodification/lua/darkrp_modules/levels"]Level System[/URL] Here is what I have now in config.lua it has these lines [CODE]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 }[/CODE] Then in addways.lua I exchanged [CODE]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 )[/CODE] To what you provided here [CODE]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 ) [/CODE] 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.
Sorry, you need to Log In to post a reply to this thread.