SA-MP Forums Archive
how to count the ammount player of team - 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: how to count the ammount player of team (/showthread.php?tid=266504)



how to count the ammount player of team - handerson - 05.07.2011

Quote:

public OnPlayerRequestSpawn(playerid)
{
new Count1, Count2;
for(new p = 0; p < GetMaxPlayers(); p++)
{
if (GetPlayerTeam(p) == TEAM_KOPASSUS) Count1++;
else if(GetPlayerTeam(p) == TEAM_TERRORIST) Count2++;
}
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);
return 1;
}

is that right, thats auto balance
and how to make if player disconnect,
the count will descrease,, pls tell me


Re: how to count the ammount player of team - Bakr - 05.07.2011

Yes, that should work, except you have the Count1 and Count2 mixed up in your statements.
pawn Код:
if((Count2 > Count1) && GetPlayerTeam(playerid) == TEAM_TERRORIST)
{
// code
}
else if((Count2 < Count1) && GetPlayerTeam(playerid) == TEAM_KOPASSUS)
{
//code
}
And if you want to decrease the value when the player disconnects, you need to create the Count1 and Count2 variables globally.
pawn Код:
//Above main( )
new Count1, Count2;

//Under OnPlayerDisconnect
if( GetPlayerTeam( playerid ) == TEAM_KOPASSUS ) Count1--;
else if( GetPlayerTeam( playerid ) == TEAM_TERRORIST ) Count2--;
You will also need to remove the existing Count1 and Count2 variable syou have under OnPlayerRequestSpawn.


Re: how to count the ammount player of team - Snipa - 05.07.2011

pawn Код:
OnPlayerDisconnect(playerid) { if (GetPlayerTeam(p) == TEAM_KOPASSUS) Count1--;
else if(GetPlayerTeam(p) == TEAM_TERRORIST) Count2--; return 1 }
Sorry if it looks fuxed. You can indent it. I was too lazy to fire up pawno.


Re: how to count the ammount player of team - handerson - 05.07.2011

how to make player cant spawn,,, if count1 > count2


Re: how to count the ammount player of team - Bakr - 05.07.2011

The same way you have it alread, return 0.

The final code should look something like this:
pawn Код:
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);
return 1;
}



Re: how to count the ammount player of team - handerson - 05.07.2011

Quote:
Originally Posted by Bakr
Посмотреть сообщение
Yes, that should work, except you have the Count1 and Count2 mixed up in your statements.
pawn Код:
if((Count2 > Count1) && GetPlayerTeam(playerid) == TEAM_TERRORIST)
{
// code
}
else if((Count2 < Count1) && GetPlayerTeam(playerid) == TEAM_KOPASSUS)
{
//code
}
And if you want to decrease the value when the player disconnects, you need to create the Count1 and Count2 variables globally.
pawn Код:
//Above main( )
new Count1, Count2;

//Under OnPlayerDisconnect
if( GetPlayerTeam( playerid ) == TEAM_KOPASSUS ) Count1--;
else if( GetPlayerTeam( playerid ) == TEAM_TERRORIST ) Count2--;
You will also need to remove the existing Count1 and Count2 variable syou have under OnPlayerRequestSpawn.
Quote:
Originally Posted by Bakr
Посмотреть сообщение
The same way you have it alread, return 0.

The final code should look something like this:
pawn Код:
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);
return 1;
}
where i should to put this
Код:
new Count1, Count2;
for(new p = 0; p < GetMaxPlayers(); p++)
{
if (GetPlayerTeam(p) == TEAM_KOPASSUS) Count1++;
else if(GetPlayerTeam(p) == TEAM_TERRORIST) Count2++;
}
sorry im newb


Re: how to count the ammount player of team - Bakr - 05.07.2011

You will not need it, since the variables are now globally created. You will need to increase them though, which I failed to do by my last post. The end result should look like this:
pawn Код:
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;
}



Re: how to count the ammount player of team - handerson - 05.07.2011

it doesnt work,,

my server can spawn 2 player with the same team