How to sorting?

Started by rww, Jan 24, 2016, 02:08 PM

Previous topic - Next topic

rww

So I need something, that in easy way will sort mine for spree list, from the highest to the lowest.

From:

rww [13]
Piterus [15]
Kunio [14]

To:

Piterus [15]
Kunio [14]
rww [13]

I saw this topic http://forum.vc-mp.org/?topic=1391.msg9534#msg9534 but idk how to write in my script...

else if (c == "spree")
{
ClientMessage("* Spree:",p,0,255,128,255);
local b = 0;
foreach (pidx in Players)
{
local pidx = FindPlayer(pidx);
if (pidx && Spree[pidx.ID] > 4)
{
b = b + 1;
MessagePlayerLang("* "+GetLevelColor(Level[pidx.ID])+"["+pidx.ID+"]"+GetTeamChatColour(pidx.Team)+" "+pidx.Name+"[#00ff80] spree: [#ffff00][ "+Spree[pidx.ID]+" ].","* "+GetLevelColor(Level[pidx.ID])+"["+pidx.ID+"]"+GetTeamChatColour(pidx.Team)+" "+pidx.Name+"[#00ff80] spree: [#ffff00][ "+Spree[pidx.ID]+" ].",p,0,255,128);
}
}
if (!b) MessagePlayerLang("* Aktualnie nikt nie ma spree!","* Currently, no one have a spree!",p,0,255,128);
}
Join to Irrelevant Club Discord: https://discord.gg/MsPPZ5uV4X

DizzasTeR

Keep a global dynamic array ( SpreePlayers <- array( GetMaxPlayers() ) and whenever someone makes a spree, add him to the array ( SpreePlayers[ killer.ID ] = killer.Spree ). So ofcourse, if someone loses spree, remove him from the array.

Now when someone does /spree you sort and reverse the SpreePlayers and then run a foreach loop like so:
local msg;
foreach( iPlayer, iSpree in SpreePlayers )
{
    if( !iPlayer || !iSpree ) continue;
    if( msg ) msg = msg + ", " + FindPlayer( iPlayer ).Name + " [" + iSpree + "]";
    else msg = "[Spree]: " + FindPlayer( iPlayer ).Name + " [" + iSpree + "]";
}
Message( msg );

I don't have any other approach though.

rww

so it almost works, when first player connect with bigger spree and then second with lower - this is OK, when vice versa, then player with lower spree takes spree player with bigger and player with bigger gets this lower spree...
Join to Irrelevant Club Discord: https://discord.gg/MsPPZ5uV4X