Issues with /spectate command
#4

Quote:
Originally Posted by Undef1ned
View Post
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;

Thank you so much, everything is fixed except for this:

If the admin is in a different world when using /spec, they see blueberry and not the player.
If the world updates whilst someone is spectating, blueberry appears again. Interior updating works fine.

PHP Code:
CMD:spec(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] >= 1)
    {
        new 
targetid;
        if(
GetPlayerState(playerid) == PLAYER_STATE_SPECTATING)
        {
            
TogglePlayerSpectating(playerid0);
            
SetPlayerPos(playerid,SpecX[playerid],SpecY[playerid],SpecZ[playerid]);
            
SetPlayerFacingAngle(playeridSpecR[playerid]);
            
SetPlayerInterior(playeridSpecI[playerid]);
            
SetPlayerVirtualWorld(playeridSpecW[playerid]);
            
IsSpecing[playerid] = 0;
            
IsBeingSpeced[SpecID[playerid]] = 0;
            new 
str[128];
            
format(strsizeof(str), "%s %s(%i) has quit spectating %s(%i)."ReturnAdminLevel(playerid), ReturnICName(playerid), playeridReturnICName(SpecID[playerid]), SpecID[playerid]);
            
ABroadCast(COLOR_SADMINstr1);
            new 
action[20];
            
format(actionsizeof(action), "spec end");
            new 
query[250];
            
mysql_format(g_SQLquerysizeof(query), "INSERT INTO logs_punishments(acc_dbid, acc_name, ip_address, time, action, reason, by_acc_dbid, by_acc_name) VALUES('%i', '%e', '%e', UTC_TIMESTAMP(), '%e', '-1', '%i', '%e')"PlayerInfo[targetid][pDBID], ReturnName(targetid), ReturnIP(targetid), actionPlayerInfo[playerid][pDBID], ReturnName(playerid));
            
mysql_tquery(g_SQLquery);
        }
        else
        {
            if(
sscanf(params"u"targetid))
                return 
SCM(playeridCOLOR_INFO"/spec [name/id](leave blank to quit spectating)");
            if(
targetid == playerid)
                return 
SCM(playeridCOLOR_ERROR"You can not use this command on yourself.");
            if(!
IsPlayerConnected(targetid))
                return 
SCM(playeridCOLOR_ERROR"That account is not connected.");
            if(!
Spawned[targetid])
                return 
SCM(playeridCOLOR_ERROR"That player has not logged in or spawned yet.");
            if(
GetPlayerState(targetid) == PLAYER_STATE_SPECTATING)
                return 
SCMEx(playeridCOLOR_ERROR"%s(%i) is spectating %s(%i) right now. Try again later."ReturnICName(targetid), targetidReturnICName(SpecID[targetid]), SpecID[targetid]);
            
OnPlayerSave(playerid); // saves the player data so that they don't get rollbacked for not being spawned if they quit in spec mode.
            
GetPlayerPos(playerid,SpecX[playerid],SpecY[playerid],SpecZ[playerid]);
            
GetPlayerFacingAngle(playeridSpecR[playerid]);
            
SpecI[playerid] = GetPlayerInterior(playerid);
            
SpecW[playerid] = GetPlayerVirtualWorld(playerid);
            if(
IsPlayerInAnyVehicle(targetid))
            {
                
TogglePlayerSpectating(playerid1);
                
SetPlayerInterior(playeridGetPlayerInterior(targetid));
                
SetPlayerVirtualWorld(playeridGetPlayerVirtualWorld(targetid));
                
PlayerSpectateVehicle(playeridGetPlayerVehicleID(targetid));
            }
            else
            {
                
TogglePlayerSpectating(playerid1);
                
SetPlayerInterior(playeridGetPlayerInterior(targetid));
                
SetPlayerVirtualWorld(playeridGetPlayerVirtualWorld(targetid));
                
PlayerSpectatePlayer(playeridtargetid);
            }
            
IsSpecing[playerid] = 1;
            
IsBeingSpeced[targetid] = 1;
            
SpecID[playerid] = targetid;
            new 
str[128];
            
format(strsizeof(str), "%s %s(%i) is spectating %s(%i)."ReturnAdminLevel(playerid), ReturnICName(playerid), playeridReturnICName(targetid), targetid);
            
ABroadCast(COLOR_SADMINstr1);
            new 
action[20];
            
format(actionsizeof(action), "spec start");
            new 
query[250];
            
mysql_format(g_SQLquerysizeof(query), "INSERT INTO logs_punishments(acc_dbid, acc_name, ip_address, time, action, reason, by_acc_dbid, by_acc_name) VALUES('%i', '%e', '%e', UTC_TIMESTAMP(), '%e', '-1', '%i', '%e')"PlayerInfo[targetid][pDBID], ReturnName(targetid), ReturnIP(targetid), actionPlayerInfo[playerid][pDBID], ReturnName(playerid));
            
mysql_tquery(g_SQLquery);
        }
    }
    else return 
SCM(playerid,COLOR_ERROR,"You do not have the required access to execute this command.");
    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: 1 Guest(s)