Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*==============================================================================
- | Spectate System For Players |
- | By RandomDude |
- |==============================================================================*/
- #include <a_samp>
- #include <zcmd>
- #include <sscanf2>
- #include <foreach>
- #if defined FILTERSCRIPT
- #endif
- #undef MAX_PLAYERS
- #define MAX_PLAYERS 32 //Change this line to how many players can get into your server etc 0/200 it would be 200... So you would change 32 to 200 :)
- #define Grey 0xC0C0C0FF
- new String[128], Float:SpecX[MAX_PLAYERS], Float:SpecY[MAX_PLAYERS], Float:SpecZ[MAX_PLAYERS], vWorld[MAX_PLAYERS], Inter[MAX_PLAYERS];
- new IsSpecing[MAX_PLAYERS], Name[MAX_PLAYER_NAME], IsBeingSpeced[MAX_PLAYERS],spectatorid[MAX_PLAYERS];
- CMD:spec(playerid, params[])
- {
- new id;
- if(sscanf(params,"u", id))return SendClientMessage(playerid, Grey, "Usage: /spec [id]");
- if(id == playerid)return SendClientMessage(playerid,Grey,"You cannot spec yourself.");
- if(id == INVALID_PLAYER_ID)return SendClientMessage(playerid, Grey, "Player not found!");
- if(IsSpecing[playerid] == 1)return SendClientMessage(playerid,Grey,"You are already specing someone.");
- GetPlayerPos(playerid,SpecX[playerid],SpecY[playerid],SpecZ[playerid]);
- Inter[playerid] = GetPlayerInterior(playerid);
- vWorld[playerid] = GetPlayerVirtualWorld(playerid);
- TogglePlayerSpectating(playerid, true);
- if(IsPlayerInAnyVehicle(id))
- {
- if(GetPlayerInterior(id) > 0)
- {
- SetPlayerInterior(playerid,GetPlayerInterior(id));
- }
- if(GetPlayerVirtualWorld(id) > 0)
- {
- SetPlayerVirtualWorld(playerid,GetPlayerVirtualWorld(id));
- }
- PlayerSpectateVehicle(playerid,GetPlayerVehicleID(id));
- }
- else
- {
- if(GetPlayerInterior(id) > 0)
- {
- SetPlayerInterior(playerid,GetPlayerInterior(id));
- }
- if(GetPlayerVirtualWorld(id) > 0)
- {
- SetPlayerVirtualWorld(playerid,GetPlayerVirtualWorld(id));
- }
- PlayerSpectatePlayer(playerid,id);
- }
- GetPlayerName(id, Name, sizeof(Name));
- format(String, sizeof(String),"You have started to spectate %s.",Name);
- SendClientMessage(playerid,0x0080C0FF,String);
- IsSpecing[playerid] = 1;
- IsBeingSpeced[id] = 1;
- spectatorid[playerid] = id;
- return 1;
- }
- CMD:specoff(playerid, params[])
- {
- if(IsSpecing[playerid] == 0)return SendClientMessage(playerid,Grey,"You are not spectating anyone.");
- TogglePlayerSpectating(playerid, 0);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(IsBeingSpeced[playerid] == 1)
- {
- foreach (new i : Player)
- {
- if(spectatorid[i] == playerid)
- {
- TogglePlayerSpectating(i,false);
- }
- }
- }
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- if(IsBeingSpeced[playerid] == 1)
- {
- foreach (new i : Player)
- {
- if(spectatorid[i] == playerid)
- {
- TogglePlayerSpectating(i,false);
- }
- }
- }
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
- {
- if(IsBeingSpeced[playerid] == 1)
- {
- foreach (new i : Player)
- {
- if(spectatorid[i] == playerid)
- {
- PlayerSpectateVehicle(i, GetPlayerVehicleID(playerid));
- }
- }
- }
- }
- if(newstate == PLAYER_STATE_ONFOOT)
- {
- if(IsBeingSpeced[playerid] == 1)
- {
- foreach (new i : Player)
- {
- if(spectatorid[i] == playerid)
- {
- PlayerSpectatePlayer(i, playerid);
- }
- }
- }
- }
- return 1;
- }
- public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
- {
- if(IsBeingSpeced[playerid] == 1)
- {
- foreach (new i : Player)
- {
- if(spectatorid[i] == playerid)
- {
- SetPlayerInterior(i,GetPlayerInterior(playerid));
- SetPlayerVirtualWorld(i,GetPlayerVirtualWorld(playerid));
- }
- }
- }
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- if(IsSpecing[playerid] == 1)
- {
- SetPlayerPos(playerid,SpecX[playerid],SpecY[playerid],SpecZ[playerid]);
- SetPlayerInterior(playerid,Inter[playerid]);
- SetPlayerVirtualWorld(playerid,vWorld[playerid]);
- IsSpecing[playerid] = 0;
- IsBeingSpeced[spectatorid[playerid]] = 0;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement