Recursion code
#1

All welcome. Recursion The compiler found in the code, need help fixing.

PHP код:
    foreach(new xPlayer)
    {
        if(!
IsPlayerConnected(x)) continue;
        if(
GetPlayerState(x) == PLAYER_STATE_SPECTATING && gSpectateID[x] == playerid)
        {
            
AdvanceSpectate(x);
        }
    } 


The full code

PHP код:
stock StartSpectate(playeridspecid)
{
    
SetPVarInt(playerid,"PlayerSpec",1);
    if(
GetPlayerState(playerid) != PLAYER_STATE_SPECTATING)
    {
        
ShowMenuForPlayer(OdminMeny,playerid);
        
GetPlayerPos(playeridTeleportDest[playerid][0],TeleportDest[playerid][1],TeleportDest[playerid][2]);
        
TeleportDestNoFloat[playerid][0] = GetPlayerInterior(playerid);
        
TeleportDestNoFloat[playerid][1] = GetPlayerVirtualWorld(playerid);
    }
    foreach(new 
xPlayer)
    {
        if(!
IsPlayerConnected(x)) continue;
        if(
GetPlayerState(x) == PLAYER_STATE_SPECTATING && gSpectateID[x] == playerid)
        {
            
AdvanceSpectate(x);
        }
    }
    if(
IsPlayerInAnyVehicle(specid))
    {
        
SetPlayerInterior(playerid,GetPlayerInterior(specid));
        
SetPlayerVirtualWorld(playeridGetPlayerVirtualWorld(specid));
        
TogglePlayerSpectating(playerid1);
        
PlayerSpectateVehicle(playeridGetPlayerVehicleID(specid));
        
gSpectateID[playerid] = specid;
        
gSpectateType[playerid] = ADMIN_SPEC_TYPE_VEHICLE;
    }
    else
    {
        
SetPlayerInterior(playerid,GetPlayerInterior(specid));
        
SetPlayerVirtualWorld(playeridGetPlayerVirtualWorld(specid));
        
TogglePlayerSpectating(playerid1);
        
PlayerSpectatePlayer(playeridspecid);
        
gSpectateID[playerid] = specid;
        
gSpectateType[playerid] = ADMIN_SPEC_TYPE_PLAYER;
    }
    
SpecAd[playerid] = specid;
    
SpecID[specid] = playerid;
    
PlayerTextDrawShow(playeridFULLRECON[playerid]);
    return 
true;

Reply
#2

How should we help you ?

If you compiler found a recursion than AdvanceSpectate is probably calling StartSpectate
Reply
#3

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
How should we help you ?

If you compiler found a recursion than AdvanceSpectate is probably calling StartSpectate
PHP код:
stock AdvanceSpectate(playerid)
{
    if(
ConnectedPlayers() == 2)
    {
        
StopSpectate(playerid);
        return 
true;
    }
    if(
GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && gSpectateID[playerid] != INVALID_PLAYER_ID)
    {
        for(new 
gSpectateID[playerid]+1<= MAX_PLAYERSx++)
        {
            if(
== MAX_PLAYERS)
            {
                
0;
            }
            if(
IsPlayerConnected(x) && != playerid)
            {
                if(
GetPlayerState(x) == PLAYER_STATE_SPECTATING && gSpectateID[x] != INVALID_PLAYER_ID ||
                        (
GetPlayerState(x) != && GetPlayerState(x) != && GetPlayerState(x) != 3))
                {
                    continue;
                }
                else
                {
                    
StartSpectate(playeridx);
                    break;
                }
            }
        }
    }
    return 
true;

Reply
#4

I am still not sure what you actually want, if you simply want to avoid the recursion you can split the StartSpectate function into a Start function and into a SpectateTarget function

pawn Код:
stock StartSpectate(playerid, specid)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING || !SpectateTarget(playerid, specid))
    {
        return false;
    }
    SetPVarInt(playerid,"PlayerSpec",1);
    ShowMenuForPlayer(OdminMeny, playerid);
    GetPlayerPos(playerid, TeleportDest[playerid][0], TeleportDest[playerid][1], TeleportDest[playerid][2]);
    TeleportDestNoFloat[playerid][0] = GetPlayerInterior(playerid);
    TeleportDestNoFloat[playerid][1] = GetPlayerVirtualWorld(playerid);

    foreach(new x: Player)
    {
        if(gSpectateID[x] == playerid)
        {
            AdvanceSpectate(x);
        }
    }
    PlayerTextDrawShow(playerid, FULLRECON[playerid]);
    return true;
}

stock SpectateTarget(playerid, specid)
{
    if(1 <= GetPlayerState(specid) <= 3)
    {
        TogglePlayerSpectating(playerid, 1);
        SetPlayerInterior(playerid,GetPlayerInterior(specid));
        SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(specid));

        if(IsPlayerInAnyVehicle(specid))
        {
            PlayerSpectateVehicle(playerid, GetPlayerVehicleID(specid));
            gSpectateType[playerid] = ADMIN_SPEC_TYPE_VEHICLE;
        }
        else
        {
            PlayerSpectatePlayer(playerid, specid);
            gSpectateType[playerid] = ADMIN_SPEC_TYPE_PLAYER;
        }
        gSpectateID[playerid] = specid;
         // no clue what these two lines \/ does
        SpecAd[playerid] = specid;
        SpecID[specid] = playerid;
        return true;
    }
    return false;
}

stock AdvanceSpectate(playerid)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING)
    {
        for(new x = gSpectateID[playerid] + 1, y = MAX_PLAYERS; y--; x++)
        {
            if(x == MAX_PLAYERS)
            {
                x = 0;
            }
            if(x != playerid && SpectateTarget(playerid, x))
            {
                return true;
            }
        } // Noone found
        StopSpectate(playerid);
    }
    return false;
}
Reply
#5

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
I am still not sure what you actually want, if you simply want to avoid the recursion you can split the StartSpectate function into a Start function and into a SpectateTarget function

pawn Код:
stock StartSpectate(playerid, specid)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING || !SpectateTarget(playerid, specid))
    {
        return false;
    }
    SetPVarInt(playerid,"PlayerSpec",1);
    ShowMenuForPlayer(OdminMeny, playerid);
    GetPlayerPos(playerid, TeleportDest[playerid][0], TeleportDest[playerid][1], TeleportDest[playerid][2]);
    TeleportDestNoFloat[playerid][0] = GetPlayerInterior(playerid);
    TeleportDestNoFloat[playerid][1] = GetPlayerVirtualWorld(playerid);

    foreach(new x: Player)
    {
        if(gSpectateID[x] == playerid)
        {
            AdvanceSpectate(x);
        }
    }
    PlayerTextDrawShow(playerid, FULLRECON[playerid]);
    return true;
}

stock SpectateTarget(playerid, specid)
{
    if(1 <= GetPlayerState(specid) <= 3)
    {
        TogglePlayerSpectating(playerid, 1);
        SetPlayerInterior(playerid,GetPlayerInterior(specid));
        SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(specid));

        if(IsPlayerInAnyVehicle(specid))
        {
            PlayerSpectateVehicle(playerid, GetPlayerVehicleID(specid));
            gSpectateType[playerid] = ADMIN_SPEC_TYPE_VEHICLE;
        }
        else
        {
            PlayerSpectatePlayer(playerid, specid);
            gSpectateType[playerid] = ADMIN_SPEC_TYPE_PLAYER;
        }
        gSpectateID[playerid] = specid;
         // no clue what these two lines \/ does
        SpecAd[playerid] = specid;
        SpecID[specid] = playerid;
        return true;
    }
    return false;
}

stock AdvanceSpectate(playerid)
{
    if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING)
    {
        for(new x = gSpectateID[playerid] + 1, y = MAX_PLAYERS; y--; x++)
        {
            if(x == MAX_PLAYERS)
            {
                x = 0;
            }
            if(x != playerid && SpectateTarget(playerid, x))
            {
                return true;
            }
        } // Noone found
        StopSpectate(playerid);
    }
    return false;
}
Thanks Closed theme.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)