Advertisement
Guest User

Explosion System

a guest
Nov 26th, 2010
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.13 KB | None | 0 0
  1.    /*------------------------*
  2.     |    Explosion System    |
  3.     |========================|
  4.     |  Author: Miguel C.     |
  5.     |  Version: 0.1          |
  6.     |  Released: 26/11/2010  |
  7.     *------------------------*/
  8.  
  9.  
  10. #define FILTERSCRIPT
  11.  
  12. #include <a_samp>
  13.  
  14. #include <zcmd>
  15. #include <foreach>
  16.  
  17. #undef MAX_PLAYERS
  18.  
  19. #define MAX_PLAYERS         (500)   // Change this to your server's max slots.
  20. #define MAX_PLAYER_CHARGES  (32)    // Change this to the player's max bombs.
  21. #define DEFAULT_TYPE        (7)     // Default explosion type.
  22. #define DEFAULT_RADIUS      (25)    // Default explosion radius.
  23.  
  24. #define COLOR_INFO      0xFFFFFFFF
  25. #define COLOR_YELLOW    0xFFFF00FF
  26. #define COLOR_SUCCESS   0x008A00FF
  27. #define COLOR_WARNING   0xF07800FF
  28. #define COLOR_ERROR     0xCE0000FF
  29.  
  30. enum
  31.     PlayerInfo
  32.     {
  33.         bool:planting,
  34.         bool:detonating,
  35.         bool:settingup,
  36.         used_charges,
  37.         first_charge,
  38.         explosion_type,
  39.         Float:explosion_radius
  40.     }
  41.  
  42. enum
  43.     ChargeInfo
  44.     {
  45.         user,
  46.         Float:x,
  47.         Float:y,
  48.         Float:z
  49.     }
  50.  
  51. new
  52.     Player[MAX_PLAYERS][PlayerInfo],
  53.     Charge[MAX_PLAYERS * MAX_PLAYER_CHARGES][ChargeInfo];
  54.  
  55. forward OnPlayerPlantBomb(playerid);
  56.  
  57. main(){}
  58.  
  59. public OnFilterScriptInit()
  60. {
  61.     printf("  Explosion System v0.1 by Miguel loaded.");
  62.     ResetChargesInfo();
  63.     foreach(Player, i) ResetPlayerChargesInfo(i);
  64.     return 1;
  65. }
  66.  
  67. public OnFilterScriptExit()
  68. {
  69.     printf("  Explosion System v0.1 by Miguel unloaded.");
  70.     return 1;
  71. }
  72.  
  73. public OnGameModeInit()
  74. {
  75.     ResetChargesInfo();
  76.     return 1;
  77. }
  78.  
  79. public OnGameModeExit()
  80. {
  81.     ResetChargesInfo();
  82.     return 1;
  83. }
  84.  
  85. public OnPlayerConnect(playerid)
  86. {
  87.     ResetPlayerChargesInfo(playerid);
  88.     return 1;
  89. }
  90.  
  91. public OnPlayerDisconnect(playerid, reason)
  92. {
  93.     ResetPlayerChargesInfo(playerid);
  94.     return 1;
  95. }
  96.  
  97. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  98. {
  99.     if(newkeys & KEY_FIRE)
  100.     {
  101.         if((Player[playerid][detonating] == true) && (IsPlayerInAnyVehicle(playerid)) && (Player[playerid][settingup] == false))
  102.         {
  103.             for(new i = Player[playerid][first_charge]; i < (Player[playerid][first_charge] + Player[playerid][used_charges]); i ++)
  104.             {
  105.                 CreateExplosion(Charge[i][x], Charge[i][y], Charge[i][z], Player[playerid][explosion_type], Player[playerid][explosion_radius]);
  106.                 Charge[i][x] = 0.0;
  107.                 Charge[i][y] = 0.0;
  108.                 Charge[i][z] = 0.0;
  109.                 Charge[i][user] = -1;
  110.             }
  111.             Player[playerid][detonating] = false;
  112.             Player[playerid][used_charges] = 0;
  113.             Player[playerid][first_charge] = -1;
  114.             SendClientMessage(playerid, COLOR_SUCCESS, "* The bombs have been detonated!");
  115.         }
  116.     }
  117.     if(newkeys & KEY_WALK)
  118.     {
  119.         if((Player[playerid][planting] == true) && (Player[playerid][settingup] == false))
  120.         {
  121.             if(Player[playerid][used_charges] < (MAX_PLAYER_CHARGES - 1))
  122.             {
  123.                 Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][user] = playerid;
  124.                 GetPlayerPos(playerid,
  125.                     Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][x],
  126.                     Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][y],
  127.                     Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][z]);
  128.                 Player[playerid][settingup] = true;
  129.                 ApplyAnimation(playerid, "BOMBER", " ", 2.5, 0, 1, 1, 0, 0, 1);
  130.                 ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 2.5, 0, 1, 1, 0, 0, 1);
  131.                 SetTimerEx("OnPlayerPlantBomb", 2400, false, "ii", playerid, Player[playerid][first_charge] + Player[playerid][used_charges]);
  132.             }
  133.             else
  134.             {
  135.                 Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][user] = playerid;
  136.                 GetPlayerPos(playerid,
  137.                     Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][x],
  138.                     Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][y],
  139.                     Charge[Player[playerid][first_charge] + Player[playerid][used_charges]][z]);
  140.                 Player[playerid][planting] = false;
  141.                 Player[playerid][detonating] = true;
  142.                 Player[playerid][settingup] = true;
  143.                 ApplyAnimation(playerid, "BOMBER", " ", 2.5, 0, 1, 1, 0, 0, 1);
  144.                 ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 2.5, 0, 1, 1, 0, 0, 1);
  145.                 SetTimerEx("OnPlayerPlantBomb", 2400, false, "ii", playerid, Player[playerid][first_charge] + Player[playerid][used_charges]);
  146.             }
  147.         }
  148.         else if((Player[playerid][detonating] == true) && (Player[playerid][settingup] == false))
  149.         {
  150.             for(new i = Player[playerid][first_charge]; i < (Player[playerid][first_charge] + Player[playerid][used_charges]); i ++)
  151.             {
  152.                 CreateExplosion(Charge[i][x], Charge[i][y], Charge[i][z], Player[playerid][explosion_type], Player[playerid][explosion_radius]);
  153.                 Charge[i][x] = 0.0;
  154.                 Charge[i][y] = 0.0;
  155.                 Charge[i][z] = 0.0;
  156.                 Charge[i][user] = -1;
  157.             }
  158.             Player[playerid][detonating] = false;
  159.             Player[playerid][used_charges] = 0;
  160.             Player[playerid][first_charge] = -1;
  161.             SendClientMessage(playerid, COLOR_SUCCESS, "* The bombs have been detonated!");
  162.         }
  163.     }
  164.     if(newkeys & KEY_SUBMISSION)
  165.     {
  166.         if((Player[playerid][detonating] == true) && (Player[playerid][settingup] == false))
  167.         {
  168.             for(new i = Player[playerid][first_charge]; i < (Player[playerid][first_charge] + Player[playerid][used_charges]); i ++)
  169.             {
  170.                 CreateExplosion(Charge[i][x], Charge[i][y], Charge[i][z], Player[playerid][explosion_type], Player[playerid][explosion_radius]);
  171.                 Charge[i][x] = 0.0;
  172.                 Charge[i][y] = 0.0;
  173.                 Charge[i][z] = 0.0;
  174.                 Charge[i][user] = -1;
  175.             }
  176.             Player[playerid][detonating] = false;
  177.             Player[playerid][used_charges] = 0;
  178.             Player[playerid][first_charge] = -1;
  179.             SendClientMessage(playerid, COLOR_SUCCESS, "* The bombs have been detonated!");
  180.         }
  181.     }
  182.     return 1;
  183. }
  184.  
  185. public OnPlayerPlantBomb(playerid)
  186. {
  187.     Player[playerid][used_charges] ++;
  188.     SendClientMessage(playerid, COLOR_YELLOW, "* You have planted a bomb.");
  189.     Player[playerid][settingup] = false;
  190.     if(Player[playerid][used_charges] >= (MAX_PLAYER_CHARGES))
  191.     {
  192.         SendClientMessage(playerid, COLOR_SUCCESS, "* You are now detonating the bombs!");
  193.         SendClientMessage(playerid, COLOR_INFO, "* Use the walk key to detonate the bombs.");
  194.         SendClientMessage(playerid, COLOR_INFO, "* If you are in a vehicle, you can alternatively use the sub-mission key.");
  195.     }
  196.     return 1;
  197. }
  198.  
  199. CMD:e_help(playerid, params[])
  200. {
  201.     SendClientMessage(playerid, COLOR_YELLOW, "* Explosion commands:");
  202.     SendClientMessage(playerid, COLOR_INFO, " /plant, /detonate, /cancel, /radius, /type.");
  203.     SendClientMessage(playerid, COLOR_ERROR, "* Usage:");
  204.     SendClientMessage(playerid, COLOR_INFO, " Use /plant and press the walk key to plant a bomb. After you plant all the bombs you wanted,");
  205.     SendClientMessage(playerid, COLOR_INFO, " type /detonate and press the walk key to activate the bombs. If you don't want to continue,");
  206.     SendClientMessage(playerid, COLOR_INFO, " type /cancel, it will remove all the explosives and it will quit the detonation.");
  207.     SendClientMessage(playerid, COLOR_INFO, " Use /radius to change your explosions radius and /type to change your explosions type.");
  208.     return 1;
  209. }
  210.  
  211. CMD:radius(playerid, params[])
  212. {
  213.     if(isnull(params)) return SendClientMessage(playerid, COLOR_ERROR, "* Usage: /radius [value]");
  214.     new
  215.         string[47],
  216.         Float:radius = floatstr(params);
  217.        
  218.     if((radius < 0.1) || (radius > 10000.0)) return SendClientMessage(playerid, COLOR_ERROR, "* The explosion radius has to be between 0.1 and 10000!");
  219.     Player[playerid][explosion_radius] = radius;
  220.     format(string, sizeof(string), "* You have set your explosions radius to %.01f", radius);
  221.     SendClientMessage(playerid, COLOR_SUCCESS, string);
  222.     return 1;
  223. }
  224.  
  225. CMD:type(playerid, params[])
  226. {
  227.     if(isnull(params)) return SendClientMessage(playerid, COLOR_ERROR, "* Usage: /type [value]");
  228.     new
  229.         string[42],
  230.         type = strval(params);
  231.        
  232.     if((type < 0) || (type > 13)) return SendClientMessage(playerid, COLOR_ERROR, "* The explosion type has to be between 0 and 13!");
  233.     Player[playerid][explosion_type] = type;
  234.     format(string, sizeof(string), "* You have set your explosions type to %i", type);
  235.     SendClientMessage(playerid, COLOR_SUCCESS, string);
  236.     return 1;
  237. }
  238.  
  239. CMD:plant(playerid, params[])
  240. {
  241.     if(Player[playerid][planting] == true)
  242.     {
  243.         SendClientMessage(playerid, COLOR_ERROR, "* You are already planting the bombs!");
  244.         SendClientMessage(playerid, COLOR_INFO, "* Use the walk key to plant bombs.");
  245.     }
  246.     else if(Player[playerid][used_charges] >= (MAX_PLAYER_CHARGES))
  247.     {
  248.         SendClientMessage(playerid, COLOR_ERROR, "* You have already used all your bombs, now you have to detonate them!");
  249.         SendClientMessage(playerid, COLOR_INFO, "* If you don't want to detonate them, type /cancel.");
  250.     }
  251.     else if(Player[playerid][detonating] == true)
  252.     {
  253.         Player[playerid][planting] = true;
  254.         Player[playerid][detonating] = false;
  255.         SendClientMessage(playerid, COLOR_SUCCESS, "* You are now planting more bombs.");
  256.     }
  257.     else
  258.     {
  259.         for(new i = 0; i < (MAX_PLAYERS * MAX_PLAYER_CHARGES); i += 32)
  260.         {
  261.             if(Charge[i][user] == -1)
  262.             {
  263.                 Charge[i][user] = playerid;
  264.                 Player[playerid][first_charge] = i;
  265.                 break;
  266.             }
  267.         }
  268.         Player[playerid][planting] = true;
  269.         Player[playerid][detonating] = false;
  270.         SendClientMessage(playerid, COLOR_SUCCESS, "* You are now planting bombs!");
  271.         SendClientMessage(playerid, COLOR_INFO, "* Use the walk key to plant bombs.");
  272.     }
  273.     return 1;
  274. }
  275.  
  276. CMD:detonate(playerid, params[])
  277. {
  278.     if(Player[playerid][detonating] == true) return SendClientMessage(playerid, COLOR_ERROR, "* You are already detonating the bombs!");
  279.     else if(Player[playerid][used_charges] < 1)
  280.     {
  281.         SendClientMessage(playerid, COLOR_ERROR, "* You have not planted any bomb!");
  282.         if(Player[playerid][planting] == false) return SendClientMessage(playerid, COLOR_INFO, "* If you want to start planting bombs, type /plant.");
  283.         else return SendClientMessage(playerid, COLOR_INFO, "* Use the walk key to plant bombs.");
  284.     }
  285.     else
  286.     {
  287.         Player[playerid][detonating] = true;
  288.         Player[playerid][planting] = false;
  289.         SendClientMessage(playerid, COLOR_SUCCESS, "* You are now detonating the bombs!");
  290.         SendClientMessage(playerid, COLOR_INFO, "* Use the walk key to detonate the bombs.");
  291.         SendClientMessage(playerid, COLOR_INFO, "* If you are in a vehicle, you can alternatively use the sub-mission key.");
  292.     }
  293.     return 1;
  294. }
  295.  
  296. CMD:cancel(playerid, params[])
  297. {
  298.     if(Player[playerid][detonating] == false)
  299.     {
  300.         if(Player[playerid][planting] == false) return SendClientMessage(playerid, COLOR_ERROR, "* You are not even planting or detonating any bomb!");
  301.         else
  302.         {
  303.             for(new i = Player[playerid][first_charge]; i < (Player[playerid][first_charge] + Player[playerid][used_charges]); i ++)
  304.             {
  305.                 Charge[i][x] = 0.0;
  306.                 Charge[i][y] = 0.0;
  307.                 Charge[i][z] = 0.0;
  308.                 Charge[i][user] = -1;
  309.             }
  310.             Player[playerid][first_charge] = -1;
  311.             Player[playerid][used_charges] = 0;
  312.             Player[playerid][planting] = false;
  313.             SendClientMessage(playerid, COLOR_WARNING, "* You have cancelled the bombs planting!");
  314.         }
  315.     }
  316.     else
  317.     {
  318.         for(new i = Player[playerid][first_charge]; i < (Player[playerid][first_charge] + Player[playerid][used_charges]); i ++)
  319.         {
  320.             Charge[i][x] = 0.0;
  321.             Charge[i][y] = 0.0;
  322.             Charge[i][z] = 0.0;
  323.             Charge[i][user] = -1;
  324.         }
  325.         Player[playerid][first_charge] = -1;
  326.         Player[playerid][used_charges] = 0;
  327.         Player[playerid][detonating] = false;
  328.         SendClientMessage(playerid, COLOR_WARNING, "* You have cancelled the bombs detonation!");
  329.     }
  330.     return 1;
  331. }
  332.  
  333. stock ResetPlayerChargesInfo(playerid)
  334. {
  335.     for(new i = Player[playerid][first_charge]; i < (Player[playerid][first_charge] + Player[playerid][used_charges]); i ++)
  336.     {
  337.         Charge[i][x] = 0.0;
  338.         Charge[i][y] = 0.0;
  339.         Charge[i][z] = 0.0;
  340.         Charge[i][user] = -1;
  341.     }
  342.     Player[playerid][planting] = false;
  343.     Player[playerid][detonating] = false;
  344.     Player[playerid][settingup] = false;
  345.     Player[playerid][used_charges] = 0;
  346.     Player[playerid][first_charge] = -1;
  347.     Player[playerid][explosion_type] = DEFAULT_TYPE;
  348.     Player[playerid][explosion_radius] = DEFAULT_RADIUS;
  349. }
  350.  
  351. stock ResetChargesInfo()
  352. {
  353.     for(new i = 0; i < (MAX_PLAYERS * MAX_PLAYER_CHARGES); i ++)
  354.     {
  355.         Charge[i][x] = 0.0;
  356.         Charge[i][y] = 0.0;
  357.         Charge[i][z] = 0.0;
  358.         Charge[i][user] = -1;
  359.     }
  360. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement