|
|
|
New table, loop old one for highest repeatedly and remove the highest form the old one each time, then the old one will be empty and the new one will be in order. |
|
|
|
|
|
Heres an example
Table={{"Jim",10},{"John",20}}
SortedTable={}
Highest=0
for u = 1, #Table do
for i = 1, #Table do
if Table[i][2]>Highest then
Highest=Table[i][2]
end
end
a=GetEntryFromHighest(Table,Highest,2)
table.insert(SortedTable,a)
table.remove(Table,a)
Highest=nil
end
function GetEntryFromHighest(table,entry, key)
for _,v in pairs(table) do
if v[key]==entry then
return v
end
Probably wouldn't work, just something that I typed out on the forum for an example. |
|
oysi93Join Date: 2008-04-27 Post Count: 12469 |
I won't come up with a fancy table formula right now,
because then I'd just explain so I'm making a script. =P
Wait, I won't do that anyway because as I started making the script
I immediately realized you set it up quite stupidly... =/
Make the Killstreaks be recorded into each player as IntValues,
then this will work:
StreakName = "Killstreak" -- What you name the killstreak intvalue thingy in each player
function getTopKillstreaks(Top)
local Players, TopP = Game.Players:GetPlayers(), {}
for _, Player in next, Players do
local Higher = 0
for _, oPlayer in next, Players do
Higher = Higher + (oPlayer[StreakName].Value > Player[StreakName].Value and 1 or 0)
end
if Higher <= Top then
TopP[#TopP + 1] = Player
end
end
return TopP
end
If like, 5 players have the same killstreak, then all those five players will be returned.
At least I think that'll happen. =P So you'll just have to exlcude randomly? >=D |
|
|
*Has been owned by oysi93* |
|
|
|
>__<
ThirdTable={}
for f = 1,5 do
table.insert(ThirdTable,SortedTable[f])
end |
|
oysi93Join Date: 2008-04-27 Post Count: 12469 |
>_<
*Feels stupid*
Imagine _6_ players had the same killstreak, all would be returned.
Btw, only reason I said five was because I gave you the easy ability
to change how many of the highest you wanted...
Top2 = getTopKillstreaks(2)
Top3 = getTopKillstreaks(3)
Top4 = getTopKillstreaks(4)
I thought it would be a nice addition. =) |
|
|
Although using table.sort you could just find out who had what number, that way it'd only be a couple of lines. |
|
oysi93Join Date: 2008-04-27 Post Count: 12469 |
Then you won't be able to find out who got those streaks. =P |
|
|
|
@Oysi
Just see who has what number. If 2 had the same they'd both end up with the same number after the calculations. |
|
oysi93Join Date: 2008-04-27 Post Count: 12469 |
Sorting out a table with two values:
4
4
Player1: Oysi93
Player2: Trappingnoobs
Getting the players from those scores...
Oysi93
Oysi93
Heh. =P |
|
|
function AreTheyInTable(player,table)
3 or 4 lines
end |
|
|