So I have a dictionary like seen below. Out of all of the players in that dictionary. How do I get the top 5 players with the most kills?
Code:class playerD { public string Name; public ulong UserID; public int Kills; public int scoreNumber; public playerD() { } }
Solved Get the max score in a data list?
Discussion in 'Rust Development' started by DylanSMR, May 23, 2016.
-
Take a look at how I did scoring in all the event plugins
[DOUBLEPOST=1463984323,1463975927][/DOUBLEPOST]Here is a few examples
Code:class playerD // Your class { public string Name; public ulong UserID; public int Kills; public int scoreNumber; } Dictionary<ulong, playerD> data = new Dictionary<ulong, playerD>(); // Your existing list private Dictionary<ulong, playerD> GetTop5Scores() // Function to return a new dictionary { var example1 = data.OrderByDescending(pair => pair.Value.Kills).Take(5).ToDictionary(pair => pair.Value.Name, pair => pair.Value.Kills); // Will create a new Fictionary<string, int> using the top 5 scores in order descending var example2 = data.OrderByDescending(pair => pair.Value.Kills).Take(5).ToDictionary(pair => pair.Key, pair => pair.Value); // Will create a new dictionary Dictionary<ulong, playerD> using the top 5 scores in order descending var example3 = data.OrderByDescending(pair => W).Take(X).ToDictionary(pair => Y, pair => Z); // W - is the variable used to sort by // X - is the amount of entries to collect // Y - is the key for the new sorted dictionary // Z - is the value for the new sorted dictionary return example2; }
-
Ah ok, thanks
-
So I have the following code. How would I get the top 5 to send to a player and have it spaced out line by line?
Code:case "top": if(args[1].Length >= 1) { SendReply(player, "<color=#91FFB5>Available Commands</color>"); SendReply(player, "<color=#91FFB5>-</color> /sgi getscore (player) or (self) => Shows either your stats or another players stats."); SendReply(player, "<color=#91FFB5>-</color> /sgi top => Shows the top 5 kills aswell as your kills."); return; } SendReply(player, GetTop5Scores()); break;
-
So this works, but instead of a score(kills) it outputs: Oxide.Plugins.ScoreGUI+test]
Code:foreach(var score in GetTop5Scores()) { SendReply(player, score + "\n"); }
Last edited by a moderator: May 24, 2016 -
Nevermind: Solved!