I am making a gamemode currently to improve my lua coding and it would be nice if someone could teach/help me make a system so that at the end of the round, the player with the most kills is displayed as the winner.
[QUOTE=landbird13;45938084]I am making a gamemode currently to improve my lua coding and it would be nice if someone could teach/help me make a system so that at the end of the round, the player with the most kills is displayed as the winner.[/QUOTE]
Bump
Use PlayerDeath to credit the kills to the attacker, then add all of the kills up on round end and display them.
[QUOTE=NiandraLades;45941821]Use PlayerDeath to credit the kills to the attacker, then add all of the kills up on round end and display them.[/QUOTE]
Would you mind telling me a hook I could use to add up the kills? Sorry if it's a stupid question.
Well, if you are writing a gamemode with a round system, just call it in the sane function that ends the round.
[QUOTE=meharryp;45944824]Well, if you are writing a gamemode with a round system, just call it in the sane function that ends the round.[/QUOTE]
What function do I call?
Where you handle round ending, make it call a hook, preferably named RoundEnded or something. Create a hook with RoundEnded or whatever you called it and do your code there
[QUOTE=AnonTakesOver;45945226]Where you handle round ending, make it call a hook, preferably named RoundEnded or something. Create a hook with RoundEnded or whatever you called it and do your code there[/QUOTE]
I have that set up already, I just don't know how to display who got the most kills at the end of a round.
[CODE]include( 'shared.lua' ) --Tell the client to load shared.lua
round = {}
-- Variables
round.Break = 30 -- 30 second breaks
round.Time = 300 -- 5 minute rounds
-- Read Variables
round.TimeLeft = -1
round.Breaking = false
function round.Broadcast(Text)
for k, v in pairs(player.GetAll()) do
v:ConCommand("play buttons/button17.wav")
v:ChatPrint(Text)
end
end
function round.Begin()
-- Your code
-- (Anything that may need to happen when the round begins)
round.Broadcast("Round starting! Round ends in " .. round.Time .. " seconds!")
round.TimeLeft = round.Time
RunConsoleCommand( "team_1" )
end
function round.End()
-- Your code
-- (Anything that may need to happen when the round ends)
for k,v in pairs( team.GetPlayers( TEAM_HUMAN ) ) do
v:SetFrags( 0 ) // Reset their frags for next round
end
round.Broadcast("Round over! Next round in " .. round.Break .. " seconds!")
round.TimeLeft = round.Break
game.CleanUpMap()
RunConsoleCommand( "team_0" )
end
function round.Handle()
if (round.TimeLeft == -1) then -- Start the first round
round.Begin()
return
end
round.TimeLeft = round.TimeLeft - 1
if (round.TimeLeft == 0) then
if (round.Breaking) then
round.Begin()
round.Breaking = false
else
round.End()
round.Breaking = true
end
end
end
timer.Create("round.Handle", 1, 0, round.Handle)[/CODE]
I'd recommend keeping track of it in PlayerDeath.. by it I mean everything...
round.End you'd want to just grab and display the top; the round.Begin you'd want to reset the array. The array should consist of kill counts, and top count. That way you only need to compare the max-kills to the current killer. No need to run through a loop or so at the end.
Here's something similar I made ( gun race logic )
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_gamemode_logic/gun_race/sv_gun_race.lua.html[/url]
It doesn't do everything you want; I know I wrote one though so I'll look some more through my code base and see if I can find it because I remember writing essentially the logic you need...
But, anyways... Take a look at how __data is manipulated, I stored kills separately so additional logic could be added. You just need 2 globals, or one table... Store the number of max kills, and store the player object, with additional information in case of disconnect.
On PlayerDeath, add 1 to the kill count for the killer if the Killer and Victim are both valid, both players, and not the same. Compare that number to max kill count... IF the number is > than max kills, update the number AND player object / additional information.
On Round-End display that information / network it to the client. On round begin, reset the information.
[QUOTE=Acecool;45946641]I'd recommend keeping track of it in PlayerDeath.. by it I mean everything...
round.End you'd want to just grab and display the top; the round.Begin you'd want to reset the array. The array should consist of kill counts, and top count. That way you only need to compare the max-kills to the current killer. No need to run through a loop or so at the end.
Here's something similar I made ( gun race logic )
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_gamemode_logic/gun_race/sv_gun_race.lua.html[/url]
It doesn't do everything you want; I know I wrote one though so I'll look some more through my code base and see if I can find it because I remember writing essentially the logic you need...
But, anyways... Take a look at how __data is manipulated, I stored kills separately so additional logic could be added. You just need 2 globals, or one table... Store the number of max kills, and store the player object, with additional information in case of disconnect.
On PlayerDeath, add 1 to the kill count for the killer if the Killer and Victim are both valid, both players, and not the same. Compare that number to max kill count... IF the number is > than max kills, update the number AND player object / additional information.
On Round-End display that information / network it to the client. On round begin, reset the information.[/QUOTE]
Thank you for the help, but I'm not good enough with lua to understand that yet. I get most of my information from the gmod wiki.
[QUOTE=landbird13;45956408]Thank you for the help, but I'm not good enough with lua to understand that yet. I get most of my information from the gmod wiki.[/QUOTE]
Bump
[QUOTE=landbird13;45964015]Bump[/QUOTE]
Can someone please help?
On round start, set everyone's kills to 0. Then on PlayerDeath, do attacker.Kills = attacker.Kills + 1
On round end, go through all players, check which one has the most via Table.sort and then use ChatPrint/Nick() however way you want to display it
[QUOTE=NiandraLades;45973232]On round start, set everyone's kills to 0. Then on PlayerDeath, do attacker.Kills = attacker.Kills + 1
On round end, go through all players, check which one has the most via Table.sort and then use ChatPrint/Nick() however way you want to display it[/QUOTE]
Remember to do checks, such as in playerdeath make sure they aren't getting kills for suicide.
[QUOTE=AnonTakesOver;45973331]Remember to do checks, such as in playerdeath make sure they aren't getting kills for suicide.[/QUOTE]
Thank you for the tip.
Sorry, you need to Log In to post a reply to this thread.