SA-MP Forums Archive
Whats wrong with this Auto Balance - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Whats wrong with this Auto Balance (/showthread.php?tid=266509)



Whats wrong with this Auto Balance - handerson - 05.07.2011

Код:
new Count1, Count2;

public OnPlayerRequestSpawn(playerid)
{
   if ((Count1 > Count2) && GetPlayerTeam(playerid) == TEAM_TERRORIST)
   {
      GameTextForPlayer(playerid, "~r~This team is full!", 600, 5);
      PlayerPlaySound(playerid,1055,0, 0, 0);
      return 0;
   }
   else if((Count2 < Count1) && GetPlayerTeam(playerid) == TEAM_KOPASSUS)
   {
      GameTextForPlayer(playerid, "~r~This team is full!", 600, 5);
      PlayerPlaySound(playerid,1055,0, 0, 0);
      return 0;
   }
   SetPlayerToTeamColour(playerid);
   if( GetPlayerTeam( playerid ) == TEAM_KOPASSUS ) Count1++;
   else if( GetPlayerTeam( playerid ) == TEAM_TERRORIST ) Count2++;
   return 1;
}

public OnPlayerDisconnect
{
 if( GetPlayerTeam( playerid ) == TEAM_KOPASSUS ) Count1--;
 else if( GetPlayerTeam( playerid ) == TEAM_TERRORIST ) Count2--;
return 1;
}
my server still could spawn 2 player with the same team,,,


Re: Whats wrong with this Auto Balance - Bakr - 05.07.2011

Ah, it seems I mixed up the variables!
pawn Код:
new Count1, Count2;

public OnPlayerRequestSpawn(playerid)
{
   if ((Count1 > Count2) && GetPlayerTeam(playerid) == TEAM_KOPASSUS)
   {
      GameTextForPlayer(playerid, "~r~This team is full!", 600, 5);
      PlayerPlaySound(playerid,1055,0, 0, 0);
      return 0;
   }
   else if((Count2 > Count1) && GetPlayerTeam(playerid) == TEAM_TERRORIST)
   {
      GameTextForPlayer(playerid, "~r~This team is full!", 600, 5);
      PlayerPlaySound(playerid,1055,0, 0, 0);
      return 0;
   }
   SetPlayerToTeamColour(playerid);
   if( GetPlayerTeam( playerid ) == TEAM_KOPASSUS ) Count1++;
   else if( GetPlayerTeam( playerid ) == TEAM_TERRORIST ) Count2++;
   return 1;
}

public OnPlayerDisconnect
{
 if( GetPlayerTeam( playerid ) == TEAM_KOPASSUS ) Count1--;
 else if( GetPlayerTeam( playerid ) == TEAM_TERRORIST ) Count2--;
return 1;
}



Re: Whats wrong with this Auto Balance - handerson - 05.07.2011

whats the different,,

that auto balance doesnt work


Re: Whats wrong with this Auto Balance - Bakr - 05.07.2011

Do you set the player's teams during OnPlayerRequestClass? If not, that would be your problem, as their team would still be equal to NO_TEAM.

Under OnPlayerRequestClass, compare their classid with the skin they are one, and set their team there. Then your script will work.


Re: Whats wrong with this Auto Balance - handerson - 05.07.2011

Quote:
Originally Posted by Bakr
Посмотреть сообщение
Do you set the player's teams during OnPlayerRequestClass? If not, that would be your problem, as their team would still be equal to NO_TEAM.

Under OnPlayerRequestClass, compare their classid with the skin they are one, and set their team there. Then your script will work.
i made this
is that right
Код:
public OnPlayerRequestClass(playerid, classid)
{
	SetPlayerPos(playerid, 1380.6447,-1753.0427,13.5469);
    SetPlayerFacingAngle(playerid, 269.6420);
    SetPlayerCameraPos(playerid, 1387.2906,-1752.8887,13.3828);
    SetPlayerCameraLookAt(playerid, 1380.6447,-1753.0427,13.5469);

    if(classid == 0)
	{
		GameTextForPlayer(playerid,"~r~Terorist",6000,6);
		gTeam[playerid] = TEAM_RED;
		SetPlayerTeam(playerid, 0);
	}
 	if(classid == 1)
	 {
		GameTextForPlayer(playerid,"~b~Counter Terorist",6000,6);
		gTeam[playerid] = TEAM_BLUE;
		SetPlayerTeam(playerid, 1);
	}
	return 1;
}



Re: Whats wrong with this Auto Balance - Bakr - 05.07.2011

It depends on your definitions. Is Counter terrorist the same as kopassus?

If so, your defines should look like this:
pawn Код:
#define TEAM_KOPASSUS 1
#define TEAM_TERRORIST 0