Advertisement
Guest User

Spikes

a guest
Jul 13th, 2011
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.01 KB | None | 0 0
  1. #define FILTERSCRIPT
  2.  
  3. #include <a_samp>
  4.  
  5. #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
  6. #define color_g 0x9EC73DAA
  7. #define color_r 0xAA3333AA
  8.  
  9. new Roads[MAX_PLAYERS][2];
  10. new panels, doors, lights, tires;
  11.  
  12. public OnFilterScriptInit()
  13. {
  14.     print("-| Spike Strip Script By Elorreli! |-");
  15.     return 1;
  16. }
  17.  
  18. public OnFilterScriptExit()
  19. {
  20.     return 1;
  21. }
  22.  
  23. public OnPlayerCommandText(playerid, cmdtext[])
  24. {
  25.     dcmd(rsp, 5, cmdtext);
  26.     return 0;
  27. }
  28.  
  29. public OnPlayerConnect(playerid)
  30. {
  31.     Roads[playerid][0] = -1, Roads[playerid][1] = -1;
  32.     return 1;
  33. }
  34.  
  35. dcmd_spike(playerid, params[])
  36. {
  37.     new option[4], Float:pos[4];
  38.     if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, color_r, "You can't be in a vehicle when placing road spikes!");
  39.     if(sscanf(params,"s", option)) return SendClientMessage(playerid,color_g,"Usage: /rs [On/Off]");
  40.     if(strcmp(option,"on",true) == 0)
  41.     {
  42.         if(Roads[playerid][1] != -1) return SendClientMessage(playerid, color_r, "You already have your road spikes deployed!");
  43.         GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  44.         GetPlayerFacingAngle(playerid, pos[3]);
  45.         Roads[playerid][0] = CreatePickup(0, 14, pos[0], pos[1], pos[2], -1);
  46.         Roads[playerid][1] = CreateObject(983, pos[0], pos[1], pos[2]-1.6, 0.0, 0.0, pos[3]+90);
  47.         SendClientMessage(playerid, color_g, "Road spikes placed, they will be auto removed when a vehicle hit it or when you use /spike off.");
  48.         return 1;
  49.     }
  50.     if(strcmp(option,"off",true) == 0)
  51.     {
  52.         DestroyPickup(Roads[playerid][0]);
  53.         DestroyObject(Roads[playerid][1]);
  54.         Roads[playerid][0] = -1, Roads[playerid][1] = -1;
  55.         SendClientMessage(playerid, color_g, "Road spikes removed.");
  56.         return 1;
  57.     }
  58.     return 1;
  59. }
  60.  
  61. public OnPlayerPickUpPickup(playerid, pickupid)
  62. {
  63.     new vehicleid = GetPlayerVehicleID(playerid);
  64.     if(IsPlayerInAnyVehicle(playerid))
  65.     {
  66.       for(new i=0; i<MAX_PLAYERS; i++)
  67.       {
  68.          if(pickupid == Roads[i][0])
  69.          {
  70.             GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
  71.             UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, 15);
  72.             DestroyObject(Roads[i][1]), DestroyPickup(Roads[i][0]);
  73.             Roads[i][1] = -1, Roads[i][0] = -1;
  74.          }
  75.       }
  76.     }
  77.     return 1;
  78. }
  79.  
  80. stock sscanf(string[], format[], {Float,_}:...)
  81. {
  82.     #if defined isnull
  83.         if (isnull(string))
  84.     #else
  85.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  86.     #endif
  87.         {
  88.             return format[0];
  89.         }
  90.     #pragma tabsize 4
  91.     new
  92.         formatPos = 0,
  93.         stringPos = 0,
  94.         paramPos = 2,
  95.         paramCount = numargs(),
  96.         delim = ' ';
  97.     while (string[stringPos] && string[stringPos] <= ' ')
  98.     {
  99.         stringPos++;
  100.     }
  101.     while (paramPos < paramCount && string[stringPos])
  102.     {
  103.         switch (format[formatPos++])
  104.         {
  105.             case '\0':
  106.             {
  107.                 return 0;
  108.             }
  109.             case 'i', 'd':
  110.             {
  111.                 new
  112.                     neg = 1,
  113.                     num = 0,
  114.                     ch = string[stringPos];
  115.                 if (ch == '-')
  116.                 {
  117.                     neg = -1;
  118.                     ch = string[++stringPos];
  119.                 }
  120.                 do
  121.                 {
  122.                     stringPos++;
  123.                     if ('0' <= ch <= '9')
  124.                     {
  125.                         num = (num * 10) + (ch - '0');
  126.                     }
  127.                     else
  128.                     {
  129.                         return -1;
  130.                     }
  131.                 }
  132.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  133.                 setarg(paramPos, 0, num * neg);
  134.             }
  135.             case 'h', 'x':
  136.             {
  137.                 new
  138.                     num = 0,
  139.                     ch = string[stringPos];
  140.                 do
  141.                 {
  142.                     stringPos++;
  143.                     switch (ch)
  144.                     {
  145.                         case 'x', 'X':
  146.                         {
  147.                             num = 0;
  148.                             continue;
  149.                         }
  150.                         case '0' .. '9':
  151.                         {
  152.                             num = (num << 4) | (ch - '0');
  153.                         }
  154.                         case 'a' .. 'f':
  155.                         {
  156.                             num = (num << 4) | (ch - ('a' - 10));
  157.                         }
  158.                         case 'A' .. 'F':
  159.                         {
  160.                             num = (num << 4) | (ch - ('A' - 10));
  161.                         }
  162.                         default:
  163.                         {
  164.                             return -1;
  165.                         }
  166.                     }
  167.                 }
  168.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  169.                 setarg(paramPos, 0, num);
  170.             }
  171.             case 'c':
  172.             {
  173.                 setarg(paramPos, 0, string[stringPos++]);
  174.             }
  175.             case 'f':
  176.             {
  177.  
  178.                 new changestr[16], changepos = 0, strpos = stringPos;
  179.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  180.                 {
  181.                     changestr[changepos++] = string[strpos++];
  182.                     }
  183.                 changestr[changepos] = '\0';
  184.                 setarg(paramPos,0,_:floatstr(changestr));
  185.             }
  186.             case 'p':
  187.             {
  188.                 delim = format[formatPos++];
  189.                 continue;
  190.             }
  191.             case '\'':
  192.             {
  193.                 new
  194.                     end = formatPos - 1,
  195.                     ch;
  196.                 while ((ch = format[++end]) && ch != '\'') {}
  197.                 if (!ch)
  198.                 {
  199.                     return -1;
  200.                 }
  201.                 format[end] = '\0';
  202.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  203.                 {
  204.                     if (format[end + 1])
  205.                     {
  206.                         return -1;
  207.                     }
  208.                     return 0;
  209.                 }
  210.                 format[end] = '\'';
  211.                 stringPos = ch + (end - formatPos);
  212.                 formatPos = end + 1;
  213.             }
  214.             case 'u':
  215.             {
  216.                 new
  217.                     end = stringPos - 1,
  218.                     id = 0,
  219.                     bool:num = true,
  220.                     ch;
  221.                 while ((ch = string[++end]) && ch != delim)
  222.                 {
  223.                     if (num)
  224.                     {
  225.                         if ('0' <= ch <= '9')
  226.                         {
  227.                             id = (id * 10) + (ch - '0');
  228.                         }
  229.                         else
  230.                         {
  231.                             num = false;
  232.                         }
  233.                     }
  234.                 }
  235.                 if (num && IsPlayerConnected(id))
  236.                 {
  237.                     setarg(paramPos, 0, id);
  238.                 }
  239.                 else
  240.                 {
  241.                     #if !defined foreach
  242.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  243.                         #define __SSCANF_FOREACH__
  244.                     #endif
  245.                     string[end] = '\0';
  246.                     num = false;
  247.                     new
  248.                         name[MAX_PLAYER_NAME];
  249.                     id = end - stringPos;
  250.                     foreach (Player, playerid)
  251.                     {
  252.                         GetPlayerName(playerid, name, sizeof (name));
  253.                         if (!strcmp(name, string[stringPos], true, id))
  254.                         {
  255.                             setarg(paramPos, 0, playerid);
  256.                             num = true;
  257.                             break;
  258.                         }
  259.                     }
  260.                     if (!num)
  261.                     {
  262.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  263.                     }
  264.                     string[end] = ch;
  265.                     #if defined __SSCANF_FOREACH__
  266.                         #undef foreach
  267.                         #undef __SSCANF_FOREACH__
  268.                     #endif
  269.                 }
  270.                 stringPos = end;
  271.             }
  272.             case 's', 'z':
  273.             {
  274.                 new
  275.                     i = 0,
  276.                     ch;
  277.                 if (format[formatPos])
  278.                 {
  279.                     while ((ch = string[stringPos++]) && ch != delim)
  280.                     {
  281.                         setarg(paramPos, i++, ch);
  282.                     }
  283.                     if (!i)
  284.                     {
  285.                         return -1;
  286.                     }
  287.                 }
  288.                 else
  289.                 {
  290.                     while ((ch = string[stringPos++]))
  291.                     {
  292.                         setarg(paramPos, i++, ch);
  293.                     }
  294.                 }
  295.                 stringPos--;
  296.                 setarg(paramPos, i, '\0');
  297.             }
  298.             default:
  299.             {
  300.                 continue;
  301.             }
  302.         }
  303.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  304.         {
  305.             stringPos++;
  306.         }
  307.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  308.         {
  309.             stringPos++;
  310.         }
  311.         paramPos++;
  312.     }
  313.     do
  314.     {
  315.         if ((delim = format[formatPos++]) > ' ')
  316.         {
  317.             if (delim == '\'')
  318.             {
  319.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  320.             }
  321.             else if (delim != 'z')
  322.             {
  323.                 return delim;
  324.             }
  325.         }
  326.     }
  327.     while (delim > ' ');
  328.     return 0;
  329. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement