How Do You Track Players NPC Kills

I’m making a game mode in fretta that is team based with classes and i need to know how to track a players kills when it comes to npcs.

Make it add to something like NwFloat or NwInt or something, Doesn’t it just add to frags?

Something like this?
[lua]
function GM:OnNPCKilled( Npc, pl )
if( pl:IsPlayer() ) then
pl:SetNetworkedInt( “NPCKills”, pl:GetNetworkedInt( “NPCKills” ) + 1 )
end
end
[/lua]

would that go in shared?

Serverside.

how could i really sinmply display that to the player so that player 1 sees how many kills he has and player 2 sees how many they have in the top right of there screen?

Use this code serverside(this is the code Dr Magnusson posted.):
[lua]
function GM:OnNPCKilled( Npc, pl )
if( pl:IsPlayer() ) then
pl:SetNetworkedInt( “NPCKills”, pl:GetNetworkedInt( “NPCKills” ) + 1 )
end
end
[/lua]
Then get the variable clientside using this function:
[lua]
LocalPlayer():GetNetworkedInt(“NPCKills”)
[/lua]

then to get it on screen would i use a draw.simple() command with the string NPCKills?

Yep, just use draw.SimpleText :slight_smile:

ok so this is my client code


include( 'shared.lua' )


function GM:PositionScoreboard( ScoreBoard )

	ScoreBoard:SetSize( 700, ScrH() - 100 )
	ScoreBoard:SetPos( (ScrW() - ScoreBoard:GetWide()) / 2, 50 )

end
LocalPlayer():GetNetworkedInt("NPCKills")  
function GM:HUDPaint()
	draw.SimpleText("NPCKills", "ScoreboardText", ScrW() / 2 - 70, ScrH() - 63, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end

but it isn’t showing up. sorry about all the questions but i’m new to lua.

That’s because you didn’t pass the variable to the function.
[lua]
include( ‘shared.lua’ )

function GM:PositionScoreboard( ScoreBoard )

ScoreBoard:SetSize( 700, ScrH() - 100 )
ScoreBoard:SetPos( (ScrW() - ScoreBoard:GetWide()) / 2, 50 )

end
function GM:HUDPaint()
draw.SimpleText("NPCKills: " … tostring(LocalPlayer():GetNetworkedInt(“NPCKills”)), “ScoreboardText”, ScrW() / 2 - 70, ScrH() - 63, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end
[/lua]

ah ok thank you its working =) My gamemode is gonna be even better now=)

Glad i could help :slight_smile:

ok now in a fretta class how can i make it while they are alive it checks the kill count and if it is equal to 10 or something it gives them a new gun?

In the OnNpcKilled hook, check how many he has killed to date, if it equals 10 or something give a new gun.

what code would i use to check it?


function GM:OnNPCKilled( Npc, pl )  
   if( pl:IsPlayer() ) then  //Checks to see if they are actually a player.
      pl:SetNetworkedInt( "NPCKills", pl:GetNetworkedInt( "NPCKills" ) + 1 )  //Increase the user's NPC Kills by 1.
      if( pl:GetNetworkedInt( "NPCKills" ) == 10 )then //After they kill a NPC, check to see if their kills are equal to 10.
           pl:Give("weapon_shotgun")//If they are equal to 10, Then give the user a weapon
      end
   end  
end

k one last thing how would i also check the players class so that they don’t get a gun that there class shouldn’t have?

You do an if check?

ya but im having problems with checking the class the wiki isn’t any help and i don’t know where to put code = (