SA-MP Forums Archive
Would this work? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Would this work? (/showthread.php?tid=203702)



Would this work? - admantis - 27.12.2010

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.


Re: Would this work? - iggy1 - 27.12.2010

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


Re: Would this work? - admantis - 27.12.2010

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?


Re: Would this work? - iggy1 - 27.12.2010

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.


Re: Would this work? - MadeMan - 27.12.2010

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.


Re: Would this work? - admantis - 27.12.2010

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


Re: Would this work? - iggy1 - 27.12.2010

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.


Re: Would this work? - MadeMan - 27.12.2010

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