Advertisement
Guest User

Bomber FS 0.96

a guest
Jul 1st, 2010
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 13.77 KB | None | 0 0
  1. /*
  2. GTA: SA-MP
  3. BOMBER FILTERSCRIPT 0.96
  4. created by Mauzen (MSoll (at) web.de) 2008-2010
  5. This code represents my own work and must not be released without my credits
  6. You are allowed to change the code, you may release your own bombtypes and explosions,
  7. but not other codechanges without my permission
  8. And of course you can use this filterscript on your server, giving some credits to me
  9. then would be nice, but is not necessarily needed
  10. */
  11.  
  12. #include <a_samp>
  13. #include <mapandreas>
  14.  
  15. #define COLOR_RED 0xAA3333AA
  16. #define COLOR_YELLOW 0xFFFF00AA
  17.  
  18. #define MAX_BOMBS 32
  19.  
  20. #define KEY_DROP_BOMB KEY_HANDBRAKE
  21. #define KEY_NEXT_BOMBTYPE KEY_ANALOG_DOWN
  22. #define KEY_PREV_BOMBTYPE KEY_ANALOG_UP
  23.  
  24. #define FILTERSCRIPT
  25.  
  26. forward Float:floatrandom(Float:max);
  27. forward Float:GetPlayerDistanceToPoint(playerid, Float:x, Float:y, Float:z);
  28. forward Float:GetGroundZ(Float:x, Float:y);
  29. forward GetVehicleStatID(modelid);
  30. forward DropBomb(playerid);
  31. forward BombTimer(playerid, num);
  32. forward DetonateBomb(playerid, num);
  33. forward CreateSpecialExplosion(num, playerid);
  34. forward ReactivateBomb(playerid, bombnum);
  35. forward IsPlayerAllowedToDropBomb(playerid);
  36. forward AutoDrop(playerid);
  37. forward CreateRadialExplosion(Float:x, Float:y, Float:z, round, max);
  38. forward ReleaseBomb(playerid, bid);
  39.  
  40. // Free changeable stuff -------------
  41.  
  42. enum bombEnum {
  43.     bombName[32],                       //Name of the bomb (plural for correct grammar ;)
  44.     expID,                              //ExplosionID of the bomb (the same as in CreateExplosion)
  45.     Float:expRadius,                    //Explosion radius (the same as in CreateExplosion)
  46.     Float:accuracy,                     //Drop accuracy, higher is better (Height / this value = max x,y tolerance)
  47.     bombModel,                          //Object model of the bomb
  48.     bombModelRot,                       //Object model rotation of the bomb
  49.     expDelay,                           //Explosion delay after reaching the ground (ms)
  50.     reloadTime,                         //Reload time (ms)
  51.     dropAtOnce,                         //Number of bombs beeing dropped with one click
  52.     dropAtOnceDelay                     //Delay between the bombs beeing dropped at once (ms)
  53. }
  54.    
  55. new gBombTypes[][bombEnum] = {
  56. {"nothing", 0, 0.0, 0.0, 0, 0, 0, 0, 0, 0},
  57. {"Normal bombs", 11, 2.0, 7.0, 1636, 270, 0, 100, 1, 0},
  58. {"Fire bombs", 1, 4.0, 8.5, 1636, 270, 0, 150, 1, 0},
  59. {"Big bombs", 7, 4.5, 10.0, 354, 270, 0, 750, 1, 0},
  60. {"High-precision bombs", 6, 2.0, 25.0, 1636, 270, 0, 1000, 1, 0},        
  61. {"Heavy bombs", -1, 5.0, 15.0, 345, 270, 0, 10000, 1, 0},                   //Explosion ID -1 is used for special explosions,f or more info check CreateSpecialExplosion
  62. {"Anti-Missile Flares", -1, 150.0, 35.0, 354, 0, 5000, 10000, 1, 0},         //Only has an effect together with my (act. unreleased) missile FS
  63. {"Nuclear Bombs", -1, 4.0, 10.0, 345, 270, 0, 10000, 1, 0},
  64. {"Clusterbombs", 11, 2.0, 3.0, 1636, 270, 0, 15000, 8, 0},
  65. {"Carpetbombs", 11, 2.0, 5.0, 1636, 270, 0, 15000, 8, 100}
  66. };
  67.  
  68. //{Vehicle model ID, bombtype 1 allowed, bombtype 2 allowed, ..., bombtype n allowed}
  69. //needs to be expanded, when more bombtypes are added
  70. new gVehicleBombs[][] = {
  71.     {476, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0},      //Rustler
  72.     {593, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},      //Dodo
  73.     {553, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1},      //Nevada
  74.     {513, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},      //Stuntplane
  75.     {512, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},      //Cropdust
  76.     {577, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1},      //At-400
  77.     {511, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0},      //Beagle
  78.     {460, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},      //Skimmer
  79.     {519, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1},      //Shamal
  80.     {548, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0},      //Cargobob
  81.     {417, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1},      //Leviathan
  82.     {487, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0},      //Maverick
  83.     {497, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0},      //Police Maverick
  84.     {563, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0},      //Raindance
  85.     {447, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},      //Seasparrow
  86.     {469, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0},      //Sparrow
  87.     {425, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0},      //Hunter
  88.     {592, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1}       //Andromeda
  89. };
  90.  
  91. new Float:gBombSpeed = 20.0;        //Bomb-falling speed (constant, non-accelerated)
  92. // Global variables ---------------
  93. new bombid[MAX_PLAYERS][MAX_BOMBS];     //Used for different stuff
  94. new bombtime[MAX_PLAYERS][MAX_BOMBS];
  95. new bombcount[MAX_PLAYERS];
  96. new bombarmed[MAX_PLAYERS][MAX_BOMBS];
  97. new Float:targetz[MAX_PLAYERS][MAX_BOMBS];
  98. new boti[MAX_PLAYERS][MAX_BOMBS];
  99. new bfree[MAX_PLAYERS];
  100. new btype[MAX_PLAYERS][MAX_BOMBS];
  101. new bptype[MAX_PLAYERS] = 0;
  102. new vmid[MAX_PLAYERS] = -1;
  103. // ----------------------------------
  104.  
  105. #if defined FILTERSCRIPT
  106.  
  107. public OnFilterScriptInit()
  108. {
  109.         print("\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  110.         print("X         Bombing filterscript  V0.96       X");
  111.         print("X        created by Mauzen 7/2008-2010      X");
  112.         print("XxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxX");
  113.         MapAndreas_Init(MAP_ANDREAS_MODE_FULL);     //This FS requires the MapAndres-plugin
  114.         return 1;
  115. }
  116.  
  117. public OnFilterScriptExit()
  118. {
  119.         return 1;
  120. }
  121. #endif
  122.  
  123. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  124. {
  125.         vmid[playerid] = GetVehicleStatID(GetVehicleModel(vehicleid));
  126.         if(vmid[playerid] > -1) {
  127.             bptype[playerid] = 0;
  128.         }
  129.         return 1;
  130. }
  131.  
  132. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  133. {
  134.         if(IsPlayerInAnyVehicle(playerid) && (vmid[playerid] > -1)) {
  135.             new old[MAX_PLAYERS];
  136.             if((newkeys & KEY_NEXT_BOMBTYPE) && !(oldkeys & KEY_NEXT_BOMBTYPE)) {
  137.                 old[playerid] = bptype[playerid];
  138.                 bptype[playerid] ++;
  139.                 if(bptype[playerid] >= sizeof gBombTypes) {
  140.                     bptype[playerid] = old[playerid];
  141.                 }
  142.                 while(gVehicleBombs[vmid[playerid]][bptype[playerid] + 1] <= 0) {
  143.                     bptype[playerid] ++;
  144.                     if(bptype[playerid] >= sizeof gBombTypes) {
  145.                         bptype[playerid] = old[playerid];
  146.                         return 1;
  147.                     }
  148.                 }
  149.                 new str[64];
  150.                 format(str, 64, "You have armed %s", gBombTypes[bptype[playerid]][bombName]);
  151.                 SendClientMessage(playerid, COLOR_YELLOW, str);
  152.             }
  153.             if((newkeys & KEY_PREV_BOMBTYPE) && !(oldkeys & KEY_PREV_BOMBTYPE)) {
  154.                 old[playerid] = bptype[playerid];
  155.                 bptype[playerid] --;
  156.                 if(bptype[playerid] < 0) {
  157.                     bptype[playerid] = old[playerid];
  158.                 }
  159.                 while(gVehicleBombs[vmid[playerid]][bptype[playerid] + 1] <= 0) {
  160.                     bptype[playerid] --;
  161.                     if(bptype[playerid] < 0) {
  162.                         bptype[playerid] = old[playerid];
  163.                         return 1;
  164.                     }
  165.                 }
  166.                 new str[64];
  167.                 format(str, 64, "You have armed %s", gBombTypes[bptype[playerid]][bombName]);
  168.                 SendClientMessage(playerid, COLOR_YELLOW, str);
  169.             }
  170.             if((newkeys & KEY_DROP_BOMB) && !(oldkeys & KEY_DROP_BOMB)) {
  171.                 if(IsPlayerAllowedToDropBomb(playerid)) {
  172.                     DropBomb(playerid);
  173.                 } else SendClientMessage(playerid, COLOR_RED, "You can't use that bomb now!");
  174.             }
  175.         }
  176.         return 1;
  177. }
  178.  
  179. // -----------------------------------------------------------------------------
  180. //useful stuff
  181. public Float:floatrandom(Float:max)
  182. {
  183.         new Float:rand;
  184.         max = max * 100000;
  185.         rand = floatdiv(float(random(floatround(max))), 100000.0);
  186.         return rand;
  187. }
  188.  
  189. public Float:GetPlayerDistanceToPoint(playerid, Float:x, Float:y, Float:z)
  190. {
  191.         new Float:px;
  192.         new Float:py;
  193.         new Float:pz;
  194.         if(!IsPlayerInAnyVehicle(playerid)) GetPlayerPos(playerid, px, py, pz);
  195.             else GetVehiclePos(GetPlayerVehicleID(playerid), px, py, pz);
  196.         return floatsqroot( floatadd( floatadd( floatpower(floatsub(x, px), 2), floatpower(floatsub(y, py), 2) ), floatpower(floatsub(z, pz), 2) ) );
  197. }
  198.  
  199. public Float:GetGroundZ(Float:x, Float:y)
  200. {
  201.         new Float:gz;
  202.         MapAndreas_FindZ_For2DCoord(x, y, gz);
  203.         return gz;
  204. }
  205.  
  206. public GetVehicleStatID(modelid)
  207. {
  208.     for(new i = 0; i < sizeof gVehicleBombs; i ++) {
  209.         if(gVehicleBombs[i][0] == modelid) {
  210.             return i;
  211.         }
  212.     }
  213.     return -1;
  214. }
  215.  
  216. // -----------------------------------------------------------------------------
  217.  
  218. public DropBomb(playerid)
  219. {
  220.         if(bptype[playerid] != 0) {
  221.             if(bfree[playerid] == 0) {
  222.                 if(bombcount[playerid] < MAX_BOMBS) {
  223.                     bfree[playerid] = 1;
  224.                     new bid = bptype[playerid];
  225.                     for(new drops = 0; drops < gBombTypes[bptype[playerid]][dropAtOnce] && bombcount[playerid] < MAX_BOMBS; drops ++) {
  226.                         if(gBombTypes[bid][dropAtOnceDelay] > 0) SetTimerEx("ReleaseBomb", gBombTypes[bid][dropAtOnceDelay] * drops, 0, "ii", playerid, bid);
  227.                             else ReleaseBomb(playerid, bid);
  228.                     }
  229.                     SetTimerEx("ReactivateBomb", gBombTypes[bptype[playerid]][reloadTime], 0, "ii", playerid, bptype[playerid]);
  230.                 } else {
  231.                     SendClientMessage(playerid, COLOR_RED, "Too many falling bombs, you cannot drop more at once!");
  232.                 }
  233.             } else {
  234.                 SendClientMessage(playerid, COLOR_RED, "The bomb needs to be loaded! Wait a moment...");
  235.             }
  236.         } else {
  237.         }
  238. }
  239. public ReleaseBomb(playerid, bid)
  240. {
  241.     bombcount[playerid] ++;
  242.     new Float:x, Float:y, Float:z;
  243.     new sel;
  244.     new Float:tolerancex, Float:tolerancey;
  245.     for(new i = 0; i < MAX_BOMBS; i++) {
  246.         if(bombid[playerid][i] <= 0) {
  247.             sel = i;
  248.             bombid[playerid][i] = 1;
  249.             break;
  250.         }
  251.     }
  252.     btype[playerid][sel] = bid;
  253.     GetVehiclePos(GetPlayerVehicleID(playerid), x, y, z);
  254.  
  255.     tolerancex = floatsub( floatrandom( floatdiv(z, gBombTypes[bid][accuracy]) ), floatdiv(floatdiv(z, gBombTypes[bid][accuracy]), 2.0));
  256.     tolerancey = floatsub( floatrandom( floatdiv(z, gBombTypes[bid][accuracy]) ), floatdiv(floatdiv(z, gBombTypes[bid][accuracy]), 2.0));
  257.     targetz[playerid][sel] = GetGroundZ(x + tolerancex, y + tolerancey);
  258.     bombid[playerid][sel] = CreateObject(gBombTypes[bid][bombModel], x, y, z - 1, gBombTypes[bid][bombModelRot], 0, 0);
  259.     MoveObject(bombid[playerid][sel], x + tolerancex, y + tolerancey, targetz[playerid][sel] - 1, gBombSpeed);
  260.     boti[playerid][sel] = 0;
  261.     bombarmed[playerid][sel] = 0;
  262.     bombtime[playerid][sel] = SetTimerEx("BombTimer", 100, 1, "ii", playerid, sel);
  263.     if(bptype[playerid] == 6) {
  264.         CallRemoteFunction("LaunchAntiRocketFlare", "iff", bombid[playerid][sel], gBombTypes[6][expRadius], gBombTypes[6][accuracy]);
  265.     }
  266. }
  267.  
  268. public BombTimer(playerid, num)
  269. {
  270.         new Float:x;
  271.         new Float:y;
  272.         new Float:z;
  273.         GetObjectPos(bombid[playerid][num], x, y, z);
  274.         boti[playerid][num] ++;
  275.  
  276.         for(new i = 0; i < MAX_PLAYERS; i ++) {
  277.             if(IsPlayerConnected(i))
  278.                 if(GetPlayerDistanceToPoint(i, x, y, z) < 7.5 && boti[playerid][num] >= 5) DetonateBomb(playerid, num);
  279.         }
  280.         if((floatsub(z, targetz[playerid][num] - 1) < 0.1) && !bombarmed[playerid][num]) {  //bomb reached ground
  281.             if(gBombTypes[btype[playerid][num]][expDelay] > 0) {
  282.                 SetTimerEx("DetonateBomb", gBombTypes[btype[playerid][num]][expDelay], 0, "ii", playerid, num);
  283.                 bombarmed[playerid][num] = 1;
  284.             } else {
  285.                 DetonateBomb(playerid, num);
  286.             }
  287.         }
  288. }
  289.  
  290. public DetonateBomb(playerid, num)
  291. {
  292.         new Float:x;
  293.         new Float:y;
  294.         new Float:z;
  295.         GetObjectPos(bombid[playerid][num], x, y, z);
  296.         KillTimer(bombtime[playerid][num]);
  297.         if(gBombTypes[btype[playerid][num]][expID] > -1) {
  298.             CreateExplosion(x, y, z, gBombTypes[btype[playerid][num]][expID], gBombTypes[btype[playerid][num]][expRadius]);
  299.         } else {
  300.             CreateSpecialExplosion(num, playerid);
  301.         }
  302.         DestroyObject(bombid[playerid][num]);
  303.         bombid[playerid][num] = -1;
  304.         bombcount[playerid] --;
  305. }
  306.  
  307. public CreateSpecialExplosion(num, playerid)
  308. {                                                           //Every explosion with explosion ID -1 is created here
  309.         new Float:x;                                        //You may add a check for your own bombs like the one already existing
  310.         new Float:y;
  311.         new Float:z;
  312.         GetObjectPos(bombid[playerid][num], x, y, z);
  313.         if(btype[playerid][num] == 5) {                     //btype[playerid][num] is the index of the bomb exploding
  314.             CreateExplosion(x, y, z, 7, 4.0);               //x, y and z are the coordinates of the bomb
  315.             CreateExplosion(x, y, z + 5.0, 1, 4.0);
  316.             CreateExplosion(x, y, z + 9.0, 1, 3.0);
  317.             CreateExplosion(x, y, z + 12.5, 1, 3.0);
  318.             CreateExplosion(x + 4.0, y, z, 0, 2.0);
  319.             CreateExplosion(x - 4.0, y, z, 0, 2.0);
  320.             CreateExplosion(x, y + 4.0, z, 0, 2.0);
  321.             CreateExplosion(x, y - 4.0, z, 0, 2.0);
  322.             CreateExplosion(x, y - 7.0, z, 1, 3.0);
  323.             CreateExplosion(x, y + 7.0, z, 1, 3.0);
  324.             CreateExplosion(x + 7.0, y, z, 1, 3.0);
  325.             CreateExplosion(x - 7.0, y, z, 1, 3.0);
  326.             CreateExplosion(x + 4.0, y + 4.0, z, 1, 4.0);
  327.             CreateExplosion(x - 4.0, y - 4.0, z, 1, 4.0);
  328.             CreateExplosion(x - 4.0, y + 4.0, z, 1, 4.0);
  329.             CreateExplosion(x + 4.0, y - 4.0, z, 1, 4.0);
  330.         } else if(btype[playerid][num] == 6) {
  331.             CallRemoteFunction("StopAntiRocketFlare", "i", bombid[playerid][num]);
  332.         } else if(btype[playerid][num] == 7) {
  333.             CreateExplosion(x, y, z, 7, 4.0);
  334.             SetTimerEx("CreateRadialExplosion", 200, 0, "fffii", x, y, z, 0, 4);
  335.         }
  336.         //To add an own explosion create a new check like this:
  337.         /*if(btype[playerid][num] == YOUR_BOMB_INDEX) {
  338.             ...your explosion...
  339.         }*/
  340. }
  341.  
  342. public CreateRadialExplosion(Float:x, Float:y, Float:z, round, max)
  343. {
  344.     for(new i = 0; i < 1 + 6 * round; i ++) {
  345.         CreateExplosion(x + round * 10 * floatcos(6.28318 * (float(i) / (1.0 + 6.0*float(round)))),  y + round * 10 * floatsin(6.28318 * (float(i) / (1.0 + 6.0*float(round)))), z, 2, 3.0);
  346.     }
  347.     round ++;
  348.     if(round <= max) SetTimerEx("CreateRadialExplosion", 200, 0, "fffii", x, y, z, round, max);
  349.     return 1;
  350. }
  351.  
  352. public ReactivateBomb(playerid)
  353. {
  354.         bfree[playerid] = 0;
  355. }
  356.  
  357. public IsPlayerAllowedToDropBomb(playerid)
  358. {
  359.     // This is used to restrict the use of bombs for single players
  360.     // For example to make them available for special teams only, ...
  361.     // bptype[playerid] is the index of the selected bomb
  362.     return 1;
  363. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement