Salinas23
|
  |
| Joined: 28 Dec 2008 |
| Total Posts: 37141 |
|
|
| 13 Dec 2016 05:34 PM |
Let's say I want to check who's the player (i.e. at the end of the game) with the highest number of Knockouts e.e
I have a spider on my back. |
|
|
| Report Abuse |
|
|
|
| 13 Dec 2016 05:36 PM |
math.max could only give you the highest number but it wouldn't tell you who has it
instead i would just use table.sort on a table and take the highest value from there |
|
|
| Report Abuse |
|
|
|
| 13 Dec 2016 05:37 PM |
function getMax(list)
local max = list[1]
for i,v in pairs(list) do max = math.max(max,list[i]) end
return max
end |
|
|
| Report Abuse |
|
|
Salinas23
|
  |
| Joined: 28 Dec 2008 |
| Total Posts: 37141 |
|
|
| 13 Dec 2016 05:42 PM |
local t = { ["Salinas23"] = 3, ["ur mom"] = 8, ["Telamon"] = 23, ["ROBLOX"] = 9, ["my mom"] = 11}
table.sort(t)
for key, value in ipairs (t) do print(key .. ": " .. value) end
This doesnt print anything... What am I doing wrong? obv no output
I have a spider on my back. |
|
|
| Report Abuse |
|
|
Salinas23
|
  |
| Joined: 28 Dec 2008 |
| Total Posts: 37141 |
|
|
| 13 Dec 2016 05:44 PM |
Oh true, I wrote it as an ipair. Thing is, using 'pairs' wont print it in order:/
I have a spider on my back. |
|
|
| Report Abuse |
|
|
|
| 13 Dec 2016 05:46 PM |
| yea for me it does but it prints it from smallest to largest and not the other way around |
|
|
| Report Abuse |
|
|
Salinas23
|
  |
| Joined: 28 Dec 2008 |
| Total Posts: 37141 |
|
|
| 13 Dec 2016 05:52 PM |
@Mister
had to read that 3 times to understand it nicely. Thanks.
I have a spider on my back. |
|
|
| Report Abuse |
|
|
|
| 13 Dec 2016 05:55 PM |
local Table = {["One"] = 1,["Two"] = 3,["Three"] = 3}
table.sort(Table, function(a,b) return a>b end)
print(table.concat(Table," "))
|
|
|
| Report Abuse |
|
|
|
| 13 Dec 2016 05:57 PM |
table.concat and table.sort work only with arrays im pretty sure not dictionarys
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 13 Dec 2016 05:58 PM |
dictionaries dont have a length so you cant sort it.
@OP just sort the array
local players = game.Players:GetPlayers()
table.sort(players,function(p1,p2) return p1.leaderstats.Kills.Value > p2.leaderstats.Kills.Value end)
for i,v in next, players do print(i,v.Name) end
|
|
|
| Report Abuse |
|
|
Salinas23
|
  |
| Joined: 28 Dec 2008 |
| Total Posts: 37141 |
|
|
| 13 Dec 2016 06:17 PM |
@time
that would work perfectly for a complete leaderboard but I need to know how many (and which) players had the highest number of 'Kills' and 'reward' them.
I have a spider on my back. |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 13 Dec 2016 06:22 PM |
i literally just showed you. i dont understand wat else you want??
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 13 Dec 2016 06:24 PM |
whatever way you keep track of the values for each player, just sort the table afterwards like i gave
|
|
|
| Report Abuse |
|
|
|
| 13 Dec 2016 06:24 PM |
@Salinas, sorting does just that, you can get as many players you want with the highest KOs or whatever other stat, and it says which.
local players = game:GetPlayers(); table.sort(players, function(value1, value2) return value1.leaderstats.KOs > value2.leaderstats.KOs; end);
Now, the array is sorted from player with the highest KOs to the player with the least KOs.
You have the player, the stat, and you can "reward" them.
|
|
|
| Report Abuse |
|
|