SA-MP Forums Archive
Help whit save position to use /spec - 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)
+--- Thread: Help whit save position to use /spec (/showthread.php?tid=574972)



Help whit save position to use /spec - Guss - 22.05.2015

Hello, I have this to save the position of the admin when you use /spec, so when you use /specoff as set in the position it was before using /spec.

PHP код:
new 
    
FloatSave_PositionMAX_PLAYERS ][ ], 
    
boolInSpectateMAX_PLAYERS 

OnPlayerConnect
PHP код:
        Save_Positionplayerid ][ ] = 0.0
    
Save_Positionplayerid ][ ] = 0.0
    
Save_Positionplayerid ][ ] = 0.0
    
Save_Positionplayerid ][ ] = 0.0
    
InSpectateplayerid ] = false
OnPlayerSpawn
PHP код:
    if( InSpectateplayerid ] ) 
    { 
        
SetPlayerPosplayeridSave_Positionplayerid ][ ], Save_Positionplayerid ][ ], Save_Positionplayerid ][ ] ); 
           
SetPlayerFacingAngleplayeridSave_Positionplayerid ][ ] ); 
        
InSpectateplayerid ] = false
    } 
/spec
PHP код:
                new SpecID[MAX_PLAYERS]; 
                new 
id
                new 
string[44]; 
                
GetPlayerPosplayeridSave_Positionplayerid ][ ], Save_Positionplayerid ][ ], Save_Positionplayerid ][ ] ); 
                
GetPlayerFacingAngleplayeridSave_Positionplayerid ][ ] ); 
                
InSpectateplayerid } = true
                
TogglePlayerSpectating(playerid1); 
                
SpecID[playerid] = id
                return 
1
/specoff
PHP код:
                TogglePlayerSpectating(playerid0); 
                
SetPlayerPosplayeridSave_Positionplayerid ][ ], Save_Positionplayerid ][ ], Save_Positionplayerid ][ ] ); 
                   return 
1
But when you use /specoff the admin returns to spawn as if he had died, why? What is wrong?


Re: Help whit save position to use /spec - AlonzoTorres - 22.05.2015

Something I noticed...

PHP код:
                new SpecID[MAX_PLAYERS]; 
                new 
id
                new 
string[44]; 
                
GetPlayerPosplayeridSave_Positionplayerid ][ ], Save_Positionplayerid ][ ], Save_Positionplayerid ][ ] ); 
                
GetPlayerFacingAngleplayeridSave_Positionplayerid ][ ] ); 
                
InSpectateplayerid } = true
                
TogglePlayerSpectating(playerid1); 
                
SpecID[playerid] = id
                return 
1

PHP код:
                new SpecID[MAX_PLAYERS]; 
                new 
id
                new 
string[44]; 
                
GetPlayerPosplayeridSave_Positionplayerid ][ ], Save_Positionplayerid ][ ], Save_Positionplayerid ][ ] ); 
                
GetPlayerFacingAngleplayeridSave_Positionplayerid ][ ] ); 
                
InSpectateplayerid ] = true// You put the wrong brackets.
                
TogglePlayerSpectating(playerid1); 
                
SpecID[playerid] = id
                return 
1



Respuesta: Re: Help whit save position to use /spec - Guss - 22.05.2015

Quote:
Originally Posted by AlonzoTorres
Посмотреть сообщение
Something I noticed...

PHP код:
                new SpecID[MAX_PLAYERS]; 
                new 
id
                new 
string[44]; 
                
GetPlayerPosplayeridSave_Positionplayerid ][ ], Save_Positionplayerid ][ ], Save_Positionplayerid ][ ] ); 
                
GetPlayerFacingAngleplayeridSave_Positionplayerid ][ ] ); 
                
InSpectateplayerid } = true
                
TogglePlayerSpectating(playerid1); 
                
SpecID[playerid] = id
                return 
1

PHP код:
                new SpecID[MAX_PLAYERS]; 
                new 
id
                new 
string[44]; 
                
GetPlayerPosplayeridSave_Positionplayerid ][ ], Save_Positionplayerid ][ ], Save_Positionplayerid ][ ] ); 
                
GetPlayerFacingAngleplayeridSave_Positionplayerid ][ ] ); 
                
InSpectateplayerid ] = true// You put the wrong brackets.
                
TogglePlayerSpectating(playerid1); 
                
SpecID[playerid] = id
                return 
1
Still does not work


Re: Help whit save position to use /spec - AlonzoTorres - 22.05.2015

Try using https://sampwiki.blast.hk/wiki/SetSpawnInfo before you detoggle the spectator mode?


Re: Help whit save position to use /spec - SickAttack - 22.05.2015

There's no need to create the same thread in multiple sections.

Please take the following code as a reference. If it doesn't solve your issue, I'm pretty sure it's something else causing it to do that to the player.
pawn Код:
new bool:sSpectating[MAX_PLAYERS] = false,
Float:pSpectatingPos[MAX_PLAYERS][4],
pSpectatingInterior[MAX_PLAYERS],
pSpectatingVirtualWorld[MAX_PLAYERS];


public OnPlayerSpawn(playerid)
{
    if(IsPlayerSpectating(playerid))
    {
        SetPlayerInterior(playerid, pSpectatingInterior[playerid]);
        SetPlayerVirtualWorld(playerid, pSpectatingVirtualWorld[playerid]);
        SetPlayerPos(playerid, pSpectatingPos[playerid][0], pSpectatingPos[playerid][1], pSpectatingPos[playerid][2]);
        SetPlayerFacingAngle(playerid, pSpectatingPos[playerid][3]);
        SetCameraBehindPlayer(playerid);

        sSpectating[playerid] = false;
    }
    return 1;
}

CMD:spec(playerid, params[])
{
    new lookupid;
    if(sscanf(params, "u", lookupid)) return SendClientMessage(playerid, -1, "Usage: /spec (id/name).");
    if(!IsPlayerConnected(lookupid)) return SendClientMessage(playerid, -1, "Player isn't connected to the server.");
    if(IsPlayerNPC(lookupid)) return SendClientMessage(playerid, -1, "You cannot spectate a bot.");
    if(lookupid == playerid) return SendClientMessage(playerid, -1, "You cannot spectate yourself.");
    if(IsPlayerSpectating(lookupid)) return SendClientMessage(playerid, -1, "You cannot spectate a player that's currently spectating.");

    if(!IsPlayerSpectating(playerid))
    {
        GetPlayerPos(playerid, pSpectatingPos[playerid][0], pSpectatingPos[playerid][1], pSpectatingPos[playerid][2]);
        GetPlayerFacingAngle(playerid, pSpectatingPos[playerid][3]);
        pSpectatingInterior[playerid] = GetPlayerInterior(playerid);
        pSpectatingVirtualWorld[playerid] = GetPlayerVirtualWorld(playerid);
    }

    sSpectating[playerid] = true;
    TogglePlayerSpectating(playerid, true);
    if(IsPlayerInAnyVehicle(lookupid))
    {
        //SetPlayerInterior(playerid, GetVehicleInterior(GetPlayerVehicleID(lookupid))); You need to get that function, it can be found in YSF or somewhere else.
        SetPlayerVirtualWorld(playerid, GetVehicleVirtualWorld(GetPlayerVehicleID(lookupid)));
        PlayerSpectateVehicle(playerid, GetPlayerVehicleID(lookupid));
    }
    else
    {
        SetPlayerInterior(playerid, GetPlayerInterior(lookupid));
        SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(lookupid));
        PlayerSpectatePlayer(playerid, lookupid);
    }
    return 1;
}

CMD:specoff(playerid, params[])
{
    if(!IsPlayerSpectating(playerid)) return SendClientMessage(playerid, -1, "** You are not spectating anyone.");

    TogglePlayerSpectating(playerid, false);
    SetPlayerInterior(playerid, 0);
    SetPlayerVirtualWorld(playerid, 0);
    return 1;
}

stock IsPlayerSpectating(playerid)
{
    if(sSpectating[playerid]) return true;
    return false;
}



Respuesta: Help whit save position to use /spec - alexus - 22.05.2015

OnPlayerDeath code perhaps ?


Respuesta: Re: Help whit save position to use /spec - Guss - 22.05.2015

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
There's no need to create the same thread in multiple sections.

Please take the following code as a reference. If it doesn't solve your issue, I'm pretty sure it's something else causing it to do that to the player.
pawn Код:
new bool:sSpectating[MAX_PLAYERS] = false,
Float:pSpectatingPos[MAX_PLAYERS][4],
pSpectatingInterior[MAX_PLAYERS],
pSpectatingVirtualWorld[MAX_PLAYERS];


public OnPlayerSpawn(playerid)
{
    if(IsPlayerSpectating(playerid))
    {
        SetPlayerInterior(playerid, pSpectatingInterior[playerid]);
        SetPlayerVirtualWorld(playerid, pSpectatingVirtualWorld[playerid]);
        SetPlayerPos(playerid, pSpectatingPos[playerid][0], pSpectatingPos[playerid][1], pSpectatingPos[playerid][2]);
        SetPlayerFacingAngle(playerid, pSpectatingPos[playerid][3]);
        SetCameraBehindPlayer(playerid);

        sSpectating[playerid] = false;
    }
    return 1;
}

CMD:spec(playerid, params[])
{
    new lookupid;
    if(sscanf(params, "u", lookupid)) return SendClientMessage(playerid, -1, "Usage: /spec (id/name).");
    if(!IsPlayerConnected(lookupid)) return SendClientMessage(playerid, -1, "Player isn't connected to the server.");
    if(IsPlayerNPC(lookupid)) return SendClientMessage(playerid, -1, "You cannot spectate a bot.");
    if(lookupid == playerid) return SendClientMessage(playerid, -1, "You cannot spectate yourself.");
    if(IsPlayerSpectating(lookupid)) return SendClientMessage(playerid, -1, "You cannot spectate a player that's currently spectating.");

    if(!IsPlayerSpectating(playerid))
    {
        GetPlayerPos(playerid, pSpectatingPos[playerid][0], pSpectatingPos[playerid][1], pSpectatingPos[playerid][2]);
        GetPlayerFacingAngle(playerid, pSpectatingPos[playerid][3]);
        pSpectatingInterior[playerid] = GetPlayerInterior(playerid);
        pSpectatingVirtualWorld[playerid] = GetPlayerVirtualWorld(playerid);
    }

    sSpectating[playerid] = true;
    TogglePlayerSpectating(playerid, true);
    if(IsPlayerInAnyVehicle(lookupid))
    {
        //SetPlayerInterior(playerid, GetVehicleInterior(GetPlayerVehicleID(lookupid))); You need to get that function, it can be found in YSF or somewhere else.
        SetPlayerVirtualWorld(playerid, GetVehicleVirtualWorld(GetPlayerVehicleID(lookupid)));
        PlayerSpectateVehicle(playerid, GetPlayerVehicleID(lookupid));
    }
    else
    {
        SetPlayerInterior(playerid, GetPlayerInterior(lookupid));
        SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(lookupid));
        PlayerSpectatePlayer(playerid, lookupid);
    }
    return 1;
}

CMD:specoff(playerid, params[])
{
    if(!IsPlayerSpectating(playerid)) return SendClientMessage(playerid, -1, "** You are not spectating anyone.");

    TogglePlayerSpectating(playerid, false);
    SetPlayerInterior(playerid, 0);
    SetPlayerVirtualWorld(playerid, 0);
    return 1;
}

stock IsPlayerSpectating(playerid)
{
    if(sSpectating[playerid]) return true;
    return false;
}
I have done so because the spanish section is inactive. I will take the code as a reference if at the end I can't fix this, thanks

Quote:
Originally Posted by alexus
Посмотреть сообщение
OnPlayerDeath code perhaps ?
There is no code in OnPlayerDeath