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 
i : Player)
{
    if(
Player[i][pGroup] == gattacker || Player[i][pGroup] == gattacked)
        
count++;
}
new 
killerids[count];
for(new 
x = 0; x < count; x++)
{
    foreach(new 
i : Player)
    {
        if(
Player[i][pGroup] == gattacker || Player[i][pGroup] == gattacked)
        {
            new 
kill_ = -1;
            if(
Player[i][Kills] > kill_)
            {
                for(new 
y = 0; y < count; y++)
                {
                    if(
killerids[y] != i)
                    {
                        
killerids[x] = i;
                        
format(str, sizeof (str), "%s\n%d\t%s\t%d", str, Player[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 
i; i < cnt; i++){
    
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-1 && startAgain)i=0,startAgain=false;
}
for(new 
i; i < cnt; i++){
    
j=arrPlayers[i];
    
format(s, sizeof(s), "%s\n%d\t%s\t%d", s, Player[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 
i : Player)
        {
            if(
Group[gattacker][gInTwar] == zoneid || Group[gattacked][gInTwar] == zoneid)
            {
                if(
Player[i][pInTwar] == zoneid)
                {
                    if(
Player[i][pGroup] == iswinner)
                        
SetPlayerScore(i, GetPlayerScore(i) + 8);
                    
GetKillerID[count][kills] = Player[i][pTwarScores];
                    
count++;
                }
            }
        }
        
SortDeepArray(GetKillerID, kills);
        new 
rstr[500];
        
rstr = "ID\tName\tKills";
        for(new 
i = 0; i < count; i++)
        {
            foreach(new 
j : 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(rstr, sizeof (rstr), "%s\n%d\t{%06x}%s\t%d", rstr, pid, PlayerColors[colorid] >>> 8, Player[pid][Name], GetKillerID[i][kills]);
        }
        for(new 
i = 0; i < count; i++)
        {
            new 
pid = GetKillerID[GetKillerID[i][kills]][kid];
            if(
IsPlayerConnected(pid))
            {
                
ShowPlayerDialog(pid, DIALOG_BLANK, DIALOG_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)