Team Balance and Auto Team Balance
#7

Quote:
Originally Posted by gurmani11
Посмотреть сообщение
i would prefer using foreach include. it just help shrink the code and work even better!
Lets start with defines, variables and iterators.
Код:
#include a_samp
#include foreach
#include izcmd
new Iterator:TeamRedPlayer<MAX_PLAYERS>;
new Iterator:TeamBluePlayer<MAX_PLAYERS>;
new bool:IsInTDM[MAX_PLAYERS];

#define Team_Red 	1
#define Team_Blue 	2
Well now lets add a command so that we enter a team that can auto balance itself
Код:
CMD:tdm(playerid)
{
	if(Iter_Count(TeamRedPlayer) > Iter_Count(TeamBluePlayer)) // easy
		SetPlayerTeamEx(playerid, Team_Blue);
	else
		SetPlayerTeamEx(playerid, Team_Red);
	return 1;
}
while working with foreach we have made an extended stock for setting a player's team
Код:
stock SetPlayerTeamEx(playerid, teamid)
{
	switch(teamid)
	{
	    case Team_Red:
	    {
			SetPlayerTeam(playerid, Team_Red);///// Setting team id
			SetPlayerColor(playerid, 0xFF0000FF);///// Color Red
			Iter_Add(TeamRedPlayer, playerid);///// Adding in iterator
	    }
	    case Team_Blue:
	    {
			SetPlayerTeam(playerid, Team_Blue); ///// Setting team id
			SetPlayerColor(playerid, 0x0000FFFF); ///// Color blue
			Iter_Add(TeamBluePlayer, playerid); ///// Adding in iterator
	    }
	}
	IsInTDM[playerid] = true; // Confirm that player is in TDM minigame now
	return 1;
}
Well what if a player disconnects? we must exclude him to avoid false counting obviously
Код:

public OnPlayerDisconnect(playerid, reason)
{
	if(IsInTDM[playerid] == true) // checking if true
		ExcludePlayerFromTeam(playerid); //then exclude player
	return 1;
}



stock ExcludePlayerFromTeam(playerid)
{
	switch(GetPlayerTeam(playerid))
	{
		case Team_Red:
		{
			Iter_Remove(TeamRedPlayer, playerid); //// Removing player so he wont be counted
			SetPlayerColor(playerid, 0xFFFF00FF); ///// Color Setting yellow color say no team color
			SetPlayerTeam(playerid, NO_TEAM); ///// Setting team id to none
		}
		case Team_Blue:
		{
			Iter_Remove(TeamRedPlayer, playerid); //// Removing player so he wont be counted
			SetPlayerColor(playerid, 0xFFFF00FF); ///// Color Setting yellow color say no team color
			SetPlayerTeam(playerid, NO_TEAM); ///// Setting team id to none
		}
		default:
			return 0; // in case player was not in the specified team
	}
	IsInTDM[playerid] = false; // ensure that player is no more in this TDM minigame
	return 1;
}
Thanks in advice, I'm not sure if it's worth it but I'll check it out.
Reply


Messages In This Thread
Team Balance and Auto Team Balance - by NeXoR - 11.10.2016, 12:59
Re: Team Balance and Auto Team Balance - by oMa37 - 11.10.2016, 13:02
Re: Team Balance and Auto Team Balance - by iLearner - 11.10.2016, 13:02
Re: Team Balance and Auto Team Balance - by NeXoR - 11.10.2016, 13:06
Re: Team Balance and Auto Team Balance - by iLearner - 11.10.2016, 13:26
Re: Team Balance and Auto Team Balance - by gurmani11 - 11.10.2016, 13:51
Re: Team Balance and Auto Team Balance - by NeXoR - 11.10.2016, 13:55
Re: Team Balance and Auto Team Balance - by Isolated - 11.10.2016, 14:16
Re: Team Balance and Auto Team Balance - by Konstantinos - 11.10.2016, 14:32
Re: Team Balance and Auto Team Balance - by gurmani11 - 11.10.2016, 14:54

Forum Jump:


Users browsing this thread: 2 Guest(s)