AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get two biggest of a series of numbers (https://forums.alliedmods.net/showthread.php?t=143183)

Jelle 11-15-2010 17:20

Get two biggest of a series of numbers
 
I have an array:

Code:

new playersXP[SH_MAXSLOTS]
I have stored everyones XP inside that array. Is there a way to get the biggest two numbers out of it, and then divide the players who has that XP into separate teams?

Exolent[jNr] 11-15-2010 17:28

Re: Get two biggest of a series of numbers
 
Code:
enum _:SortData {     iOriginalIndex,     iValue }; new playersXP[ SH_MAXSLOTS ]; foo( ) {     new eSortData[ SH_MAXSLOTS ][ SortData ];     for( new i = 0; i < SH_MAXSLOTS; i++ )     {         eSortData[ i ][ iOriginalIndex ] = i;         eSortData[ i ][ iValue ] = playersXP[ i ];     }         SortCustom2D( eSortData, SH_MAXSLOTS, "SortData" );         // get top player     new iPlayer1 = eSortData[ 0 ][ iOriginalIndex ];     // get 2nd top player     new iPlayer2 = eSortData[ 1 ][ iOriginalIndex ];     // etc. } public SortData( iElem1[ ], iElem2[ ], iArray[ ], iData[ ], iDataSize ) {     if( iElem1[ iValue ] > iElemt2[ iValue ] ) return -1;     return 1; }

Jelle 11-15-2010 20:22

Re: Get two biggest of a series of numbers
 
Thanks, I will try that!

Kreation 11-15-2010 20:39

Re: Get two biggest of a series of numbers
 
@Exolent: Where did the SortCustom2D( ) come from? Is it a stock? :o

EDIT: I hate that face, it's supposed to look scared but it looks like interested in a creepy way.

Exolent[jNr] 11-15-2010 21:21

Re: Get two biggest of a series of numbers
 
Quote:

Originally Posted by Kreation (Post 1350324)
@Exolent: Where did the SortCustom2D( ) come from? Is it a stock? :o

EDIT: I hate that face, it's supposed to look scared but it looks like interested in a creepy way.

It's a native. See sorting.inc.

Kreation 11-15-2010 21:22

Re: Get two biggest of a series of numbers
 
Quote:

Originally Posted by Exolent[jNr] (Post 1350344)
It's a native. See sorting.inc.

Will do.


All times are GMT -4. The time now is 11:23.

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