PDA

View Full Version : Team Balancer Problem


TheSimpleGuy
03/05/2016, 01:11 PM
It is a little bit hard to explain, but here we go:
I have created a team balancer that, of course, balances the teams. I have four teams in all.
So, after I start my server, and I am of course prompted to select a team. I will select Team 0 as my team, and use /count. Team 0's count will not increase. If I select another team, for example, Team 1/2/3, its count will increase. I do not understand why. Help me.

UPDATE: tInfo[pInfo[playerid][PreviousTeam]][Count]--; // ======= THIS IS NOW THE PROBLEM LINE, I AM SETTING THE PreviousTeam VARIABLE AS 99 AT ONPLAYERCONNECT BUT IT RETURNS 0!

enum TeamInfo
{
Count
};
new tInfo[][TeamInfo];

public OnGameModeInIt()
{
for(new i = 0; i < 4; i++) return tInfo[i][Count] = 1; // I made it as 1 because the operators at OnPlayerRequestSpawn won't read 0...
}

public OnPlayerRequestClass(playerid, classid)
{
switch(classid)
{
case 0..2: SetPlayerTeam(playerid, 0);
case 3..5: SetPlayerTeam(playerid, 1);
case 6..8: SetPlayerTeam(playerid, 2);
case 9..11: SetPlayerTeam(playerid, 3);
}
GameTextForPlayer(playerid, tInfo[GetPlayerTeam(playerid)][Name], 1000, 5);
SetPlayerColor(playerid, tInfo[GetPlayerTeam(playerid)][Color]);
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572+10, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}

public OnPlayerRequestSpawn(playerid)
{
switch(GetPlayerTeam(playerid))
{
case 0:
{
if(tInfo[0][Count] > tInfo[1][Count] && tInfo[2][Count] && tInfo[3][Count])
{
SendClientMessage(playerid, -1, ""COL_GRAY"This team is full!");
return 0;
}
}
case 1:
{
if(tInfo[1][Count] > tInfo[0][Count] && tInfo[2][Count] && tInfo[3][Count])
{
SendClientMessage(playerid, -1, ""COL_GRAY"This team is full!");
return 0;
}
}
case 2:
{
if(tInfo[2][Count] > tInfo[1][Count] && tInfo[0][Count] && tInfo[3][Count])
{
SendClientMessage(playerid, -1, ""COL_GRAY"This team is full!");
return 0;
}
}
case 3:
{
if(tInfo[3][Count] > tInfo[1][Count] && tInfo[2][Count] && tInfo[0][Count])
{
SendClientMessage(playerid, -1, ""COL_GRAY"This team is full!");
return 0;
}
}
}
tInfo[GetPlayerTeam(playerid)][Count]++;
tInfo[pInfo[playerid][PreviousTeam]][Count]--; // ======= THIS IS NOW THE PROBLEM LINE, I AM SETTING THE PreviousTeam VARIABLE AS 99 AT ONPLAYERCONNECT BUT IT RETURNS 0!
//if(tInfo[pInfo[playerid][PreviousTeam]][Count] < 1) tInfo[pInfo[playerid][PreviousTeam]][Count] = 1;
pInfo[playerid][PreviousTeam] = GetPlayerTeam(playerid);
return 1;
}

CMD:count(playerid, params[])
{
new string[128];
for(new i = 0; i < 4; i++)
{
format(string, sizeof(string), "%s%s:%d",string,tInfo[i][Name],tInfo[i][Count]);
}
SendClientMessage(playerid, -1, string);
return 1;
}

MBilal
03/05/2016, 01:50 PM
Don't understand no need of that loop

for(new i = 0; i < 4; i++) return tInfo[i][Count] = 1; // I made it as 1 because the operators at OnPlayerRequestSpawn won't read 0...

For Example you join server and chose team 1 think no budy in server.
tInfo[GetPlayerTeam(playerid)][Count]++;

tInfo[1][Count]++;
it set team 1 count is 1

But what is saved in this varaible pInfo[playerid][PreviousTeam] ?
if that is equal to 0 that -- that can take it to -ve count.
That mean team 0 going to be in negative count.
tInfo[pInfo[playerid][PreviousTeam]][Count]--;
tInfo[0][Count]--;
and thats why also Team 0 count not increasing.

So try not to use tInfo[pInfo[playerid][PreviousTeam]][Count]--;

use this tInfo[GetPlayerTeam(playerid)][Count]--; when player leave

But when player try to change team then use that tInfo[pInfo[playerid][PreviousTeam]][Count]--;