Raised This Month: $ Target: $400
 0% 

Dividing


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Simon.
Member
Join Date: Oct 2016
Location: Sweden
Old 02-15-2017 , 15:45   Dividing
Reply With Quote #1

Is there a way to divide cases?

Let's say I want to divide terrorists into 2 teams,

PHP Code:
        switch(GetRandomInt(12))
        {
            
            case 
1:{
                             
//team1
            
}
            case 
2:{
                
//team2
            
}
        } 
but if I use GetRandomInt there is a chance that they won't be divided correctly, is there another way do this?


Any suggestions/comments greatly appreciated!
__________________

Last edited by Simon.; 02-21-2017 at 02:03.
Simon. is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 02-15-2017 , 15:57   Re: Dividing
Reply With Quote #2

I generally make an array with all players. Scramble the array. Then loop from the start and toggle between putting the player on ct/t on each iteration step.
__________________
Neuro Toxin is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 02-15-2017 , 16:32   Re: Dividing
Reply With Quote #3

The easiest way I can think of would to use of an ArrayLists (or possibly normal array)
Add all players on terrorists to the ArrayList.
Pick a random index between 0 and the size of the ArrayList
set a variable that switches between the two teams 0/1.
If the variable is 0 add to team 1, if the variable is 1 add to team 2.
When the player is added switch the variable 0/1.
By the end of the loop of players the teams should be as even as possible.
edit: went into a meeting then came back out and was ninja'd oops.

Last edited by Mitchell; 02-15-2017 at 16:32.
Mitchell is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 02-15-2017 , 16:59   Re: Dividing
Reply With Quote #4

Devide the set into two groups, scramble one and mirror the other. That way if 3 players end up on T, and 2 on CT, in the other group 3 must go to CT and 2 to T.

Edit: Scramble the array before processing it so client on position 3 and 6 (both are in the middle of the subset) don't always end up on the same team

Code:
********************X*********************
*    T       T      X T     T    T     T *
*                   X                    *
*                   X                    *
* C    C   C    C   X    C          C    *
*                   X                    *
********************X*********************
Edit: wtf Am I saying, just scramble the array and put 0 to n/2 on one team and n/2 to n on the other team
__________________

Last edited by fakuivan; 02-15-2017 at 17:58.
fakuivan is offline
Simon.
Member
Join Date: Oct 2016
Location: Sweden
Old 02-17-2017 , 12:04   Re: Dividing
Reply With Quote #5

Ok, thanks but how do i count clients?

GetClientCount?
__________________
Simon. is offline
sdz
Senior Member
Join Date: Feb 2012
Old 02-17-2017 , 20:45   Re: Dividing
Reply With Quote #6

Quote:
Originally Posted by Simon. View Post
Ok, thanks but how do i count clients?

GetClientCount?
PHP Code:
for(new 1<= MaxClientsi++)
{
     
//Do stuff.

You can add in conditionals in that loop in order to get yourself the precise number you desire.
sdz is offline
Starbish
AlliedModders Donor
Join Date: Oct 2011
Location: South Korea
Old 02-19-2017 , 06:06   Re: Dividing
Reply With Quote #7

get team client's counts for making int arrays,

and put all client ids into that array

and sort it as random
__________________
Starbish is offline
noxuu
Member
Join Date: Dec 2015
Old 02-19-2017 , 18:49   Re: Dividing
Reply With Quote #8

Code:
	int aliveT;
	for(int client = 1; client <= MaxClients; ++client) 
	{ 
		if (!IsClientInGame(client) || !IsPlayerAlive(client) || GetClientTeam(client) != CS_TEAM_T) 
			continue; 
		
		aliveT++;
	}
	
	int color1, color2;
	for(int client = 1; client <= MaxClients; ++client) 
	{ 
		if (!IsClientInGame(client) || !IsPlayerAlive(client) || GetClientTeam(client) != CS_TEAM_T) 
			continue;
		
		if(GetRandomInt(1,2) == 1)
		{
			if(color1 < aliveT / 2)
			{
				SetEntityRenderColor(client, 0, 255, 0, 255);
				Jail_KolorGracza[client] = 1;
				color1++;
			}
			else
			{
				SetEntityRenderColor(client, 255, 0, 0, 255);
				Jail_KolorGracza[client] = 2;
				color2++;
			}
		}
		else
		{
			if(color2 < aliveT / 2)
			{
				SetEntityRenderColor(client, 255, 0, 0, 255);
				color2++;
			}
			else
			{
				SetEntityRenderColor(client, 0, 255, 0, 255);
				color1++;
			}
		}
	}
Works perfect. Don't need to use arrays.

Last edited by noxuu; 02-19-2017 at 18:50.
noxuu is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 02-19-2017 , 19:46   Re: Dividing
Reply With Quote #9

Just shuffle an array of valid clients and then alternate assignment.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 02-20-2017 , 07:13   Re: Dividing
Reply With Quote #10

Quote:
Originally Posted by noxuu View Post
Code:
	int aliveT;
	for(int client = 1; client <= MaxClients; ++client) 
	{ 
		if (!IsClientInGame(client) || !IsPlayerAlive(client) || GetClientTeam(client) != CS_TEAM_T) 
			continue; 
		
		aliveT++;
	}
	
	int color1, color2;
	for(int client = 1; client <= MaxClients; ++client) 
	{ 
		if (!IsClientInGame(client) || !IsPlayerAlive(client) || GetClientTeam(client) != CS_TEAM_T) 
			continue;
		
		if(GetRandomInt(1,2) == 1)
		{
			if(color1 < aliveT / 2)
			{
				SetEntityRenderColor(client, 0, 255, 0, 255);
				Jail_KolorGracza[client] = 1;
				color1++;
			}
			else
			{
				SetEntityRenderColor(client, 255, 0, 0, 255);
				Jail_KolorGracza[client] = 2;
				color2++;
			}
		}
		else
		{
			if(color2 < aliveT / 2)
			{
				SetEntityRenderColor(client, 255, 0, 0, 255);
				color2++;
			}
			else
			{
				SetEntityRenderColor(client, 0, 255, 0, 255);
				color1++;
			}
		}
	}
Works perfect. Don't need to use arrays.
It's still easier to just have an array of players (shuffled) and alternate 1/2 concurrently on each of them.
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS

Last edited by OSWO; 02-20-2017 at 07:14.
OSWO 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 02:12.


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