A simple Team Balancer ++
#1

Ok ive created a simple balancer for teams so you automaticly get set to which team is lowest on players when you spawn..

Please note: My teams are team 1 and team 2 thats why i have a +1 on the random so there cant be a 0

Код:
stock BalanceTeams(playerid)
{
	if(ServerGameMode == 1)
	{
		if(TeamOp == TeamSpet)
		{
		    PlayerInfo[playerid][pTeam] = random(2)+1;
		    if(PlayerInfo[playerid][pTeam] == 1)
		    {
		        TeamOp ++;
			}
		    if(PlayerInfo[playerid][pTeam] == 2)
		    {
		        TeamSpet ++;
			}
		}
		if(TeamOp > TeamSpet)
		{
		    PlayerInfo[playerid][pTeam] = 2;
		    TeamOp ++;
		}
		if(TeamSpet > TeamOp)
		{
		    PlayerInfo[playerid][pTeam] = 1;
		    TeamSpet ++;
		}
		return 1;
	}
	return 1;
}
But it doesent work any clues why?
This is stopping my whole script working so please please help!
Reply
#2

If TeamOp has a greater number of players, you put the player in TeamSpet but are increasing the count of TeamOp. Similarly, you are putting the player in TeamOp and increasing the count of TeamSpet. You need to increase the count of the team that the player was put in, not the other team.
Reply
#3

I'll give you a little snippet out of my code, so you can get the basic idea. You seem to have a relatively firm grasp on pawno, so it shoudln't be a challenge

pawn Код:
public AutoAssign(playerid)
{
    new RedCount, BlueCount;
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(EventTeam[i] == EVENT_TEAM_RED)
        {
            RedCount ++;
        }
        if(EventTeam[i] == EVENT_TEAM_BLUE)
        {
            BlueCount ++;
        }
    }
    if(RedCount > BlueCount)
    {
        return EVENT_TEAM_BLUE;
    }
    if(BlueCount > RedCount)
    {
        return EVENT_TEAM_RED;
    }
    if(BlueCount == RedCount)
    {
        new decide = random(2);
        if(decide == 0)
        {
            return EVENT_TEAM_RED;
        }
        if(decide == 1)
        {
            return EVENT_TEAM_BLUE;
        }
    }
    return 0;
}
Reply
#4

Quote:
Originally Posted by Rob_Maate
Посмотреть сообщение
I'll give you a little snippet out of my code, so you can get the basic idea. You seem to have a relatively firm grasp on pawno, so it shoudln't be a challenge

pawn Код:
public AutoAssign(playerid)
{
    new RedCount, BlueCount;
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(EventTeam[i] == EVENT_TEAM_RED)
        {
            RedCount ++;
        }
        if(EventTeam[i] == EVENT_TEAM_BLUE)
        {
            BlueCount ++;
        }
    }
    if(RedCount > BlueCount)
    {
        return EVENT_TEAM_BLUE;
    }
    if(BlueCount > RedCount)
    {
        return EVENT_TEAM_RED;
    }
    if(BlueCount == RedCount)
    {
        new decide = random(2);
        if(decide == 0)
        {
            return EVENT_TEAM_RED;
        }
        if(decide == 1)
        {
            return EVENT_TEAM_BLUE;
        }
    }
    return 0;
}
Stop using loops!!!!! You can increase/decrease the team count within the if statements... Then do a checktowards which team the player is in and decrease the count. Think more effective :O
Reply
#5

Lol what the hell?

1loop isn't gonna do much
Reply
#6

Quote:
Originally Posted by Rob_Maate
Посмотреть сообщение
Lol what the hell?

1loop isn't gonna do much
Well, don't respond at all if you think that is so while there is better code that can be provided and even more shorter... Do a bench mark with that code as well, see which one is faster.

That loop has no check for IsPlayerConnected, meaning it can be unsafe in various ways :O.
Reply
#7

if(IsPlayerConnected(playerid))
{
AutoAssign(playerid);
}
Reply
#8

Hey ok abit confused with the mixed comments personally i cant see much wrong with mine. like i say 2 teams
PlayerInfo[playerid][pTeam] = 1; and PlayerInfo[playerid][pTeam] = 2;
i dont have a team 0 so does the random(2)+1; feature work will that return either a 1 or a 2?

and then if there is anything wrong can someone edit it please and show me what is wrong
Much appreciated
Reply
#9

Quote:
Originally Posted by legho
Посмотреть сообщение
Hey ok abit confused with the mixed comments personally i cant see much wrong with mine. like i say 2 teams
PlayerInfo[playerid][pTeam] = 1; and PlayerInfo[playerid][pTeam] = 2;
i dont have a team 0 so does the random(2)+1; feature work will that return either a 1 or a 2?

and then if there is anything wrong can someone edit it please and show me what is wrong
Much appreciated
Well, check if the 2 teams are the same, if they are just use "random" to find a team to be assigned to. However don't use the previous guys code, stick with yours and just fix up a bit.
Reply
#10

Yeah fixed it up all i need to know
what this will return?

random(2)+1; either a 1 or a 2?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)