Advertisement
Guest User

Seif

a guest
Aug 29th, 2008
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.37 KB | None | 0 0
  1. /*
  2.                             Bombing Script by Seif - Allowing you to
  3. */
  4. /*x---------------------------------Important-------------------------------------x*/
  5. //**INCLUDES**//
  6. #include <a_samp>
  7. //**PRAGMAS**//
  8.  
  9. //**MISC**//
  10.  
  11. /*x---------------------------------Defining-------------------------------------x*/
  12. //**COLORS*//
  13. #define GREEN           0x21DD00FF
  14. #define RED             0xE60000FF
  15. #define ADMIN_RED       0xFB0000FF
  16. #define YELLOW          0xFFFF00FF
  17. #define ORANGE          0xF97804FF
  18. #define LIGHTRED        0xFF8080FF
  19. #define LIGHTBLUE       0x00C2ECFF
  20. #define PURPLE          0xB360FDFF
  21. #define PLAYER_COLOR    0xFFFFFFFF
  22. #define BLUE            0x1229FAFF
  23. #define LIGHTGREEN      0x38FF06FF
  24. #define DARKPINK        0xE100E1FF
  25. #define DARKGREEN       0x008040FF
  26. #define ANNOUNCEMENT    0x6AF7E1FF
  27. #define COLOR_SYSTEM    0xEFEFF7AA
  28. #define GREY            0xCECECEFF
  29. #define PINK            0xD52DFFFF
  30. #define DARKGREY        0x626262FF
  31. #define AQUAGREEN       0x03D687FF
  32. #define NICESKY         0x99FFFFAA
  33. #define WHITE           0xFFFFFFFF
  34. //**MISC**//
  35. #define MAX_BOMBS       500
  36. //**VARIABLES**//
  37. enum bombInfo
  38. {
  39.     bombPlanter[MAX_PLAYER_NAME],
  40.     Float:bombX,
  41.     Float:bombY,
  42.     Float:bombZ,
  43. };
  44. new BombInfo[MAX_BOMBS][bombInfo];
  45. new Bombs[MAX_PLAYERS];
  46. new VehicleBombed[MAX_VEHICLES];
  47. new Bomber[MAX_PLAYERS];
  48. new ExplosiveObject[MAX_OBJECTS];
  49. new explosive = 0;
  50. // **FORWARDS** //
  51.  
  52. /*x---------------------------------CallBacks-------------------------------------x*/
  53. public OnFilterScriptInit()
  54. {
  55.     for(new b = 0; b < MAX_BOMBS; b++)
  56.     {
  57.         strmid(BombInfo[b][bombPlanter], "[NONE]", 0, strlen("[NONE]"), 128);
  58.         BombInfo[b][bombX] = 0.0;
  59.         BombInfo[b][bombY] = 0.0;
  60.         BombInfo[b][bombZ] = 0.0;
  61.     }
  62.     for(new v = 1; v < MAX_VEHICLES; v++) VehicleBombed[v] = 0;
  63.     explosive = 0;
  64.  
  65.     print("<|-----------------------------------------|>");
  66.     print("  .:[ - Bombing Script by Seif - ]:.");
  67.     print("<|-----------------------------------------|>");
  68.     return 1;
  69. }
  70.  
  71. public OnFilterScriptExit()
  72. {
  73.     for(new o = 0; o < MAX_OBJECTS; o++) DestroyObject(ExplosiveObject[o]);
  74.     return 1;
  75. }
  76.  
  77. public OnPlayerConnect(playerid)
  78. {
  79.     Bombs[playerid] = 0;
  80.     Bomber[playerid] = 0;
  81.     return 1;
  82. }
  83.  
  84. public OnPlayerCommandText(playerid, cmdtext[])
  85. {
  86.     new tmp[256],cmd[256],idx;
  87.     cmd = strtok(cmdtext, idx);
  88.     if(strcmp("/setbomb", cmd, true) == 0)
  89.     {
  90.         tmp = strtok(cmdtext, idx);
  91.         if (!Bombs[playerid]) return SendClientMessage(playerid, ORANGE," You don't have a bomb with you.");
  92.         if(!strlen(tmp)) return SendClientMessage(playerid, ORANGE,"USAGE: /setbomb [foot/car]");
  93.         else if (strcmp("foot", tmp, true) == 0)
  94.         {
  95.             if (GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) return SendClientMessage(playerid, ORANGE, " You're not on foot");
  96.             new Float:X,Float:Y,Float:Z,Float:A;
  97.             new playername[24];
  98.             GetPlayerPos(playerid, X, Y, Z);
  99.             GetPlayerFacingAngle(playerid,A);
  100.             GetPlayerName(playerid, playername, 24);
  101.             explosive++;
  102.             Y += (1 * floatcos(-A, degrees));
  103.             X += (1 * floatsin(-A, degrees));
  104.             ApplyAnimation(playerid, "BOMBER","BOM_Plant_In",4.0,0,0,0,0,0);
  105.             ExplosiveObject[explosive] = CreateObject(1654, X, Y, Z-0.9, 0, 90, 0);
  106.             Bomber[playerid] = 1;
  107.             BombInfo[explosive][bombX] = X;
  108.             BombInfo[explosive][bombY] = Y;
  109.             BombInfo[explosive][bombZ] = Z;
  110.             strmid(BombInfo[explosive][bombPlanter], playername, 0, strlen(playername), 50);
  111.             printf("%d",explosive);
  112.             SendClientMessage(playerid,ORANGE," You have planted a bomb on the ground. Type /usebomb to detonate it.");
  113.             Bombs[playerid]--;
  114.         }
  115.         else if (strcmp("car", tmp, true) == 0)
  116.         {
  117.             if (IsPlayerInAnyVehicle(playerid))
  118.             {
  119.                 new vehicleid = GetPlayerVehicleID(playerid);
  120.                 new playername[24];
  121.                 GetPlayerName(playerid, playername, 24);
  122.                 VehicleBombed[vehicleid] = 1;
  123.                 Bomber[playerid] = 2;
  124.                 explosive++;
  125.                 strmid(BombInfo[explosive][bombPlanter], playername, 0, strlen(playername), 50);
  126.                 SendClientMessage(playerid,ORANGE," You have planted a bomb inside the car. Type /usebomb to detonate it.");
  127.                 Bombs[playerid]--;
  128.             }
  129.             else SendClientMessage(playerid, ORANGE, " You're not inside a vehicle");
  130.         }
  131.         else SendClientMessage(playerid, ORANGE,"USAGE: /setbomb [foot/car]");
  132.         return 1;
  133.     }
  134.    
  135.     if(strcmp(cmdtext, "/bomber", true)==0)
  136.     {
  137.         new string[128];
  138.         for(new i = 0; i < MAX_BOMBS; i++)
  139.         {
  140.             if (PlayerToPoint(playerid,3,BombInfo[i][bombX],BombInfo[i][bombY],BombInfo[i][bombZ]))
  141.             {
  142.                 printf("%d - %d",explosive,i);
  143.                 format(string,sizeof(string),"Bomber: %s - Bomb #%d",BombInfo[i][bombPlanter],i);
  144.                 SendClientMessage(playerid,GREY,string);
  145.             }
  146.         }
  147.         return 1;
  148.     }
  149.    
  150.     if (strcmp("/usebomb", cmd, true) == 0)
  151.     {
  152.         if (Bomber[playerid] == 1) // On foot bomb
  153.         {
  154.             new playa[128];
  155.             GetPlayerName(playerid, playa, 24);
  156.             new count = 0;
  157.             for(new bomb = 1; bomb < MAX_BOMBS; bomb++)
  158.             {
  159.                 if (!strcmp(BombInfo[bomb][bombPlanter], playa, false)) // if he's the planter of this bomb
  160.                 {
  161.                     CreateExplosion(BombInfo[bomb][bombX],BombInfo[bomb][bombY],BombInfo[bomb][bombZ], 7, 7);
  162.                     DestroyObject(ExplosiveObject[bomb]);
  163.                     if (explosive <= 0) explosive = 1;
  164.                     explosive--;
  165.                     Bomber[playerid] = 0;
  166.                     BombInfo[bomb][bombX] = 0.0;
  167.                     BombInfo[bomb][bombY] = 0.0;
  168.                     BombInfo[bomb][bombZ] = 0.0;
  169.                     strmid(BombInfo[bomb][bombPlanter], "[NONE]", 0, strlen("[NONE]"), 128);
  170.                     printf("[ON FOOT] B: %d - E: %d - P: %s",bomb, explosive, BombInfo[bomb][bombPlanter]);
  171.                     count++;
  172.                 }
  173.             }
  174.             format(playa, sizeof(playa), "You activated %d bombs", count);
  175.             SendClientMessage(playerid, ORANGE, playa);
  176.         }
  177.         else if (Bomber[playerid] == 2) // car bomb
  178.         {
  179.             new playa[128];
  180.             GetPlayerName(playerid, playa, 24);
  181.             new count = 0;
  182.             for(new carbomb = 1; carbomb < MAX_VEHICLES; carbomb++)
  183.             {
  184.                 if (VehicleBombed[carbomb] == 1)
  185.                 {
  186.                     new bomb = 0;
  187.                     while(bomb < MAX_BOMBS)
  188.                     {
  189.                         bomb++;
  190.                         if (strcmp(BombInfo[bomb][bombPlanter], playa, true) == 0) // if he's the planter of this bomb
  191.                         {
  192.                             new Float:X,Float:Y,Float:Z;
  193.                             GetVehiclePos(carbomb,X,Y,Z);
  194.                             SetVehicleHealth(carbomb,-999);
  195.                             CreateExplosion(X,Y,Z, 7, 7);
  196.                             Bomber[playerid] = 0;
  197.                             VehicleBombed[carbomb] = 0;
  198.                             strmid(BombInfo[bomb][bombPlanter], "[NONE]", 0, strlen("[NONE]"), 128);
  199.                             if (explosive <= 0) explosive = 1;
  200.                             explosive--;
  201.                             printf("[IN VEH] B: %d - E: %d",bomb, explosive);
  202.                             count++;
  203.                         }
  204.                     }
  205.                 }
  206.             }
  207.             format(playa, sizeof(playa), "You activated %d car bombs", count);
  208.             SendClientMessage(playerid, ORANGE, playa);
  209.         }
  210.         return 1;
  211.     }
  212.    
  213.     if(strcmp(cmd, "/givebomb", true) == 0)
  214.     {
  215.         if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, RED, " You're not an admin");
  216.         tmp = strtok(cmdtext, idx);
  217.         new targetid = ReturnUser(tmp, playerid);
  218.         new name[MAX_PLAYER_NAME];
  219.         GetPlayerName(targetid, name, sizeof(name));
  220.         new tname[MAX_PLAYER_NAME];
  221.         GetPlayerName(targetid, tname, sizeof(tname));
  222.        
  223.         tmp = strtok(cmdtext, idx);
  224.         new amount = strval(tmp);
  225.         if (!strlen(tmp)) amount = 1;
  226.         Bombs[targetid] += amount;
  227.         format(tmp, 128, " You gave %d bombs to %s.",amount, tname);
  228.         SendClientMessage(playerid, LIGHTBLUE, tmp);
  229.         format(tmp, 128, " You have received %d bombs from %s.",amount, name);
  230.         SendClientMessage(targetid, LIGHTBLUE, tmp);
  231.         return 1;
  232.     }
  233.    
  234.     if (!strcmp("/test", cmdtext, true))
  235.     {
  236.         new name[24];
  237.         GetPlayerName(playerid, name, 24);
  238.         if (!strcmp(BombInfo[1][bombPlanter], name, false))
  239.         {
  240.             printf("%s : %s", BombInfo[1][bombPlanter], name);
  241.             return 0;
  242.         }
  243.         return 1;
  244.     }
  245.     return 0;
  246. }
  247.  
  248. strtok(const string[], &index)
  249. {
  250.     new length = strlen(string);
  251.     while ((index < length) && (string[index] <= ' '))
  252.     {
  253.         index++;
  254.     }
  255.  
  256.     new offset = index;
  257.     new result[20];
  258.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  259.     {
  260.         result[index - offset] = string[index];
  261.         index++;
  262.     }
  263.     result[index - offset] = EOS;
  264.     return result;
  265. }
  266.  
  267. PlayerToPoint(playerid,Float:radi, Float:px, Float:py, Float:pz)
  268. {
  269.     if(IsPlayerConnected(playerid))
  270.     {
  271.         new Float:x, Float:y, Float:z;
  272.         new Float:ox, Float:oy, Float:oz;
  273.         GetPlayerPos(playerid, ox, oy, oz);
  274.         x = (ox -px);
  275.         y = (oy -py);
  276.         z = (oz -pz);
  277.         if (((x < radi) && (x > -radi)) && ((y < radi) && (y > -radi)) && ((z < radi) && (z > -radi))) return 1;
  278.     }
  279.     return 0;
  280. }
  281.  
  282. stock IsNumeric(const string[])
  283. {
  284.     for (new i = 0, j = strlen(string); i < j; i++)
  285.     if (string[i] > '9' || string[i] < '0')
  286.     return 0;
  287.     return 1;
  288. }
  289.  
  290. ReturnUser(text[], playerid = INVALID_PLAYER_ID)
  291. {
  292.     new pos = 0;
  293.     while (text[pos] < 0x21)
  294.     {
  295.     if (text[pos] == 0) return INVALID_PLAYER_ID;
  296.     pos++;
  297.     }
  298.     new userid = INVALID_PLAYER_ID;
  299.     if (IsNumeric(text[pos]))
  300.     {
  301.     userid = strval(text[pos]);
  302.     if (userid >=0 && userid < MAX_PLAYERS)
  303.     {
  304.     if(!IsPlayerConnected(userid))
  305.     {
  306.     userid = INVALID_PLAYER_ID;
  307.     }
  308.     else
  309.     {
  310.     return userid;
  311.     }
  312.     }
  313.     }
  314.     new len = strlen(text[pos]);
  315.     new count = 0;
  316.     new pname[MAX_PLAYER_NAME];
  317.     for (new i = 0; i < MAX_PLAYERS; i++)
  318.     {
  319.     if (IsPlayerConnected(i))
  320.     {
  321.     GetPlayerName(i, pname, sizeof (pname));
  322.     if (strcmp(pname, text[pos], true, len) == 0)
  323.     {
  324.     if (len == strlen(pname))
  325.     {
  326.     return i;
  327.     }
  328.     else
  329.     {
  330.     count++;
  331.     userid = i;
  332.     }
  333.     }
  334.     }
  335.     }
  336.     if (count != 1)
  337.     {
  338.     if (playerid != INVALID_PLAYER_ID)
  339.     {
  340.     if (count)
  341.     {
  342.     SendClientMessage(playerid, COLOR_SYSTEM, "There are multiple users, enter full playername.");
  343.     }
  344.     else
  345.     {
  346.     SendClientMessage(playerid, COLOR_SYSTEM, "Playername not found.");
  347.     }
  348.     }
  349.     userid = INVALID_PLAYER_ID;
  350.     }
  351.     return userid;
  352. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement