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;
}