21.03.2015, 17:06
Heey
How to make Team balancer?
Don't say search on ****** or something because I already did
How to make Team balancer?
Don't say search on ****** or something because I already did
#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;
}
#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;
}
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;
}
if you're using GetPlayerTeam
pawn Код:
if you're using array, variables.. pawn Код:
|
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(1743) : error 017: undefined symbol "UpdateConfig"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2207) : error 017: undefined symbol "DestroyAllMenus"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2217) : error 017: undefined symbol "SavePlayer"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2322) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2327) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2331) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2336) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2470) : error 017: undefined symbol "SaveToFile"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2484) : error 017: undefined symbol "SaveToFile"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2747) : error 017: undefined symbol "SavePlayer"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2748) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(2748) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3130) : error 017: undefined symbol "JailPlayer"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3363) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3379) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3395) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3411) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3427) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3453) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3461) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3469) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3477) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3485) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3493) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3501) : error 017: undefined symbol "PlayerName2"
C:\Users\Administrator\Desktop\TESTSERVER\gamemodes\SvTMike.pwn(3509) : error 017: undefined symbol "PlayerName2"
#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;
}
#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;
}
try this fixed
if u're using GetPlayerTeam pawn Код:
and if you're using variables... 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;
}
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 Код:
|