TogglePlayerSpectating

From SA-MP Wiki

Jump to: navigation, search


Description:

Toggle whether a player is in spectator mode or not. While in spectator mode a player can spectate (watch) other players and vehicles. After using this function, either PlayerSpectatePlayer or PlayerSpectateVehicle needs to be used.


Parameters:
(playerid, toggle)
playeridThe ID of the player who should spectate
toggle1 to enable spectating and 0 to disable


Return Values:

  • 1: The function executed successfully.
  • 0: The function failed to execute. The player does not exist.


Image:32px-Circle-style-warning.png

Warning

If the player is not loaded in before setting the spectate status to false, the connection can be closed unexpectedly.


Image:32px-Ambox_warning_orange.png

Notes

  • When spectator mode is disabled, OnPlayerSpawn will automatically be called, if you wish to restore player to state before spectating, you will have to handle that in OnPlayerSpawn. Note also, that player can also go to class selection before if they used F4 during spectate, a player also CAN die in spectate mode due to various glitches.
  • If you need to spawn a player while they are in spectating mode, do use TogglePlayerSpectating and not SpawnPlayer. Otherwise they won't be spawned and instead will show the player flying mid-air


Tip

Image:Light_bulb_icon.png

When a player is in spectate mode their HUD is hidden, making it useful for setting a player's camera without the HUD. Also, objects near the player's camera will be streamed in, making this useful for interpolating cameras.


Example Usage:

public OnPlayerDeath(playerid, killerid, reason)
{
    TogglePlayerSpectating(playerid, 1);
    PlayerSpectatePlayer(playerid, killerid);
    return 1;
}

Related Functions

The following functions may be useful, as they are related to this function in one way or another.

In other languages