Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Admin Spec 2.1 by [VLV]Cross
- *
- * Testers: [VLV]Aaron
- * Thanks to SA-MP Team for making "adminspec".
- */
- #pragma tabsize 0
- #include <a_samp>
- #include <core>
- #include <float>
- #define COLOR_GREY 0xAFAFAFAA
- #define COLOR_GREEN 0x33AA33AA
- #define COLOR_RED 0xAA3333AA
- #define COLOR_YELLOW 0xFFFF00AA
- #define COLOR_WHITE 0xFFFFFFFF
- forward OnPlayerVirtualWorldChange(playerid, newvirtualworldid, oldvirtualworldid);
- // DCMD
- #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
- //------------------------------------------------------------------------------
- #define ADMIN_SPEC_TYPE_NONE 0
- #define ADMIN_SPEC_TYPE_PLAYER 1
- #define ADMIN_SPEC_TYPE_VEHICLE 2
- new CurrentVirtualWorld[MAX_PLAYERS];
- enum pSpec
- {
- SpectateUpdate,
- SpectateID,
- SpectateType,
- };
- new Spec[MAX_PLAYERS][pSpec];
- new spectateupdatetimer;
- //------------------------------------------------------------------------------
- public OnFilterScriptInit()
- {
- spectateupdatetimer = SetTimer("SpectatorUpdate", 1000, 1);
- }
- public OnFilterScriptExit()
- {
- KillTimer(spectateupdatetimer);
- }
- //------------------------------------------------------------------------------
- public OnPlayerConnect(playerid)
- {
- Spec[playerid][SpectateUpdate] = 255;
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- for(new x=0; x<MAX_PLAYERS; x++)
- if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid)
- AdvanceSpectate(x);
- return 1;
- }
- //------------------------------------------------------------------------------
- public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
- {
- for(new x=0; x<MAX_PLAYERS; x++)
- {
- if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid && Spec[x][SpectateType] == ADMIN_SPEC_TYPE_VEHICLE || GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid && Spec[x][SpectateType] == ADMIN_SPEC_TYPE_PLAYER)
- {
- SetPlayerInterior(x,newinteriorid);
- }
- }
- }
- public OnPlayerVirtualWorldChange(playerid, newvirtualworldid, oldvirtualworldid)
- {
- for(new x=0; x<MAX_PLAYERS; x++)
- {
- if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid && Spec[x][SpectateType] == ADMIN_SPEC_TYPE_VEHICLE || GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid && Spec[x][SpectateType] == ADMIN_SPEC_TYPE_PLAYER)
- {
- SetPlayerVirtualWorld(x,newvirtualworldid);
- }
- }
- }
- //--------------------[ DCMD ]--------------------------------------------------
- dcmd_spec(playerid,params[])
- {
- new tmp[256], specplayerid, idx;
- tmp = strtok(params, idx);
- if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /spec [playerid]");
- specplayerid = strval(tmp);
- if(specplayerid == playerid) return SendClientMessage(playerid, COLOR_RED, "ERROR: You cannot spectate yourself");
- if(GetPlayerState(specplayerid) != 1 && GetPlayerState(specplayerid) != 2 && GetPlayerState(specplayerid) != 3) return SendClientMessage(playerid, COLOR_RED, "Spectate: Player not spawned");
- if(IsPlayerConnected(specplayerid))
- {
- StartSpectate(playerid, specplayerid);
- return SendClientMessage(playerid,COLOR_GREY,"Now Spectating");
- }
- else return SendClientMessage(playerid, COLOR_RED, "ERROR: that player isn't active.");
- }
- // SPECTATE A VEHICLE
- dcmd_specvehicle(playerid,params[])
- {
- new tmp[256], specvehicleid, idx;
- tmp = strtok(params, idx);
- if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /specvehicle [vehicleid]");
- specvehicleid = strval(tmp);
- if(specvehicleid < MAX_VEHICLES)
- {
- TogglePlayerSpectating(playerid, 1);
- PlayerSpectateVehicle(playerid, specvehicleid);
- Spec[playerid][SpectateID] = specvehicleid;
- SendClientMessage(playerid,COLOR_GREY,"Now Spectating");
- return Spec[playerid][SpectateType] = ADMIN_SPEC_TYPE_VEHICLE;
- } else return SendClientMessage(playerid,COLOR_RED,"ERROR: Invaild vehicle ID.");
- }
- // STOP SPECTATING
- dcmd_specoff(playerid,params[])
- {
- #pragma unused params
- if(Spec[playerid][SpectateType] != ADMIN_SPEC_TYPE_NONE)
- {
- StopSpectate(playerid);
- return SendClientMessage(playerid,COLOR_GREY,"No Longer Spectating");
- }
- else return SendClientMessage(playerid,COLOR_RED,"ERROR: Your not Specing anybody.");
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if(!IsPlayerAdmin(playerid)) return 0;
- // Spec
- dcmd(spec, 4, cmdtext);
- dcmd(specvehicle, 11, cmdtext);
- dcmd(specoff, 7, cmdtext);
- return 0;
- }
- //------------------------------------------------------------------------------
- forward SpectatorUpdate(playerid);
- public SpectatorUpdate(playerid)
- {
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- if(GetPlayerState(i) == PLAYER_STATE_SPECTATING && Spec[i][SpectateType] == ADMIN_SPEC_TYPE_PLAYER || GetPlayerState(i) == PLAYER_STATE_SPECTATING && Spec[i][SpectateType] == ADMIN_SPEC_TYPE_VEHICLE)
- {
- if(IsPlayerConnected(i))
- {
- if(Spec[i][SpectateUpdate] < 253 && Spec[i][SpectateUpdate] != 255)
- {
- new targetid = Spec[i][SpectateUpdate];
- if(IsPlayerConnected(targetid))
- {
- if(IsPlayerAdmin(i))// Change this to whatever your Admin Script is Defined as.
- {
- new string[100], Float:hp, Float:ar;
- GetPlayerName(targetid,string,sizeof(string));
- GetPlayerHealth(targetid, hp); GetPlayerArmour(targetid, ar);
- format(string,sizeof(string),"~n~~n~~n~~n~~n~~n~~n~~n~~w~%s - id:%d~n~(Jump - Sprint)~n~hp:%0.1f ar:%0.1f $%d", string,targetid,hp,ar,GetPlayerMoney(targetid) );
- GameTextForPlayer(i,string,4000,3);
- }
- }
- }
- if(Spec[i][SpectateUpdate] == 253)
- {
- Spec[i][SpectateUpdate] = 255;
- }
- }
- }
- }
- }
- //------------------------------------------------------------------------------
- stock StartSpectate(playerid, specplayerid)
- {
- for(new x=0; x<MAX_PLAYERS; x++)
- {
- if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid)
- {
- AdvanceSpectate(x);
- }
- }
- TogglePlayerSpectating(playerid, 1);
- Spec[playerid][SpectateUpdate] = specplayerid;
- SetPlayerInterior(playerid,GetPlayerInterior(specplayerid));
- SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(specplayerid));
- if(IsPlayerInAnyVehicle(specplayerid))
- {
- PlayerSpectateVehicle(playerid, GetPlayerVehicleID(specplayerid));
- Spec[playerid][SpectateID] = specplayerid;
- Spec[playerid][SpectateType] = ADMIN_SPEC_TYPE_VEHICLE;
- }
- else
- {
- PlayerSpectatePlayer(playerid, specplayerid);
- Spec[playerid][SpectateID] = specplayerid;
- Spec[playerid][SpectateType] = ADMIN_SPEC_TYPE_PLAYER;
- }
- return 1;
- }
- stock StopSpectate(playerid)
- {
- TogglePlayerSpectating(playerid, 0);
- Spec[playerid][SpectateID] = INVALID_PLAYER_ID;
- Spec[playerid][SpectateType] = ADMIN_SPEC_TYPE_NONE;
- Spec[playerid][SpectateUpdate] = 255;
- GameTextForPlayer(playerid,"~n~~n~~n~~w~Spectate mode ended",1000,3);
- return 1;
- }
- stock AdvanceSpectate(playerid)
- {
- if(ConnectedPlayers() == 2) { StopSpectate(playerid); return 1; }
- if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && Spec[playerid][SpectateID] != INVALID_PLAYER_ID)
- {
- for(new x=Spec[playerid][SpectateID]+1; x<=MAX_PLAYERS; x++)
- {
- if(x == MAX_PLAYERS) x = 0;
- if(IsPlayerConnected(x) && x != playerid)
- {
- if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] != INVALID_PLAYER_ID || (GetPlayerState(x) != 1 && GetPlayerState(x) != 2 && GetPlayerState(x) != 3))
- {
- continue;
- }
- else
- {
- StartSpectate(playerid, x);
- break;
- }
- }
- }
- }
- return 1;
- }
- stock ReverseSpectate(playerid)
- {
- if(ConnectedPlayers() == 2) { StopSpectate(playerid); return 1; }
- if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && Spec[playerid][SpectateID] != INVALID_PLAYER_ID)
- {
- for(new x=Spec[playerid][SpectateID]-1; x>=0; x--)
- {
- if(x == 0) x = MAX_PLAYERS;
- if(IsPlayerConnected(x) && x != playerid)
- {
- if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] != INVALID_PLAYER_ID || (GetPlayerState(x) != 1 && GetPlayerState(x) != 2 && GetPlayerState(x) != 3))
- {
- continue;
- }
- else
- {
- StartSpectate(playerid, x);
- break;
- }
- }
- }
- }
- return 1;
- }
- //------------------------------------------------------------------------------
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && Spec[playerid][SpectateID] != INVALID_PLAYER_ID)
- {
- if(newkeys == KEY_JUMP) AdvanceSpectate(playerid);
- else if(newkeys == KEY_SPRINT) ReverseSpectate(playerid);
- }
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- new vehicleid;
- vehicleid = GetPlayerVehicleID(playerid);
- for(new x=0; x<MAX_PLAYERS; x++)
- {
- if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid && Spec[x][SpectateType] == ADMIN_SPEC_TYPE_VEHICLE)
- {
- if(GetPlayerState(playerid) == PLAYER_STATE_NONE)
- {
- StopSpectate(x);
- }
- }
- }
- for(new x=0; x<MAX_PLAYERS; x++)
- {
- if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid && Spec[x][SpectateType] == ADMIN_SPEC_TYPE_VEHICLE)
- {
- if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
- {
- TogglePlayerSpectating(x, 1);
- PlayerSpectatePlayer(x, playerid);
- Spec[x][SpectateType] = ADMIN_SPEC_TYPE_PLAYER;
- }
- }
- }
- for(new x=0; x<MAX_PLAYERS; x++)
- {
- if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid)
- {
- if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
- {
- TogglePlayerSpectating(x, 1);
- PlayerSpectateVehicle(x, vehicleid);
- Spec[x][SpectateType] = ADMIN_SPEC_TYPE_VEHICLE;
- }
- }
- }
- for(new x=0; x<MAX_PLAYERS; x++)
- {
- if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid)
- {
- if(GetPlayerState(playerid) == PLAYER_STATE_WASTED)
- {
- AdvanceSpectate(x);
- }
- }
- }
- return 1;
- }
- //------------------------------------------------------------------------------
- public OnPlayerUpdate(playerid)
- {
- if(!IsPlayerConnected(playerid)) return 0;
- new CurVirtualWorld[MAX_PLAYERS];
- CurVirtualWorld[playerid] = GetPlayerVirtualWorld(playerid);
- if(CurVirtualWorld[playerid] != CurrentVirtualWorld[playerid])
- {
- OnPlayerVirtualWorldChange(playerid, CurVirtualWorld[playerid], CurrentVirtualWorld[playerid]);
- CurrentVirtualWorld[playerid] = CurVirtualWorld[playerid];
- }
- return 1;
- }
- //------------------------------------------------------------------------------
- forward ConnectedPlayers();
- public ConnectedPlayers()
- {
- new Connected;
- for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i)) Connected++;
- return Connected;
- }
- stock strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- stock pName(playerid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, sizeof(name));
- return name;
- }
- //------------------------------------------------------------------------------
- // NOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement