SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 19/10/2018, 07:47 PM   #1
TwentyFour
Little Clucker
 
Join Date: Aug 2017
Location: Canada
Posts: 10
Reputation: 0
Default Sorting Top killers

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 Code:
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.
TwentyFour is offline   Reply With Quote
Old 19/10/2018, 09:01 PM   #2
g1venchy
Little Clucker
 
g1venchy's Avatar
 
Join Date: Oct 2018
Posts: 25
Reputation: 0
Default Re: Sorting Top killers

PHP Code:
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]); 


Last edited by g1venchy; 19/10/2018 at 11:57 PM.
g1venchy is online now   Reply With Quote
Old 19/10/2018, 10:45 PM   #3
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,208
Reputation: 3178
Default Re: Sorting Top killers

It looks like you're trying to write your own sorting algorithm. 1) These have been very well studied since at least the '60s, 2) yours is horribly broken anyway.

Get md-sort by Slice.
Y_Less is online now   Reply With Quote
Old 19/10/2018, 11:54 PM   #4
g1venchy
Little Clucker
 
g1venchy's Avatar
 
Join Date: Oct 2018
Posts: 25
Reputation: 0
Default Re: Sorting Top killers

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
g1venchy is online now   Reply With Quote
Old 20/10/2018, 02:32 AM   #5
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,208
Reputation: 3178
Default Re: Sorting Top killers

Yes, everyone has the right to learn, and that includes the thread starter - posting your own attempts at learning as an answer is not only not helpful to them, but actually against the rules. If you are going to answer questions, make sure the code works. If you want to learn, start your own thread. Anyway, your right to learn as well is precisely why I told you there were problems with your code, and that there is a lot of research on good ways to do this. From your old code, it wasn't even obvious that you were trying to implement bubble sort, and now that it is, I can tell you there are much much better ones to do - like quicksort or mergesort.

As for attitudes, you are the one that needs to be careful. Everything I said was a statement of fact. You clearly took them on board (since you have edited your code on the back of it), then started insulting the people trying to help you, while reading in to things that were not there.
Y_Less is online now   Reply With Quote
Old 20/10/2018, 06:26 AM   #6
agit
Little Clucker
 
Join Date: Sep 2018
Posts: 2
Reputation: 0
Default Re: Sorting Top killers

Use bubbleSort method or you could googling to learn algorithm sorting
agit is online now   Reply With Quote
Old 22/10/2018, 08:09 AM   #7
TwentyFour
Little Clucker
 
Join Date: Aug 2017
Location: Canada
Posts: 10
Reputation: 0
Default Re: Sorting Top killers

Guys don't fight,

OnTopic: I have used both mixture of Y_less's and G1venchy and it produces the result as i want
PHP Code:
        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
TwentyFour is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[HELP]Top 5 Killers [R]ambo Scripting Help 1 16/03/2013 10:26 PM
TOP 10 killers Baboon Help Archive 1 06/04/2011 09:29 PM
Top 10 killers Baboon Help Archive 2 04/04/2011 03:26 PM
top 5 killers!!! billiout Help Archive 6 24/06/2010 09:02 PM
[HELP] Top killers! leapfish Help Archive 2 19/02/2010 05:02 PM


All times are GMT. The time now is 02:10 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.