Raised This Month: $51 Target: $400
 12% 

2D Array sorting


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FroL
Member
Join Date: Jul 2007
Old 11-20-2008 , 07:54   2D Array sorting
Reply With Quote #1

I have a 2D array "Kills[MAXPLAYERS+1][MAXPLAYERS+1]".

PHP Code:
new Kills[MAXPLAYERS+1][MAXPLAYERS+1];

public 
OnPluginStart()
{
    
HookEvent("player_death"EventPlayerDeath);
}

public 
EventPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
victimId GetEventInt(event"userid");
    new 
attackerId GetEventInt(event"attacker");

    new 
victim GetClientOfUserId(victimId);
    new 
attacker GetClientOfUserId(attackerId);

    
// Give the attacker credit for killing me
    
if ( ( attacker ) && ( attacker <= GetMaxClients() ) && ( victim != attacker ) )
    {
        
Kills[attacker][victim]++;
    }

I want to sort this array by kills, for example:
kills[1 attacker][all victims] = 5 (kills)
kills[2 attacker][all victims] = 3 (kills)
kills[3 attacker][all victims] = 1 (kills)
__________________

3SMedia #1 | classic gameplay | tick 100 (81.25.49.19:27015)
3SMedia #2 | pro gaming | tick 100 (81.25.49.19:27016)
3SMedia #3 | deathmatch | tick 100 (81.25.49.19:27017)
Sorry for my VERY bad english .
FroL is offline
SAMURAI16
BANNED
Join Date: Sep 2006
Old 11-20-2008 , 11:26   Re: 2D Array sorting
Reply With Quote #2

using SortCustom2D() ?
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
FroL
Member
Join Date: Jul 2007
Old 11-20-2008 , 15:59   Re: 2D Array sorting
Reply With Quote #3

Quote:
using SortCustom2D() ?
Yes, I tryed it. But I had errors... Give me an example as I may use this function, please.
__________________

3SMedia #1 | classic gameplay | tick 100 (81.25.49.19:27015)
3SMedia #2 | pro gaming | tick 100 (81.25.49.19:27016)
3SMedia #3 | deathmatch | tick 100 (81.25.49.19:27017)
Sorry for my VERY bad english .
FroL is offline
SAMURAI16
BANNED
Join Date: Sep 2006
Old 11-21-2008 , 06:49   Re: 2D Array sorting
Reply With Quote #4

this is an example to sort kills somehow
I hope you understand what I made:
Code:
new g_iPlayerKills[33]; public example() {     new count, i , maxclients;     new sort[33][2];         maxclients = GetMaxClients();         for(i = 1 ; i<= maxclients; i++)     {         sort[count][0] = i;         sort[count][1] = g_iPlayerKills[i];         count++;     }         SortCustom2D(sort,count,custom_func_compare);         new a,b;     b = clamp(count,0,5);         new String:name[32], client;     for(a = 0; a < b; a++)     {         client = sort[a][0];                 GetClientName(client,name,sizeof(name));                 PrintToChatAll("Name : %s | Kills : %d",name,sort[a][1]);     }    } public custom_func_compare(x[], y[], array[][], Handle:data) {     if(x[1] > y[1]) return -1;     else if(x[1] < y[1]) return 1;         return 0; } stock clamp(value,min,max) {     new iVal = value;         if(min > max)         return 0;         if(iVal < min)         iVal = min;         else if(iVal > max)         iVal = max;         return iVal; }
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
FroL
Member
Join Date: Jul 2007
Old 11-21-2008 , 07:08   Re: 2D Array sorting
Reply With Quote #5

I'm not c++ coder, but I will try understand it. Thank you for your time.
__________________

3SMedia #1 | classic gameplay | tick 100 (81.25.49.19:27015)
3SMedia #2 | pro gaming | tick 100 (81.25.49.19:27016)
3SMedia #3 | deathmatch | tick 100 (81.25.49.19:27017)
Sorry for my VERY bad english .
FroL is offline
Lebson506th
Veteran Member
Join Date: Jul 2008
Old 11-21-2008 , 08:02   Re: 2D Array sorting
Reply With Quote #6

That's not C++, that's SourcePawn. The language that SourceMod plugins are written in.


If you have questions about parts of the code, just ask and we'll answer them =)
__________________
My Plugins
Spray Tracer by Nican, maintained by me
Simple TK Manager
DoD:S Admin Weapons

Links
Resistance and Liberation (A HL2 Multiplayer Modification)
Lebson506th is offline
FroL
Member
Join Date: Jul 2007
Old 11-21-2008 , 18:42   Re: 2D Array sorting
Reply With Quote #7

Ok...
I'm will be glad to see any comments on the lines of this code...
__________________

3SMedia #1 | classic gameplay | tick 100 (81.25.49.19:27015)
3SMedia #2 | pro gaming | tick 100 (81.25.49.19:27016)
3SMedia #3 | deathmatch | tick 100 (81.25.49.19:27017)
Sorry for my VERY bad english .
FroL is offline
SAMURAI16
BANNED
Join Date: Sep 2006
Old 11-22-2008 , 01:27   Re: 2D Array sorting
Reply With Quote #8

i forgot to say that's an example to sort kills and it's display kills descending untill 5. It's like a top5 kills
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
FroL
Member
Join Date: Jul 2007
Old 11-22-2008 , 07:46   Re: 2D Array sorting
Reply With Quote #9

Yahooo! I have understood all of the code! Thank you, SAMURAI16!
__________________

3SMedia #1 | classic gameplay | tick 100 (81.25.49.19:27015)
3SMedia #2 | pro gaming | tick 100 (81.25.49.19:27016)
3SMedia #3 | deathmatch | tick 100 (81.25.49.19:27017)
Sorry for my VERY bad english .
FroL is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 18:54.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode