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

How can I split clients iin teams?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kratoss1812
Senior Member
Join Date: May 2018
Location: Romānia
Old 11-16-2019 , 14:45   How can I split clients iin teams?
Reply With Quote #1

I'm trying to divide the clients in teams equally and randomly.

For example: There are 6 players connected. When i 'divide' them there will be 3 CTs and 3T. But, next time I 'divide' them there will not be the same players in CT team or in T team.
__________________
kratoss1812 is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 11-16-2019 , 22:32   Re: How can I split clients iin teams?
Reply With Quote #2

I had a similar problem and came up with this for TF2. It may help you....

Code:
#include <sourcemod> 

public Plugin:myinfo = 
{
	name = "Balance Team",
	author = "PC Gamer",
	description = "Place equal number of Players on each team",
	version = "PLUGIN_VERSION 1.0",
}

public OnPluginStart()
{ 
	RegAdminCmd("sm_balance", Command_balteam, ADMFLAG_SLAY, "Balance the Players on Each Team");
}

public Action Command_balteam(client, args)
{
	new pcount = 1
	for(new i = 1; i < MaxClients; i++)
	{
		if (IsClientInGame(i) && (pcount % 2 == 0))
		{
			ChangeClientTeam(i, 2);  //change player to Red Team
		}
		if (IsClientInGame(i) && (pcount % 2 == 1)) 
		{
			ChangeClientTeam(i, 3);  //change player to Blue Team
		}
		if (IsClientInGame(i))
		{
			pcount++;
		}
	}
	return Plugin_Handled;		
}
Attached Files
File Type: sp Get Plugin or Get Source (teambalance.sp - 96 views - 750 Bytes)
PC Gamer is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 11-17-2019 , 06:21   Re: How can I split clients iin teams?
Reply With Quote #3

Insert all valid client indexes in an array ( Should be the size of MAXPLAYERS+1 ), remember of course to keep track of the number of players in the array. Then, use a random array sort

SortIntegers(clients, count, Sort_Random);

If you need me to post an exact code, I'll do it.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 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:01.


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