So I am trying to get the player(s) with the most amount of kills on my server, I have set it up with a data file and a dictionary (Quite similar to PVP Stats by Dana) and I am trying to sort everyones stats so I can get the top 5 players on my server with the most kills. However it's not working.
Currently when you run the command it shows this: "generalPEPSI id:76561198***** with 2 kills" When that is incorrect, because i have more kills then that player, this is proof found in the data file:
{
"PlayerID": 76561198*******,
"PlayerKills": 3,
"Deaths": 4
}
See there I have 3 kills, so why do I not display when you run /top? I also want it to display up to 5 players, however its only displaying 1.
[ChatCommand("top")]
private void topCommand(BasePlayer player, string Command, string[] args) //OrderByDescending(x => x.Value).Take(5)
{
Puts("Ran command!");
StringBuilder result = new StringBuilder();
Dictionary<BasePlayer, int> TopKills = new Dictionary<BasePlayer, int>();
foreach (KeyValuePair<ulong, PLRStats> stats in cachedPlayerStats)
{
var playerKills = stats.Value.PlayerKills;
if (playerKills > 0)
{
Puts("Kills over 0");
BasePlayer findPlayer = BasePlayer.FindByID(stats.Value.PlayerID);
if (!TopKills.ContainsKey(findPlayer))
{
TopKills.Add(findPlayer, playerKills);
Puts("Adding playing to top kills list");
}
else foreach (KeyValuePair<BasePlayer, int> topFivePlayers in TopKills.OrderByDescending(x => x.Value).Take(5))
{
Puts("Getting all the top players stuff as a test"); // OrderByDescending(x => x.Value).Take(5);
PLRStats.TryLoad(topFivePlayers.Key.userID);
result.Append($"Top Player Kills\n\n {topFivePlayers.Key.displayName} id:{topFivePlayers.Key.userID} with {TopKills[findPlayer]} kills");
SendMessage(player, result.ToString());
Puts("Sent message");
}
}
else Puts("Kills not over 0!"); return;
}
}