Advertisement
Guest User

Cross

a guest
Nov 14th, 2009
1,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.77 KB | None | 0 0
  1. /*                  
  2. *            Admin Spec 2.1 by [VLV]Cross
  3. *  
  4. *                Testers: [VLV]Aaron
  5. *     Thanks to SA-MP Team for making "adminspec".
  6. */
  7.  
  8. #pragma tabsize 0
  9. #include <a_samp>
  10. #include <core>
  11. #include <float>
  12.  
  13. #define COLOR_GREY 0xAFAFAFAA
  14. #define COLOR_GREEN 0x33AA33AA
  15. #define COLOR_RED 0xAA3333AA
  16. #define COLOR_YELLOW 0xFFFF00AA
  17. #define COLOR_WHITE 0xFFFFFFFF
  18.  
  19. forward OnPlayerVirtualWorldChange(playerid, newvirtualworldid, oldvirtualworldid);
  20.  
  21. // DCMD
  22. #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
  23.  
  24. //------------------------------------------------------------------------------
  25.  
  26. #define ADMIN_SPEC_TYPE_NONE 0
  27. #define ADMIN_SPEC_TYPE_PLAYER 1
  28. #define ADMIN_SPEC_TYPE_VEHICLE 2
  29.  
  30. new CurrentVirtualWorld[MAX_PLAYERS];
  31.  
  32. enum pSpec
  33. {
  34.     SpectateUpdate,
  35.     SpectateID,
  36.     SpectateType,
  37. };
  38. new Spec[MAX_PLAYERS][pSpec];
  39. new spectateupdatetimer;
  40.  
  41. //------------------------------------------------------------------------------
  42.  
  43. public OnFilterScriptInit()
  44. {
  45.     spectateupdatetimer = SetTimer("SpectatorUpdate", 1000, 1);
  46. }
  47.  
  48. public OnFilterScriptExit()
  49. {
  50.     KillTimer(spectateupdatetimer);
  51. }
  52. //------------------------------------------------------------------------------
  53.  
  54. public OnPlayerConnect(playerid)
  55. {
  56.     Spec[playerid][SpectateUpdate] = 255;
  57.     return 1;
  58. }
  59.  
  60. public OnPlayerDisconnect(playerid, reason)
  61. {
  62.     for(new x=0; x<MAX_PLAYERS; x++)
  63.         if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid)
  64.             AdvanceSpectate(x);
  65.     return 1;
  66. }
  67.  
  68. //------------------------------------------------------------------------------
  69.  
  70. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  71. {
  72.     for(new x=0; x<MAX_PLAYERS; x++)
  73.     {
  74.         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)
  75.         {
  76.             SetPlayerInterior(x,newinteriorid);
  77.         }
  78.     }
  79. }
  80.  
  81. public OnPlayerVirtualWorldChange(playerid, newvirtualworldid, oldvirtualworldid)
  82. {
  83.     for(new x=0; x<MAX_PLAYERS; x++)
  84.     {
  85.         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)
  86.         {
  87.             SetPlayerVirtualWorld(x,newvirtualworldid);
  88.         }
  89.     }
  90. }
  91.  
  92. //--------------------[ DCMD ]--------------------------------------------------
  93.  
  94. dcmd_spec(playerid,params[])
  95. {
  96.     new tmp[256], specplayerid, idx;
  97.     tmp = strtok(params, idx);
  98.  
  99.     if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /spec [playerid]");
  100.     specplayerid = strval(tmp);
  101.  
  102.     if(specplayerid == playerid) return SendClientMessage(playerid, COLOR_RED, "ERROR: You cannot spectate yourself");
  103.     if(GetPlayerState(specplayerid) != 1 && GetPlayerState(specplayerid) != 2 && GetPlayerState(specplayerid) != 3) return SendClientMessage(playerid, COLOR_RED, "Spectate: Player not spawned");
  104.     if(IsPlayerConnected(specplayerid))
  105.     {
  106.         StartSpectate(playerid, specplayerid);
  107.         return SendClientMessage(playerid,COLOR_GREY,"Now Spectating");
  108.     }
  109.     else return SendClientMessage(playerid, COLOR_RED, "ERROR: that player isn't active.");
  110. }
  111.  
  112. // SPECTATE A VEHICLE
  113. dcmd_specvehicle(playerid,params[])
  114. {
  115.     new tmp[256], specvehicleid, idx;
  116.     tmp = strtok(params, idx);
  117.  
  118.     if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /specvehicle [vehicleid]");
  119.     specvehicleid = strval(tmp);
  120.  
  121.     if(specvehicleid < MAX_VEHICLES)
  122.     {
  123.         TogglePlayerSpectating(playerid, 1);
  124.         PlayerSpectateVehicle(playerid, specvehicleid);
  125.         Spec[playerid][SpectateID] = specvehicleid;
  126.         SendClientMessage(playerid,COLOR_GREY,"Now Spectating");
  127.         return Spec[playerid][SpectateType] = ADMIN_SPEC_TYPE_VEHICLE;
  128.     } else return SendClientMessage(playerid,COLOR_RED,"ERROR: Invaild vehicle ID.");
  129. }
  130.  
  131. // STOP SPECTATING
  132. dcmd_specoff(playerid,params[])
  133. {
  134.     #pragma unused params
  135.     if(Spec[playerid][SpectateType] != ADMIN_SPEC_TYPE_NONE)
  136.     {
  137.         StopSpectate(playerid);
  138.         return SendClientMessage(playerid,COLOR_GREY,"No Longer Spectating");
  139.     }
  140.     else return SendClientMessage(playerid,COLOR_RED,"ERROR: Your not Specing anybody.");
  141. }
  142.  
  143. public OnPlayerCommandText(playerid, cmdtext[])
  144. {
  145.     if(!IsPlayerAdmin(playerid)) return 0;
  146.    
  147.     // Spec
  148.     dcmd(spec, 4, cmdtext);
  149.     dcmd(specvehicle, 11, cmdtext);
  150.     dcmd(specoff, 7, cmdtext);
  151.     return 0;
  152. }
  153.  
  154. //------------------------------------------------------------------------------
  155.  
  156. forward SpectatorUpdate(playerid);
  157. public SpectatorUpdate(playerid)
  158. {
  159.     for(new i = 0; i < MAX_PLAYERS; i++)
  160.     {
  161.         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)
  162.         {
  163.             if(IsPlayerConnected(i))
  164.             {
  165.                 if(Spec[i][SpectateUpdate] < 253 && Spec[i][SpectateUpdate] != 255)
  166.                 {
  167.                     new targetid = Spec[i][SpectateUpdate];
  168.                     if(IsPlayerConnected(targetid))
  169.                     {
  170.                         if(IsPlayerAdmin(i))// Change this to whatever your Admin Script is Defined as.
  171.                         {
  172.                             new string[100], Float:hp, Float:ar;
  173.                             GetPlayerName(targetid,string,sizeof(string));
  174.                             GetPlayerHealth(targetid, hp);  GetPlayerArmour(targetid, ar);
  175.                             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) );
  176.                             GameTextForPlayer(i,string,4000,3);
  177.                         }
  178.                     }
  179.                 }
  180.                 if(Spec[i][SpectateUpdate] == 253)
  181.                 {
  182.                     Spec[i][SpectateUpdate] = 255;
  183.                 }
  184.             }
  185.         }
  186.     }
  187. }
  188.  
  189. //------------------------------------------------------------------------------
  190.  
  191. stock StartSpectate(playerid, specplayerid)
  192. {
  193.     for(new x=0; x<MAX_PLAYERS; x++)
  194.     {
  195.         if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid)
  196.         {
  197.            AdvanceSpectate(x);
  198.         }
  199.     }
  200.     TogglePlayerSpectating(playerid, 1);
  201.     Spec[playerid][SpectateUpdate] = specplayerid;
  202.     SetPlayerInterior(playerid,GetPlayerInterior(specplayerid));
  203.     SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(specplayerid));
  204.     if(IsPlayerInAnyVehicle(specplayerid))
  205.     {
  206.         PlayerSpectateVehicle(playerid, GetPlayerVehicleID(specplayerid));
  207.         Spec[playerid][SpectateID] = specplayerid;
  208.         Spec[playerid][SpectateType] = ADMIN_SPEC_TYPE_VEHICLE;
  209.     }
  210.     else
  211.     {
  212.         PlayerSpectatePlayer(playerid, specplayerid);
  213.         Spec[playerid][SpectateID] = specplayerid;
  214.         Spec[playerid][SpectateType] = ADMIN_SPEC_TYPE_PLAYER;
  215.     }
  216.     return 1;
  217. }
  218.  
  219. stock StopSpectate(playerid)
  220. {
  221.     TogglePlayerSpectating(playerid, 0);
  222.     Spec[playerid][SpectateID] = INVALID_PLAYER_ID;
  223.     Spec[playerid][SpectateType] = ADMIN_SPEC_TYPE_NONE;
  224.     Spec[playerid][SpectateUpdate] = 255;
  225.     GameTextForPlayer(playerid,"~n~~n~~n~~w~Spectate mode ended",1000,3);
  226.     return 1;
  227. }
  228.  
  229. stock AdvanceSpectate(playerid)
  230. {
  231.     if(ConnectedPlayers() == 2) { StopSpectate(playerid); return 1; }
  232.     if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && Spec[playerid][SpectateID] != INVALID_PLAYER_ID)
  233.     {
  234.         for(new x=Spec[playerid][SpectateID]+1; x<=MAX_PLAYERS; x++)
  235.         {
  236.             if(x == MAX_PLAYERS) x = 0;
  237.             if(IsPlayerConnected(x) && x != playerid)
  238.             {
  239.                 if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] != INVALID_PLAYER_ID || (GetPlayerState(x) != 1 && GetPlayerState(x) != 2 && GetPlayerState(x) != 3))
  240.                 {
  241.                     continue;
  242.                 }
  243.                 else
  244.                 {
  245.                     StartSpectate(playerid, x);
  246.                     break;
  247.                 }
  248.             }
  249.         }
  250.     }
  251.     return 1;
  252. }
  253.  
  254. stock ReverseSpectate(playerid)
  255. {
  256.     if(ConnectedPlayers() == 2) { StopSpectate(playerid); return 1; }
  257.     if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && Spec[playerid][SpectateID] != INVALID_PLAYER_ID)
  258.     {
  259.         for(new x=Spec[playerid][SpectateID]-1; x>=0; x--)
  260.         {
  261.             if(x == 0) x = MAX_PLAYERS;
  262.             if(IsPlayerConnected(x) && x != playerid)
  263.             {
  264.                 if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] != INVALID_PLAYER_ID || (GetPlayerState(x) != 1 && GetPlayerState(x) != 2 && GetPlayerState(x) != 3))
  265.                 {
  266.                     continue;
  267.                 }
  268.                 else
  269.                 {
  270.                     StartSpectate(playerid, x);
  271.                     break;
  272.                 }
  273.             }
  274.         }
  275.     }
  276.     return 1;
  277. }
  278.  
  279. //------------------------------------------------------------------------------
  280.  
  281. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  282. {
  283.    
  284.     if(GetPlayerState(playerid) == PLAYER_STATE_SPECTATING && Spec[playerid][SpectateID] != INVALID_PLAYER_ID)
  285.     {
  286.         if(newkeys == KEY_JUMP) AdvanceSpectate(playerid);
  287.         else if(newkeys == KEY_SPRINT) ReverseSpectate(playerid);
  288.     }
  289.     return 1;
  290. }
  291.  
  292. public OnPlayerStateChange(playerid, newstate, oldstate)
  293. {
  294.     new vehicleid;
  295.     vehicleid = GetPlayerVehicleID(playerid);
  296.     for(new x=0; x<MAX_PLAYERS; x++)
  297.     {
  298.         if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid && Spec[x][SpectateType] == ADMIN_SPEC_TYPE_VEHICLE)
  299.         {
  300.             if(GetPlayerState(playerid) == PLAYER_STATE_NONE)
  301.             {
  302.                 StopSpectate(x);
  303.             }
  304.         }
  305.     }
  306.  
  307.     for(new x=0; x<MAX_PLAYERS; x++)
  308.     {
  309.         if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid && Spec[x][SpectateType] == ADMIN_SPEC_TYPE_VEHICLE)
  310.         {
  311.             if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
  312.             {
  313.                 TogglePlayerSpectating(x, 1);
  314.                 PlayerSpectatePlayer(x, playerid);
  315.                 Spec[x][SpectateType] = ADMIN_SPEC_TYPE_PLAYER;
  316.             }
  317.         }
  318.     }
  319.  
  320.     for(new x=0; x<MAX_PLAYERS; x++)
  321.     {
  322.         if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid)
  323.         {
  324.             if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
  325.             {
  326.                 TogglePlayerSpectating(x, 1);
  327.                 PlayerSpectateVehicle(x, vehicleid);
  328.                 Spec[x][SpectateType] = ADMIN_SPEC_TYPE_VEHICLE;
  329.             }
  330.         }
  331.     }
  332.  
  333.     for(new x=0; x<MAX_PLAYERS; x++)
  334.     {
  335.         if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && Spec[x][SpectateID] == playerid)
  336.         {
  337.             if(GetPlayerState(playerid) == PLAYER_STATE_WASTED)
  338.             {
  339.                 AdvanceSpectate(x);
  340.             }
  341.         }
  342.     }
  343.     return 1;
  344. }
  345.  
  346. //------------------------------------------------------------------------------
  347.  
  348. public OnPlayerUpdate(playerid)
  349. {
  350.     if(!IsPlayerConnected(playerid)) return 0;
  351.  
  352.     new CurVirtualWorld[MAX_PLAYERS];
  353.     CurVirtualWorld[playerid] = GetPlayerVirtualWorld(playerid);
  354.     if(CurVirtualWorld[playerid] != CurrentVirtualWorld[playerid])
  355.     {
  356.         OnPlayerVirtualWorldChange(playerid, CurVirtualWorld[playerid], CurrentVirtualWorld[playerid]);
  357.         CurrentVirtualWorld[playerid] = CurVirtualWorld[playerid];
  358.     }
  359.     return 1;
  360. }
  361.  
  362. //------------------------------------------------------------------------------
  363.  
  364. forward ConnectedPlayers();
  365. public ConnectedPlayers()
  366. {
  367.     new Connected;
  368.     for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i)) Connected++;
  369.     return Connected;
  370. }
  371.  
  372. stock strtok(const string[], &index)
  373. {
  374.     new length = strlen(string);
  375.     while ((index < length) && (string[index] <= ' '))
  376.     {
  377.         index++;
  378.     }
  379.  
  380.     new offset = index;
  381.     new result[20];
  382.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  383.     {
  384.         result[index - offset] = string[index];
  385.         index++;
  386.     }
  387.     result[index - offset] = EOS;
  388.     return result;
  389. }
  390.  
  391. stock pName(playerid)
  392. {
  393.   new name[MAX_PLAYER_NAME];
  394.   GetPlayerName(playerid, name, sizeof(name));
  395.   return name;
  396. }
  397.  
  398. //------------------------------------------------------------------------------
  399. // NOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement