• Whats wrong with my code? :C
    2 replies, posted
I am trying to get this script to add XP to a players level everytime they kill a npc. [LUA]hook.Add("OnNPCKilled", "AddXP", function() ply:AddXP(ply,15) end)[/LUA] Does this look right? I am using this leveling system [url]http://steamcommunity.com/sharedfiles/filedetails/?id=222631611[/url] [editline]24th March 2014[/editline] [IMG]http://i.gyazo.com/51e911384d48a8853d0cfc3b22e3f77f.png[/IMG]
You're missing the arguments for the hook. [url]http://wiki.garrysmod.com/page/GM/OnNPCKilled[/url] You're gonna want to check if the killer is a player, and then add the xp.
You need the function to pass the arguments supplied by the hook, it should be function( npc, ply, attacker ) AddXP is not a player function, simply use AddXP( ply, 15 ) Make sure you are doing this on server-side. [editline]24th March 2014[/editline] Yes, also add a "if not ply:IsValid() then return end" on the first line of your function. It's always good practice.
Sorry, you need to Log In to post a reply to this thread.