team balance issue
#1

hi,

i have this team balance but its bugged.

pawn Код:
public OnPlayerRequestSpawn(playerid)
{


CountPolice = 0;
CountTerrorists = 0;

//print1
new stringg[128];
format(stringg,sizeof(stringg),"   police: %d      terrorist: %d",CountPolice,CountTerrorists);
SendClientMessage(playerid, 0xE100E1FF, stringg);


    foreach (Player, i)
    {
        if(gTeam[i] == TEAM_POLICE)
        {
            CountPolice++;
        }
        if(gTeam[i] == TEAM_TERRORISTS)
        {
            CountTerrorists++;
        }
    }

//print2
new stringg[128];
format(stringg,sizeof(stringg),"   police: %d      terrorist: %d",CountPolice,CountTerrorists);
SendClientMessage(playerid, 0xE100E1FF, stringg);



        if(gTeam[playerid] == TEAM_POLICE && CountPolice > CountTerrorists)
        {
            SendClientMessage(playerid, 0xE100E1FF, "join other team");
            GameTextForPlayer(playerid, "full!", 2000, 5);
            return 0;
        }
        if(gTeam[playerid] == TEAM_TERRORISTS && CountPolice < CountTerrorists)
        {
            SendClientMessage(playerid, 0xE100E1FF, "join other team");
            GameTextForPlayer(playerid, "full!", 2000, 5);
            return 0;
        }

return 1;
}
The looping and counting of the team members works but not the if statement.
print1 shows team police = 0 and team terror = 0. thats right cause it is resettet before a new looping begins as u can see in the code.
prin2 shows the right team count as well this time with the looping count.
if print2 shows e.g. 0:1 it doesnt let me spawn on both teams. always writing its full on both teams why?
The looping works as the print shows but not the if statements...

i hope u can help me.
Reply
#2

change some things and instead of onplayerequestspawn use this in onplayerrequestclass
sorry for no capitals i am on phone.
Reply
#3

thx but

what things shall i change?

also if i use this under on playerrequestclass they can still spawn if the team is full.

the main problem is the if statement.
Altought the variables are unequal it wont let me spawn on both teams!

please help
Reply
#4

what if you replace the last 2 if statements with this:
pawn Код:
if(gTeam[playerid] == TEAM_POLICE)
        {
            if(CountPolice <= CountTerrorists)
            {
                SendClientMessage(playerid, 0xE100E1FF, "Have fun");
                GameTextForPlayer(playerid, "Have fun", 2000, 5);
                return 1;
            }
            else
            {
                SendClientMessage(playerid, 0xE100E1FF, "join other team");
                GameTextForPlayer(playerid, "full!", 2000, 5);
                return 0;
            }
        }
        else
        if(gTeam[playerid] == TEAM_TERRORISTS)
        {
            if(CountTerrorists <= CountPolice)
            {
                SendClientMessage(playerid, 0xE100E1FF, "Have fun");
                GameTextForPlayer(playerid, "Have fun", 2000, 5);
                return 1;
            }
            else
            {
                SendClientMessage(playerid, 0xE100E1FF, "join other team");
                GameTextForPlayer(playerid, "full!", 2000, 5);
                return 0;
            }
        }
?
Reply
#5

You can set that if classid== whatever and then disable that player for spawn like it happens in protect the president.
If you can't do it pm me I will reply as soon I am on computer.
Reply
#6

@gamer_z: mhhh, still the same problem i cant spawn on both teams (it says both teams are full)

any ideas?
this very confused

the variables that are compared are right but somehow the comparing sucks
Reply
#7

Change:
pawn Код:
if(CountPolice <= CountTerrorists)
if(CountTerrorists <= CountPolice)
To:
pawn Код:
if(CountPolice < CountTerrorists)
if(CountTerrorists < CountPolice)
At the moment, you're saying if both teams have the same number... nobody can join them. Which is useless, because when a player join, both teams have 0 players, therefore cancelling each other out and not allowing the player to choose a team. <= (Less or Equal to) < (Less than)

EDIT: Wait no wtf am I saying... sorry, I have really got to start reading these properly...
Reply
#8

i did, this is the code i currently have:

pawn Код:
//OnPlayerRequestSpawn

CountPolice = 0;
CountTerrorists = 0;

    foreach (Player, i)
    {
        if(gTeam[i] == TEAM_POLICE)
        {
            CountPolice++;
        }
        if(gTeam[i] == TEAM_TERRORISTS)
        {
            CountTerrorists++;
        }
    }


        if(gTeam[playerid] == TEAM_POLICE && CountPolice > CountTerrorists)
        {
            SendClientMessage(playerid, 0xE100E1FF, "join other team");
            GameTextForPlayer(playerid, "full!", 2000, 5);
            return 0;
        }
        if(gTeam[playerid] == TEAM_TERRORISTS && CountPolice < CountTerrorists)
        {
            SendClientMessage(playerid, 0xE100E1FF, "join other team");
            GameTextForPlayer(playerid, "full!", 2000, 5);
            return 0;
        }
still the same prob, i cant join no team cause both are full

im getting crazy here guys
i just cant understand.
Reply
#9

pawn Код:
//OnPlayerRequestSpawn

CountPolice = 0; // Remove this
CountTerrorists = 0; // Remove this

    foreach (Player, i)
    {
        if(gTeam[i] == TEAM_POLICE)
        {
            CountPolice++;
        }
        if(gTeam[i] == TEAM_TERRORISTS)
        {
            CountTerrorists++;
        }
    }


        if(gTeam[playerid] == TEAM_POLICE && CountPolice > CountTerrorists)
        {
            SendClientMessage(playerid, 0xE100E1FF, "Join the other team!");
            GameTextForPlayer(playerid, "full!", 2000, 5);
            ForceClassSelection(playerid);
            return 0;
        }
        if(gTeam[playerid] == TEAM_TERRORISTS && CountPolice < CountTerrorists)
        {
            SendClientMessage(playerid, 0xE100E1FF, "Join the other team!");
            GameTextForPlayer(playerid, "full!", 2000, 5);
            ForceClassSelection(playerid);
            return 0;
        }
        if(gTeam[playerid] == TEAM_POLICE && CountPolice == CountTerrorists)
        {
            SendClientMessage(playerid, 0xE100E1FF, "Welcome to the 'Police' team!");
            GameTextForPlayer(playerid, "~b~Police", 2000, 5);
            return 0;
        }
        if(gTeam[playerid] == TEAM_TERRORISTS && CountPolice == CountTerrorists)
        {
            SendClientMessage(playerid, 0xE100E1FF, "Welcome to the 'Terrorists' team!");
            GameTextForPlayer(playerid, "~r~Terrorists", 2000, 5);
            return 0;
        }
Reply
#10

Try this

On top
pawn Код:
new players, cop, terrorist;
pawn Код:
public OnPlayerConnect(playerid)
{
    players++;
    return 1;
}  

public OnPlayerDisconnect(playerid)
{
    players--;
    if(GetPlayerTeam(playerid) == TEAM_COPS)
    {
        cop--;
    }
    else if(GetPlayerTeam(playerid) == TEAM_TERRORISTS)
    {
        terrorist--;
    }
    return 1;
}
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    new _limit = (players/2), bool:limit;
    if(terrorist >= _limit || cop >= _limit)
    {
        limit = true;
    }
    else
    {
        limit = false;
    }
    if(classid == TEAM_COPS && limit == true) return SendClientMessage(playerid, 0xFF0000, "That team is full!");
    else
    {
        cop++;
    }
    if(classid == TEAM_TERRORISTS && limit == true) return SendClientMessage(playerid, 0xFF0000, "That team is full!");
    else
    {
        terrorist++;
    }
    return 1;
}
Always try to use SetPlayerTeam with this
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)