• Good victim=money, bad one= lose money problem.
    5 replies, posted
the code: [CODE] hook.Add( "OnNPCKilled", "Points", function( ply, victim ) if ply:Team() == 1 and victim == npc_monk then victim:GivePoints( 15 ) else victim:GivePoints( 0 ) end end ) [/CODE] this is the error :( [CODE] Hook 'Points' Failed: [gamemodes\getthem\gamemode\init.lua:223] attempt to call method 'Team' (a nil value) n [/CODE]
You've got the arguments to the hook in the wrong order - it's victim, killer, weapon. [URL]http://wiki.garrysmod.com/?title=Gamemode.OnNPCKilled[/URL] You also need to put npc_monk in quote marks, and you need to get the victim's entity class using victim:GetClass().
[CODE] hook.Add( "OnNPCKilled", "Points", function( victim, killer, weapon ) if killer:Team() == 1 and victim:GetClass() == "npc_monk" then killer:GivePoints( 15 ) else killer:GivePoints( 0 ) end end ) [/code] no error. thankyou MegaJohnny!
which line is that? [editline]19th April 2011[/editline] And also, you should put lua in lua tags.
You might also want to add stuff to the if statement to make sure the killer is a player - otherwise you might get the Team nil value error again when an NPC is killed by something other than a player. The else bit isn't needed unless the 0 is a temporary value, either.
now the code don't gives an error like i said, but i didn't look at the points, ... yes, if you kill one of the other team you don't get you'r points like in the code... :(
Sorry, you need to Log In to post a reply to this thread.