View Single Post
shauli
Member
Join Date: Jun 2018
Old 09-15-2018 , 06:09   Re: Can anyone write function to mix array..?
Reply With Quote #4

I understand your request but couldn't understand the array you've provided ('Player[1][iTeam]'), so I suggest two different alternatives:

Team Array:
PHP Code:
#define TEAMS 8

new aTeamsTEAMS ][ ];

new 
aPlayers32 ], iPnumiCurrentiIndex;
get_playersaPlayersiPnum ); // get players on the server

SortIntegersaPlayersiPnumSort_Random ); // shuffle the players array

while( iPnum )
{
    
aTeamsiCurrent ][ iIndex ] = aPlayersiPnum ]; // push a player to a team, one by one to each team
    
iPnum --;
    
    if( ++
iCurrent >= TEAMS )
    {
        
iCurrent 0;
        
iIndex ++;
    }
}

/*

To use like this:

aTeams[ 0 ][ 0 ], first player in team A
aTeams[ 2 ][ 3 ], last player in team C

*/ 
Players Array:
PHP Code:
#define TEAMS 8

new aPlayerTeams33 ];

new 
aPlayers32 ], iPnumiCurrent;
get_playersaPlayersiPnum ); // get players on the server

SortIntegersaPlayersiPnumSort_Random ); // shuffle the players array

for( new 0iPnumi++ )
{
    
aPlayerTeamsaPlayers] ] = iCurrent// set player's team, one by one to each team

    
if( ++iCurrent >= TEAMS )
        
iCurrent 0;
}

/*

To use like this:

aPlayerTeams[ 14 ] to get team of player 14, result will be between 0 and 7

*/ 
Also there's a chance that Sort_Random is only for AMXX 1.8.3/1.9 (I don't really remember), so if you have problems with that native tell me and i'll change it.

Last edited by shauli; 09-15-2018 at 06:10.
shauli is offline