Would this work?
#1

I need anybody to tell me if this script will work or have any bug..
pawn Код:
new JAPCount, USACount;

public OnPlayerRequestSpawn(playerid)
{
    if (LoggedIn[playerid] == 0) return SendClientMessage(playerid,COLOR_RED,"ERROR: You must log in before playing !");
    if (PlayerTeam[playerid] == TEAM_JAPFLEET)
    {
        if (JAPCount > USACount) return SendClientMessage(playerid,COLOR_RED,"INFO: This team is full. Join another team");
        JAPCount++;
    }
    if (PlayerTeam[playerid] == TEAM_AIRFORCE)
    {
        if (USACount > JAPCount) return SendClientMessage(playerid,COLOR_RED,"INFO: This team is full. Join another team");
        USACount++;
    }
}
Sorry to post this kind of post but I dont haqve anybody to test it with.
Reply
#2

One thing that will fail that i noticed is, what if both teams have equal players? The nested ifs will fail.
Reply
#3

Quote:
Originally Posted by iggy1
Посмотреть сообщение
One thing that will fail that i noticed is, what if both teams have equal players? The nested ifs will fail.
well.. you got a fix? Like
pawn Код:
if (USACount == JAPCount) return 1;
Or anything?
Reply
#4

pawn Код:
public OnPlayerRequestSpawn(playerid)
{
    if(JAPCount == USACount)
    {
        new randteam = random(2);//this is assumming the team ids are 0 and 1
        switch(randteam)
        {
            case TEAM_JAPFLEET:
            {
                JAPCount++;
                return 1;
            }
            case TEAM_AIRFORCE:
            {
                USACount++;
                return 1;
            }
        }
    }
    if (LoggedIn[playerid] == 0) return SendClientMessage(playerid,COLOR_RED,"ERROR: You must log in before playing !");
    if (PlayerTeam[playerid] == TEAM_JAPFLEET)
    {
        if (JAPCount > USACount) return SendClientMessage(playerid,COLOR_RED,"INFO: This team is full. Join another team");
        JAPCount++;
    }
    if (PlayerTeam[playerid] == TEAM_AIRFORCE)
    {
        if (USACount > JAPCount) return SendClientMessage(playerid,COLOR_RED,"INFO: This team is full. Join another team");
        USACount++;
    }
}
There might be better ways but thats what i'd do.
Reply
#5

Quote:
Originally Posted by admantis
Посмотреть сообщение
I need anybody to tell me if this script will work or have any bug..
pawn Код:
new JAPCount, USACount;

public OnPlayerRequestSpawn(playerid)
{
    if (LoggedIn[playerid] == 0) return SendClientMessage(playerid,COLOR_RED,"ERROR: You must log in before playing !");
    if (PlayerTeam[playerid] == TEAM_JAPFLEET)
    {
        if (JAPCount > USACount) return SendClientMessage(playerid,COLOR_RED,"INFO: This team is full. Join another team");
        JAPCount++;
    }
    if (PlayerTeam[playerid] == TEAM_AIRFORCE)
    {
        if (USACount > JAPCount) return SendClientMessage(playerid,COLOR_RED,"INFO: This team is full. Join another team");
        USACount++;
    }
}
Sorry to post this kind of post but I dont haqve anybody to test it with.
Should work fine.
Reply
#6

Quote:
Originally Posted by iggy1
Посмотреть сообщение
pawn Код:
public OnPlayerRequestSpawn(playerid)
{
    if(JAPCount == USACount)
    {
        new randteam = random(2);//this is assumming the team ids are 0 and 1
        switch(randteam)
        {
            case TEAM_JAPFLEET:
            {
                JAPCount++;
                return 1;
            }
            case TEAM_AIRFORCE:
            {
                USACount++;
                return 1;
            }
        }
    }
    if (LoggedIn[playerid] == 0) return SendClientMessage(playerid,COLOR_RED,"ERROR: You must log in before playing !");
    if (PlayerTeam[playerid] == TEAM_JAPFLEET)
    {
        if (JAPCount > USACount) return SendClientMessage(playerid,COLOR_RED,"INFO: This team is full. Join another team");
        JAPCount++;
    }
    if (PlayerTeam[playerid] == TEAM_AIRFORCE)
    {
        if (USACount > JAPCount) return SendClientMessage(playerid,COLOR_RED,"INFO: This team is full. Join another team");
        USACount++;
    }
}
There might be better ways but thats what i'd do.
Will that just add one to USACount or JAPCount as debug or assign a random team to the player? Because I don't see it assigns a team spawn player or anything like that.

@Mademan: iggy1 said it will be bugged if there are equal count for both teams
Reply
#7

No i never put them in a team i was using the op's code, i thought that was strange myself...

It would be bugged because neither nested ifs will be true or false if they are even.
Reply
#8

Quote:
Originally Posted by admantis
Посмотреть сообщение
@Mademan: iggy1 said it will be bugged if there are equal count for both teams
How?
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)