How to make Team balancer?
#1

Heey

How to make Team balancer?

Don't say search on ****** or something because I already did
Reply
#2

if you're using GetPlayerTeam

pawn Код:
#define TEAMA 1
#define TEAMB 2

public OnPlayerRequestSpawn(playerid)
{
   new team1 = GetPlayersInTeamFromMaxPlayers(TEAMA);
   new team2 = GetPlayersInTeamFromMaxPlayers(TEAMB);
   if(team1 > team2 && gTeam[playerid] == TEAMB && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team B Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, COLOR_RED, "Please Choose Another team because team B is full.");
      return 0;
   }
   else if(team2 > team1 && gTeam[playerid] == TEAMA && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team A Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, COLOR_RED, "Please Choose Another team because team A is full.");
      return 0;
   }
   return 1;
}

stock GetPlayersInTeamFromMaxPlayers(teamid)
{
    new playercount = 0;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;
        if(GetPlayerTeam(i) != teamid) continue;
        playercount++;
    }
    return playercount;
}

if you're using array, variables..
pawn Код:
#define TEAMA 1
#define TEAMB 2

new gTeam[MAX_PLAYERS];

public OnPlayerRequestSpawn(playerid)
{
   new team1 = GetPlayersInTeamFromMaxPlayers(TEAMA);
   new team2 = GetPlayersInTeamFromMaxPlayers(TEAMB);
   if(team1 > team2 && GetPlayerTeam(playerid) == TEAMB && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team B Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, COLOR_RED, "Please Choose Another team because team B is full.");
      return 0;
   }
   else if(team2 > team1 && GetPlayerTeam(playerid) == TEAMA && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team A Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, COLOR_RED, "Please Choose Another team because team A is full.");
      return 0;
   }
   return 1;
}

stock GetPlayersInTeamFromMaxPlayers(teamid)
{
    new playercount = 0;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;
        if(gTeam[i] != teamid) continue;
        playercount++;
    }
    return playercount;
}
Reply
#3

Example:
pawn Код:
new gTeam1,
gTeam2,
pTeam[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
    if(gTeam1 <= gTeam2)
    {
        SendClientMessage(playerid, -1 "You have joined team 1!");
        pTeam[playerid] = 1;
        gTeam1 ++;
    }
    else
    {
        SendClientMessage(playerid, -1 "You have joined team 2!");
        pTeam[playerid] = 2;
        gTeam2 ++;
    }
    return 1;
}

CMD:balanceteams(playerid, params[])
{
    SendClientMessageToAll(-1, "An administrator has balanced the teams!");

    gTeam1 = 0, gTeam2 = 0;
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(gTeam1 <= gTeam2)
        {
            SendClientMessage(playerid, -1 "You have joined team 1!");
            pTeam[playerid] = 1;
            gTeam1 ++;
        }
        else
        {
            SendClientMessage(playerid, -1 "You have joined team 2!");
            pTeam[playerid] = 2;
            gTeam2 ++;
        }
    }
    return 1;
}
Reply
#4

Quote:
Originally Posted by ReD_HunTeR
Посмотреть сообщение
if you're using GetPlayerTeam

pawn Код:
#define TEAMA 1
#define TEAMB 2

public OnPlayerRequestSpawn(playerid)
{
   new team1 = GetPlayersInTeamFromMaxPlayers(TEAMA);
   new team2 = GetPlayersInTeamFromMaxPlayers(TEAMB);
   if(team1 > team2 && gTeam[playerid] == TEAMB && team1 != team2)
   {
       if(PlayerInfo[playerid][pMafia] == 0)
       {
          GameTextForPlayer(playerid, "~r~Team B Full!~n~~w~Choose Another Team!", 3000, 5);
          SendClientMessage(playerid, COLOR_RED, "Please Choose Another team because team B is full.");
          return 0;
       }
   }
   else if(team2 > team1 && gTeam[playerid] == TEAMA && team1 != team2)
   {
       if(PlayerInfo[playerid][pOptic] == 0)
       {
          GameTextForPlayer(playerid, "~r~Team A Full!~n~~w~Choose Another Team!", 3000, 5);
          SendClientMessage(playerid, COLOR_RED, "Please Choose Another team because team A is full.");
          return 0;
       }
   }
   return 1;
}

stock GetPlayersInTeamFromMaxPlayers(teamid)
{
    new playercount = 0;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;
        if(GetPlayerTeam(i) != teamid) continue;
        playercount++;
    }
    return playercount;
}

if you're using array, variables..
pawn Код:
#define TEAMA 1
#define TEAMB 2

new gTeam[MAX_PLAYERS];

public OnPlayerRequestSpawn(playerid)
{
   new team1 = GetPlayersInTeamFromMaxPlayers(TEAMA);
   new team2 = GetPlayersInTeamFromMaxPlayers(TEAMB);
   if(team1 > team2 && GetPlayerTeam(playerid) == TEAMB && team1 != team2)
   {
       if(PlayerInfo[playerid][pMafia] == 0)
       {
          GameTextForPlayer(playerid, "~r~Team B Full!~n~~w~Choose Another Team!", 3000, 5);
          SendClientMessage(playerid, COLOR_RED, "Please Choose Another team because team B is full.");
          return 0;
       }
   }
   else if(team2 > team1 && GetPlayerTeam(playerid) == TEAMA && team1 != team2)
   {
       if(PlayerInfo[playerid][pOptic] == 0)
       {
          GameTextForPlayer(playerid, "~r~Team A Full!~n~~w~Choose Another Team!", 3000, 5);
          SendClientMessage(playerid, COLOR_RED, "Please Choose Another team because team A is full.");
          return 0;
       }
   }
   return 1;
}

stock GetPlayersInTeamFromMaxPlayers(teamid)
{
    new playercount = 0;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;
        if(gTeam[i] != teamid) continue;
        playercount++;
    }
    return playercount;
}
PHP код:
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(1743) : error 017undefined symbol "UpdateConfig"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2207) : error 017undefined symbol "DestroyAllMenus"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2217) : error 017undefined symbol "SavePlayer"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2322) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2327) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2331) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2336) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2470) : error 017undefined symbol "SaveToFile"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2484) : error 017undefined symbol "SaveToFile"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2747) : error 017undefined symbol "SavePlayer"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2748) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2748) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3130) : error 017undefined symbol "JailPlayer"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3363) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3379) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3395) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3411) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3427) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3453) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3461) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3469) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3477) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3485) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3493) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3501) : error 017undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3509) : error 017undefined symbol "PlayerName2" 
Reply
#5

try this fixed

if u're using GetPlayerTeam
pawn Код:
#include <a_samp>

#define TEAMA 1
#define TEAMB 2

public OnPlayerRequestSpawn(playerid)
{
   new team1 = GetPlayersInTeamFromMaxPlayers(TEAMA);
   new team2 = GetPlayersInTeamFromMaxPlayers(TEAMB);
   if(team1 > team2 && GetPlayerTeam(playerid) == TEAMB && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team B Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, 0xFF0000AA, "Please Choose Another team because team B is full.");
      return 0;
   }
   else if(team2 > team1 && GetPlayerTeam(playerid) == TEAMA && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team A Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, 0xFF0000AA, "Please Choose Another team because team A is full.");
      return 0;
   }
   return 1;
}

stock GetPlayersInTeamFromMaxPlayers(teamid)
{
    new playercount = 0;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;
        if(GetPlayerTeam(i) != teamid) continue;
        playercount++;
    }
    return playercount;
}


and if you're using variables...

pawn Код:
#include <a_samp>

#define TEAMA 1
#define TEAMB 2

new gTeam[MAX_PLAYERS];

public OnPlayerRequestSpawn(playerid)
{
   new team1 = GetPlayersInTeamFromMaxPlayers(TEAMA);
   new team2 = GetPlayersInTeamFromMaxPlayers(TEAMB);
   if(team1 > team2 && gTeam[playerid] == TEAMB && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team B Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, 0xFF0000AA, "Please Choose Another team because team B is full.");
      return 0;
   }
   else if(team2 > team1 && gTeam[playerid] == TEAMA && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team A Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, 0xFF0000AA, "Please Choose Another team because team A is full.");
      return 0;
   }
   return 1;
}

stock GetPlayersInTeamFromMaxPlayers(teamid)
{
    new playercount = 0;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;
        if(gTeam[i] != teamid) continue;
        playercount++;
    }
    return playercount;
}
Reply
#6

Quote:
Originally Posted by ReD_HunTeR
Посмотреть сообщение
try this fixed

if u're using GetPlayerTeam
pawn Код:
#include <a_samp>

#define TEAMA 1
#define TEAMB 2

public OnPlayerRequestSpawn(playerid)
{
   new team1 = GetPlayersInTeamFromMaxPlayers(TEAMA);
   new team2 = GetPlayersInTeamFromMaxPlayers(TEAMB);
   if(team1 > team2 && GetPlayerTeam(playerid) == TEAMB && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team B Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, 0xFF0000AA, "Please Choose Another team because team B is full.");
      return 0;
   }
   else if(team2 > team1 && GetPlayerTeam(playerid) == TEAMA && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team A Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, 0xFF0000AA, "Please Choose Another team because team A is full.");
      return 0;
   }
   return 1;
}

stock GetPlayersInTeamFromMaxPlayers(teamid)
{
    new playercount = 0;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;
        if(GetPlayerTeam(i) != teamid) continue;
        playercount++;
    }
    return playercount;
}


and if you're using variables...

pawn Код:
#include <a_samp>

#define TEAMA 1
#define TEAMB 2

new gTeam[MAX_PLAYERS];

public OnPlayerRequestSpawn(playerid)
{
   new team1 = GetPlayersInTeamFromMaxPlayers(TEAMA);
   new team2 = GetPlayersInTeamFromMaxPlayers(TEAMB);
   if(team1 > team2 && gTeam[playerid] == TEAMB && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team B Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, 0xFF0000AA, "Please Choose Another team because team B is full.");
      return 0;
   }
   else if(team2 > team1 && gTeam[playerid] == TEAMA && team1 != team2)
   {
      GameTextForPlayer(playerid, "~r~Team A Full!~n~~w~Choose Another Team!", 3000, 5);
      SendClientMessage(playerid, 0xFF0000AA, "Please Choose Another team because team A is full.");
      return 0;
   }
   return 1;
}

stock GetPlayersInTeamFromMaxPlayers(teamid)
{
    new playercount = 0;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(GetPlayerState(i) == PLAYER_STATE_NONE) continue;
        if(gTeam[i] != teamid) continue;
        playercount++;
    }
    return playercount;
}
There's no need to loop through all the players just to see how much of them are on a specific team, you could just use a variable as an accumulator:

pawn Код:
new gTeam1,
gTeam2,
pTeam[MAX_PLAYERS];

public OnPlayerDisconnect(playerid, reason)
{
    if(pTeam[playerid] == 1) gTeam1 --;
    else gTeam2 --;
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    if(pTeam[playerid] == 1)
    {
        gTeam1 --;
        pTeam[playerid] = 0;
    }
    else if(pTeam[playerid] == 2)
    {
        gTeam2 --;
        pTeam[playerid] = 0;
    }
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
   if(gTeam1 <= gTeam2)
   {
      GameTextForPlayer(playerid, "~r~Team 1 is full!~n~~w~Choose another team!", 3000, 5);
      SendClientMessage(playerid, 0xFF0000AA, "Please choose another team because team 1 is full.");
      return 0;
   }
   else
   {
      GameTextForPlayer(playerid, "~r~Team 2 is full!~n~~w~Choose another team!", 3000, 5);
      SendClientMessage(playerid, 0xFF0000AA, "Please choose another team because team 2 is full.");
      return 0;
   }
   return 1;
}

public OnPlayerSpawn(playerid)
{
    if(gTeam1 <= gTeam2)
    {
        SendClientMessage(playerid, -1 "You have joined team 1!");
        pTeam[playerid] = 1;
        gTeam1 ++;
    }
    else
    {
        SendClientMessage(playerid, -1 "You have joined team 2!");
        pTeam[playerid] = 2;
        gTeam2 ++;
    }
    return 1;
}

CMD:balanceteams(playerid, params[])
{
    SendClientMessageToAll(-1, "An administrator has balanced the teams!");

    gTeam1 = 0, gTeam2 = 0;
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(gTeam1 <= gTeam2)
        {
            SendClientMessage(playerid, -1 "You have joined team 1!");
            pTeam[playerid] = 1;
            gTeam1 ++;
        }
        else
        {
            SendClientMessage(playerid, -1 "You have joined team 2!");
            pTeam[playerid] = 2;
            gTeam2 ++;
        }
    }
    return 1;
}
Reply
#7

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
There's no need to loop through all the players just to see how much of them are on a specific team, you could just use a variable as an accumulator:

pawn Код:
new gTeam1,
gTeam2,
pTeam[MAX_PLAYERS];

public OnPlayerDisconnect(playerid, reason)
{
    if(pTeam[playerid] == 1) gTeam1 --;
    else gTeam2 --;
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    if(pTeam[playerid] == 1)
    {
        gTeam1 --;
        pTeam[playerid] = 0;
    }
    else if(pTeam[playerid] == 2)
    {
        gTeam2 --;
        pTeam[playerid] = 0;
    }
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
   if(gTeam1 <= gTeam2)
   {
      GameTextForPlayer(playerid, "~r~Team 1 is full!~n~~w~Choose another team!", 3000, 5);
      SendClientMessage(playerid, 0xFF0000AA, "Please choose another team because team 1 is full.");
      return 0;
   }
   else
   {
      GameTextForPlayer(playerid, "~r~Team 2 is full!~n~~w~Choose another team!", 3000, 5);
      SendClientMessage(playerid, 0xFF0000AA, "Please choose another team because team 2 is full.");
      return 0;
   }
   return 1;
}

public OnPlayerSpawn(playerid)
{
    if(gTeam1 <= gTeam2)
    {
        SendClientMessage(playerid, -1 "You have joined team 1!");
        pTeam[playerid] = 1;
        gTeam1 ++;
    }
    else
    {
        SendClientMessage(playerid, -1 "You have joined team 2!");
        pTeam[playerid] = 2;
        gTeam2 ++;
    }
    return 1;
}

CMD:balanceteams(playerid, params[])
{
    SendClientMessageToAll(-1, "An administrator has balanced the teams!");

    gTeam1 = 0, gTeam2 = 0;
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(gTeam1 <= gTeam2)
        {
            SendClientMessage(playerid, -1 "You have joined team 1!");
            pTeam[playerid] = 1;
            gTeam1 ++;
        }
        else
        {
            SendClientMessage(playerid, -1 "You have joined team 2!");
            pTeam[playerid] = 2;
            gTeam2 ++;
        }
    }
    return 1;
}
Both don't work
Reply
#8

Quote:
Originally Posted by Fantje
Посмотреть сообщение
Both don't work
They are only examples, you're the one who has to make it work with your script.
Reply
#9

I changed the teams to mine? don't work thanks btw
Reply
#10

Quote:
Originally Posted by Fantje
Посмотреть сообщение
I changed the teams to mine? don't work thanks btw
Post your code, and we'll gladly help you out with it.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)