Raised This Month: $32 Target: $400
 8% 

Can anyone write function to mix array..?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ElijahDD
Junior Member
Join Date: Aug 2018
Old 09-14-2018 , 11:14   Can anyone write function to mix array..?
Reply With Quote #1

Hello.
Maybe someone have or can write this function:

I have 8 teams (4 players in each), 32 players online. I need function to mix players in teams.
For example:

Code:
//First team (1, 10, 15, 25 - player index)
Player[1][iTeam] = 1;
Player[10][iTeam] = 1;
Player[15][iTeam] = 1;
Player[25][iTeam] = 1;

//Second team
Player[2][iTeam] = 2;
Player[6][iTeam] = 2;
Player[31][iTeam] = 2;
Player[11][iTeam] = 2;
If someone can help with this - please help me

Last edited by ElijahDD; 09-14-2018 at 11:58.
ElijahDD is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 09-14-2018 , 12:12   Re: Can anyone write function to mix array..?
Reply With Quote #2

That's something my CS Battle Royale mod does. https://forums.alliedmods.net/showthread.php?t=309613
__________________
edon1337 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 09-14-2018 , 16:24   Re: Can anyone write function to mix array..?
Reply With Quote #3

Here use this
https://forums.alliedmods.net/showpo...6&postcount=10


Example usage
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 09-14-2018 at 16:27.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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
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 03:40.


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