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?
[QUOTE=??????;18825462]would that go in shared?[/QUOTE]
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 [b]Dr Magnusson[/b] 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 :)
[url]http://wiki.garrysmod.com/?title=Draw.SimpleText[/url]
ok so this is my client code [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[/code]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 :-)
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?
[code]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[/code]
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 = (
Sorry, you need to Log In to post a reply to this thread.