Issues with /spectate command
#3

Test it.

By the way, in the 'foreach' you must verify if all the 'id' traversed are in 'spectator' mode (variable 'IsSpecing' enabled). Another thing, when using 'foreach' it is not necessary to check if the player is connected or disconnected.

PHP Code:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        if(
IsBeingSpeced[playerid] == 1)
        {
            foreach(new 
i:Player)
            {
                if(
IsSpecing[i] != 1) continue; //All those who do not have the variable 'IsSpecing' enabled
                
if(SpecID[i] != playerid) continue;
                
SetPlayerVirtualWorld(iGetPlayerVirtualWorld(playerid));
                
PlayerSpectateVehicle(iGetPlayerVehicleID(playerid));
            }
        }
    }
    
    if(
oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
    {
        if(
IsBeingSpeced[playerid] == 1)
        {
            foreach(new 
i:Player)
            {
                if(
IsSpecing[i] != 1) continue; //All those who do not have the variable 'IsSpecing' enabled
                
if(SpecID[i] != playerid) continue;
                
SetPlayerVirtualWorld(iGetPlayerVirtualWorld(playerid));
                
PlayerSpectatePlayer(iplayerid);
            }
        }
    }
    return 
1;

PHP Code:
public OnPlayerInteriorChange(playeridnewinterioridoldinteriorid)
{
    if(
IsBeingSpeced[playerid] == 1)
    {
        foreach(new 
i:Player)
        {
            if(
IsSpecing[i] != 1) continue; //All those who do not have the variable 'IsSpecing' enabled
            
if(SpecID[i] != playerid) continue;
            
SetPlayerInterior(iGetPlayerInterior(playerid));
            
SetPlayerVirtualWorld(iGetPlayerVirtualWorld(playerid));
            if(
IsPlayerInAnyVehicle(playerid)) PlayerSpectateVehicle(iGetPlayerVehicleID(playerid));
            else 
PlayerSpectatePlayer(iplayerid);
        }
    }
    return 
1;

Reply


Messages In This Thread
Issues with /spectate command - by Stefhan - 16.01.2019, 21:37
Re: Issues with /spectate command - by Stefhan - 17.01.2019, 12:56
Re: Issues with /spectate command - by Undef1ned - 17.01.2019, 15:26
Re: Issues with /spectate command - by Stefhan - 17.01.2019, 16:38
Re: Issues with /spectate command - by Undef1ned - 17.01.2019, 19:57
Re: Issues with /spectate command - by Stefhan - 17.01.2019, 20:17
Re: Issues with /spectate command - by Undef1ned - 18.01.2019, 00:40
Re: Issues with /spectate command - by Stefhan - 19.01.2019, 17:17

Forum Jump:


Users browsing this thread: 2 Guest(s)