A loop is blocking my code.
#1

pawn Код:
public OnPlayerSpawn(playerid);
{
        TerrorsCounter=0;
        CopsCounter=0;
    if(Account[playerid][gTeam]==Cops)
    {
        print("Debug : Cops Random spawn called.");
        new Random = random(sizeof(RandomSpawnsCops));
        SetPlayerPos(playerid, RandomSpawnsCops[Random][0], RandomSpawnsCops[Random][1], RandomSpawnsCops[Random][2]);
        SetPlayerFacingAngle(playerid, RandomSpawnsCops[Random][3]);
        return 1;
    }
    else if(Account[playerid][gTeam]==Terrorists)
    {
        print("Debug : Teorrists Random spawn called.");
        new Random = random(sizeof(RandomSpawnsTerrorists));
        SetPlayerPos(playerid, RandomSpawnsTerrorists[Random][0], RandomSpawnsTerrorists[Random][1], RandomSpawnsTerrorists[Random][2]);
        SetPlayerFacingAngle(playerid, RandomSpawnsTerrorists[Random][3]);
        return 1;
    }
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(Account[i][gTeam]==Terrorists) return TerrorsCounter++;
        else if(Account[i][gTeam]==Cops) return CopsCounter++;
    }
    return 1;
}
Now this loop is my problem , if i put it on the top of the callback the loop gets called but the rest of the callback is not called if i put the loop at the bottom of my callback it doesn't get called also tried adding and removing return 1; but still
Any help please?
Reply
#2

pawn Код:
public OnPlayerSpawn(playerid);
{
    if(Account[playerid][gTeam]==Cops)
    {
        print("Debug : Cops Random spawn called.");
        new Random = random(sizeof(RandomSpawnsCops));
        SetPlayerPos(playerid, RandomSpawnsCops[Random][0], RandomSpawnsCops[Random][1], RandomSpawnsCops[Random][2]);
        SetPlayerFacingAngle(playerid, RandomSpawnsCops[Random][3]);
        return 1;
    }
    else if(Account[playerid][gTeam]==Terrorists)
    {
        print("Debug : Teorrists Random spawn called.");
        new Random = random(sizeof(RandomSpawnsTerrorists));
        SetPlayerPos(playerid, RandomSpawnsTerrorists[Random][0], RandomSpawnsTerrorists[Random][1], RandomSpawnsTerrorists[Random][2]);
        SetPlayerFacingAngle(playerid, RandomSpawnsTerrorists[Random][3]);
        return 1;
    }
    return1;
}
If this do not work show us your RandomSpawnsTerrorists and RandomSpawnsCops code
Reply
#3

Sir where did the loop go? :O
Reply
#4

You are probably going out of bounds with "Account"
That's what normally happens to me in these situations.. is it something like

pawn Код:
new Account[MAX_PLAYERS]...
?
Reply
#5

Erm no sir , that's an enum
and my script wouldn't have compiled.
and crash detect plugin would have printed out of bounds error.
pawn Код:
new Account[MAX_PLAYERS][PlayerData];
Reply
#6

Here goes, by the way, this is not the right way to count how many players has a team, you should increase it on onplayerrequestclass and remove it on onplayerdisconnect instead of make this loop inside this callback.
pawn Код:
public OnPlayerSpawn(playerid);
{
    if(Account[playerid][gTeam]==Cops)
    {
        print("Debug : Cops Random spawn called.");
        new Random = random(sizeof(RandomSpawnsCops));
        SetPlayerPos(playerid, RandomSpawnsCops[Random][0], RandomSpawnsCops[Random][1], RandomSpawnsCops[Random][2]);
        SetPlayerFacingAngle(playerid, RandomSpawnsCops[Random][3]);
    }
    else if(Account[playerid][gTeam]==Terrorists)
    {
        print("Debug : Teorrists Random spawn called.");
        new Random = random(sizeof(RandomSpawnsTerrorists));
        SetPlayerPos(playerid, RandomSpawnsTerrorists[Random][0], RandomSpawnsTerrorists[Random][1], RandomSpawnsTerrorists[Random][2]);
        SetPlayerFacingAngle(playerid, RandomSpawnsTerrorists[Random][3]);
    }
    static i = 0,u = MAX_PLAYERS;
    for(; i < u; ++i)
    {
        if(Account[i][gTeam]==Terrorists) TerrorsCounter++;
        else if(Account[i][gTeam]==Cops) CopsCounter++;
    }
    return 1;
}
Reply
#7

Yes sir i know and my balancer works like u just said but problem is i have a spectate command on a filter script so reseting variables would be the best choice since i can't access the fs pwn file
anyways, can you please explain to me how the loop will get executed?

EDIT : Still , the loop didn't get executed :/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)