[HELP] Team Balancer problem - 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)
+--- Thread: [HELP] Team Balancer problem (
/showthread.php?tid=446133)
[HELP] Team Balancer problem -
VIP475 - 24.06.2013
hi,
so iam using this: added to my script:
pawn Код:
//[Tutorial] Simple Team Balancer [SA-MP] @ http://www.devshack.info - Tutorial by Weponz Inc. © 2010 - 2011#include <a_samp>//If i need to explain this to you, may god have mercy on your soul..//-----------------------------------[STEP 1]---------------------------------////Ok, Im going to use two teams for this tutorial, TEAM_ONE & TEAM_TWO,//you could simply add more later. Type the following below:#define TEAM_ONE 0#define TEAM_TWO 1//-----------------------------------[STEP 2]---------------------------------////Ok, now we have defined our teams(classes) we need to make a variable//that checks the players team, so we can use a function(shown below)//later to check there team, type the following below:static gTeam
[MAX_PLAYERS
];
//Yes its very common..//Now we can use gTeam[playerid] == TEAM_ONE or gTeam[playerid] == TEAM_TWO..//-----------------------------------[STEP 2]---------------------------------////Now, we need to create a stock which loops through MAX_PLAYERS, counting//how many online players are in our specified team, returning a player count//as an integra(number), This stock was developed by myself so keep my credits!//i will show you below how it works:stock GetPlayersInTeamFromMaxPlayers
(teamid
)//Stock developed by Weponz (Weponz Inc. © 2010 - 2011){ new playercount
= 0;
//Set our count to 0 as we have not counted any players yet.. for(new i
= 0; i
< MAX_PLAYERS; i
++)//Loop through MAX_PLAYERS(I suggest you redefine MAX_PLAYERS to ensure max efficency).. { if(GetPlayerState
(i
) == PLAYER_STATE_NONE
) continue;
//If a player is in class selection continue.. if(gTeam
[i
] != teamid
) continue;
//If a player is NOT in the specified teamid continue.. playercount
++;
//else (there in the teamid) so count the player in the team.. } return playercount;
//Return the total players counted in the specified team..}//-----------------------------------[STEP 3]---------------------------------////Ok, now we can count how many players are in w/e team we check//with our new function GetPlayersInTeamFromMaxPlayers(teamid) we can now//check for team in-balance under OnPlayerRequestSpawn as its most efficent..public OnPlayerRequestSpawn
(playerid
){ new team1
= GetPlayersInTeamFromMaxPlayers
(TEAM_ONE
);
//team1 = how many players are in TEAM_ONE.. new team2
= GetPlayersInTeamFromMaxPlayers
(TEAM_TWO
);
//team2 = how many players are in TEAM_TWO.. if(team1
> team2
&& gTeam
[playerid
] == TEAM_ONE
)//if team1 has more players than team2 and the player is trying to spawn as TEAM_ONE.. { GameTextForPlayer
(playerid,
"~r~Team Full!~n~~w~Choose Another Team!",
3000,
5);
//Tell them its full, choose another team.. return 0;
//And stop them from spawning.. } else if(team2
> team1
&& gTeam
[playerid
] == TEAM_TWO
)//if team2 has more players than team1 and the player is trying to spawn as TEAM_TWO.. { GameTextForPlayer
(playerid,
"~r~Team Full!~n~~w~Choose Another Team!",
3000,
5);
//Tell them its full, choose another team.. return 0;
//And stop them from spawning.. } return 1;
}//Bang, you now have a team balancer.//Enjoy,//-------------------------------[End OF Tutorial]----------------------------////Tutorial by Weponz Inc. © 2010 - 2011
i have these in my script:
for teams;:
//Teams
#define NAME_TEAM_0 "Not Selected team"
#define NAME_TEAM_1 "Grove"
#define NAME_TEAM_2 "Ballas"
#define NAME_TEAM_3 "Vagos"
#define NAME_TEAM_4 "Aztecas"
i check if player is in a team id like this: if(PlayerTeam[playerid] == x)
So now after i added this balancer, it lets me spawn in any team, and then when someone else want to spawn, it always says this team is full. it says same to all teams even where are 0 players in it.
0 errors and 0 warnings, compiles fine but doesnt work as it should
anyone can help fix it?
Re: [HELP] Team Balancer problem -
VIP475 - 24.06.2013
players cant spawn at all if one player spawns , it says teams are full