how to count the ammount player of team
#1

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
Reply
#2

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.
Reply
#3

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.
Reply
#4

how to make player cant spawn,,, if count1 > count2
Reply
#5

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;
}
Reply
#6

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
Reply
#7

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;
}
Reply
#8

it doesnt work,,

my server can spawn 2 player with the same team
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)