Kill Counter

Hi, i am completely a n00b when it comes to lua scripting, but what im trying to do is simple(i think)… What i am trying to do is create a kill counter that will go up 1 every time a player kills an NPC. But here’s the hard part, if it is possible, I would like each player to have their own kill counter. It would also be nice to have a separate script that would do the same thing, only for players instead of NPCs.

Thanks in advance

[editline]25th March 2011[/editline]

And why is the default profile picture justin bieber!!!

You can use the **[Gamemode.OnNPCKilled

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.OnNPCKilled)** hook to register NPC kills. If you want to do it per-player then you can save the value inside the killer entity.

[lua]function NPCKillCounter( npc, killer, weapon )
if not killer:IsPlayer() then return end

if killer.KillCount then -- Check if the KillCount variable exists
	killer.KillCount = killer.KillCount + 1 -- If the variable exists then increase its value by 1
else
	killer.KillCount = 1 -- If the variable doesn't exist then set it to 1
end

end

hook.Add( “OnNPCKilled”, “NPCKillCounter”, NPCKillCounter ) – Register the hook[/lua]

Alternatively you could use killer.KillCount = (killer.KillCount or 0) + 1 instead of if statement.

Dont call me a noob, i am fully aware that i am, but where would i put thet lua file

Also there is a tutorial on the wiki: http://wiki.garrysmod.com/?title=Kill_Counter :cool:

Well, I guess in lua/autorun/server, but it’s not a complete script. You won’t see anything visually because all it does is store the kill count in a variable. It was just to point you in the right direction.

Will the one on the wiki pe individual to every player, or if one player kills something, will all the players see it?

[editline]25th March 2011[/editline]

correction, be

If it’s localized then only for the player whos killing the NPC’s. If you want a variable to show up you can use the GM:HUDPaint function, just go on the wiki and search keywords in the function search.

I didn’t know you could save local values on the player ent