Sorting Top killers
#1

I am making a Gang system where after the Gang Turf Attack ends, the Defender's and Attacker's both of them kills are shown in a dialog. but they are unsorted.
p1 11
p2 15
p3 9
p4 20

However i want it to look something like this

p4 20
p2 15
p1 11
p3 9

So here is what i made
PHP код:
new count 0;
foreach(new 
Player)
{
    if(
Player[i][pGroup] == gattacker || Player[i][pGroup] == gattacked)
        
count++;
}
new 
killerids[count];
for(new 
0countx++)
{
    foreach(new 
Player)
    {
        if(
Player[i][pGroup] == gattacker || Player[i][pGroup] == gattacked)
        {
            new 
kill_ = -1;
            if(
Player[i][Kills] > kill_)
            {
                for(new 
0county++)
                {
                    if(
killerids[y] != i)
                    {
                        
killerids[x] = i;
                        
format(strsizeof (str), "%s\n%d\t%s\t%d"strPlayer[i][pID], Player[i][Name], Player[i][Kills]);
                    }
                }
            }
        }
    }

Now question is, isnt it laggy if it has to loop through above than 200 players? Any Remedy would be appreciated.
Please correct me if i am wrong in this script.
Reply
#2

PHP код:
new arrPlayers[MAX_PLAYERS],
    
cnt,
    
j,
    
k,
    
bool:startAgain=false,
    
s[300];
foreach(new 
i:Player){
    if(
Player[i][pGroup] == gattacker || Player[i][pGroup] == gattacked)arrPlayers[cnt++]=i;
}
for(new 
icnti++){
    
j=arrPlayers[i];
    
k=arrPlayers[i+1];
    if(
Player[j][Kills] > Player[k][Kills])arrPlayers[i+1]=j,arrPlayers[i]=k,startAgain=true;
    if(
i==cnt-&& startAgain)i=0,startAgain=false;
}
for(new 
icnti++){
    
j=arrPlayers[i];
    
format(ssizeof(s), "%s\n%d\t%s\t%d"sPlayer[j][pID], Player[j][Name], Player[j][Kills]); 

Reply
#3

its just simple example of bubble sort, you dont have to be so cocky in every post.
just cause you have written pawn code from year 2006 and haven't done anything else doesn't give you right to be such a douchbag.
others have also right to post code and learn throw that.
made little changes in my code
Reply
#4

Use bubbleSort method or you could googling to learn algorithm sorting
Reply
#5

Guys don't fight,

OnTopic: I have used both mixture of ******'s and G1venchy and it produces the result as i want
PHP код:
        enum infofof
        
{
            
kills,
            
kid
        
};
        new 
GetKillerID[MAX_PLAYERS][infofof];
        new    
count 0;
        foreach (new 
Player)
        {
            if(
Group[gattacker][gInTwar] == zoneid || Group[gattacked][gInTwar] == zoneid)
            {
                if(
Player[i][pInTwar] == zoneid)
                {
                    if(
Player[i][pGroup] == iswinner)
                        
SetPlayerScore(iGetPlayerScore(i) + 8);
                    
GetKillerID[count][kills] = Player[i][pTwarScores];
                    
count++;
                }
            }
        }
        
SortDeepArray(GetKillerIDkills);
        new 
rstr[500];
        
rstr "ID\tName\tKills";
        for(new 
0counti++)
        {
            foreach(new 
Player)
            {
                if(
Player[j][pTwarScores] == GetKillerID[i][kills])
                {
                    if(
Player[j][pInTwar] != zoneid)
                        continue;
                        
                    
GetKillerID[GetKillerID[i][kills]][kid] = j;
                }
            }
            new 
pid GetKillerID[GetKillerID[i][kills]][kid];
            new 
groupid Player[pid][pGroup];
            new 
colorid Group[groupid][gcolor];
            
format(rstrsizeof (rstr), "%s\n%d\t{%06x}%s\t%d"rstrpidPlayerColors[colorid] >>> 8Player[pid][Name], GetKillerID[i][kills]);
        }
        for(new 
0counti++)
        {
            new 
pid GetKillerID[GetKillerID[i][kills]][kid];
            if(
IsPlayerConnected(pid))
            {
                
ShowPlayerDialog(pidDIALOG_BLANKDIALOG_STYLE_TABLIST_HEADERS"Turf War Stats"rstr,"close","");
                
GetKillerID[i][kills] = 0;
            }
        } 
if there is any fastest method. i would love to hear it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)