Advertisement
Guest User

Explosive Include

a guest
Mar 15th, 2011
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.69 KB | None | 0 0
  1. /*
  2.     Explosive Include V1.0
  3.    
  4.     This include provides some explosion releated functions.
  5.  
  6.     All scripting work was done by Mauzen, msoll(a)web.de, 2011
  7.     Feel free to use this include or to modify it for your own use.
  8.     Do not claim this as your own, or re-release it without my permission.
  9.     Do not remove this comment header.
  10.     Give me some credits if you like (Or not, I cant control it anyways)
  11.    
  12.     native CreateExplosionEx(playerid, Float:x, Float:y, Float:z, Float:radius, Float:maxdamage, type=EXPLOSION_TYPE_MEDIUM, reason=51, playsound=true);
  13.     native DamagePlayer(playerid, Float:amount, damagerid, reason);
  14. */
  15.  
  16.  
  17. #if !defined CreateObject
  18.     #error "Use this include in gamemodes or filterscripts only."
  19. #endif
  20. #if defined EXPLOSIVE_INCLUDED
  21.     #error "Only include this include once to avoid confilcts."
  22. #endif
  23.  
  24. #define EXPLOSIVE_INCLUDED                          (true)
  25.  
  26. /*
  27.     Different defines to support some other includes,
  28.     to provide maximum compatibility
  29. */
  30.  
  31. #if defined MapAndreas_Init                         //MapAndreas is not used yet
  32.     #define MAPANDREAS_AVAILABLE                    (true)
  33. #else
  34.     #define MAPANDREAS_AVAILABLE                    (false)
  35. #endif
  36.  
  37. #if defined foreach
  38.     #define FOREACH_AVAILABLE                       (true)
  39. #else
  40.     #define FOREACH_AVAILABLE                       (false)
  41. #endif
  42.  
  43. #if defined CreateDynamicObject
  44.     #define USE_STREAMER                            (true)
  45. #else
  46.     #define USE_STREAMER                            (false)
  47. #endif
  48.  
  49.  
  50.  
  51. #define EXPLOSION_TYPE_FUEL_CAR                     (0)
  52. #define EXPLOSION_TYPE_LARGE                        (1)
  53. #define EXPLOSION_TYPE_MEDIUM                       (2)
  54. #define EXPLOSION_TYPE_MOLOTOV                      (3)
  55. #define EXPLOSION_TYPE_SMALL                        (4)
  56. #define EXPLOSION_TYPE_TINY                         (5)
  57.  
  58.  
  59. // -----------------------------------------------------------------------------
  60. // ---------------------------- MAIN STOCKS ------------------------------------
  61.  
  62. /*
  63.     The main function of this include
  64.     Creates an explosion with a lot of custom parameters
  65.    
  66.         playerid:       "Owner" of the explosion
  67.         x/z/z:          Coordinates
  68.         radius:         Max. damage radius
  69.         maxdamage:      Max. damage
  70.         type:           Type of the explosion (determines the style)
  71.         reason:         Deathreason for SendDeathMessage if someone is killed
  72.         playsound:      Play an explosion sound to all players or not.
  73.  
  74.         returns:        nothing
  75. */
  76. stock CreateExplosionEx(playerid, Float:x, Float:y, Float:z, Float:radius, Float:maxdamage, type=EXPLOSION_TYPE_MEDIUM, reason=51, playsound=true)
  77. {
  78.     if(type < 0 || type > 5) return;
  79.     new objectid;
  80.     #if (USE_STREAMER == true)
  81.         objectid = CreateDynamicObject(18681 + type, x, y, z - 1.5, 0.0, 0.0, 0.0);
  82.     #else
  83.         objectid = CreateObject(18681 + type, x, y, z - 1.5, 0.0, 0.0, 0.0);
  84.     #endif
  85.     SetTimerEx("DestroyObjectPub", 5000, 0, "i", objectid);
  86.     if(type == 1 || type == 2 || type == 4) CreateExplosion(x, y, z, 13, 0.0);
  87.    
  88.     if(playsound)       //Sound
  89.     {
  90.         #if (FOREACH_AVAILABLE == true)
  91.             foreach(Player, i)
  92.             {
  93.         #else
  94.             for(new i = 0, j = GetMaxPlayers(); i < j; i ++)
  95.             {
  96.                 if(!IsPlayerConnected(playerid)) continue;
  97.         #endif
  98.        
  99.             PlayerPlaySound(i, 1159, x, y, z);
  100.         }
  101.     }
  102.    
  103.     if(maxdamage > 0.0 && radius > 0.0)
  104.     {
  105.         new Float:radiussquare = radius * radius;
  106.         new Float:pdist;
  107.         #if (FOREACH_AVAILABLE == true)
  108.             foreach(Player, i)
  109.             {
  110.         #else
  111.             for(new i = 0, j = GetMaxPlayers(); i < j; i ++)
  112.             {
  113.                 if(!IsPlayerConnected(playerid)) continue;
  114.         #endif
  115.            
  116.             pdist = M_GetPlayerToPointSquare(i, x, y, z);
  117.             if(pdist > radiussquare) continue;
  118.             pdist = floatsqroot(pdist);
  119.             DamagePlayer(i, (1 - (pdist / radius)) * maxdamage, playerid, reason);
  120.         }
  121.    
  122.     }
  123. }
  124.  
  125.  
  126. // -----------------------------------------------------------------------------
  127. // ------------------------- GENERAL FUNCTIONS ---------------------------------
  128.  
  129. stock DamagePlayer(playerid, Float:amount, damagerid, reason)
  130. {
  131.     new Float:armour, Float:health;
  132.    
  133.     if(IsPlayerInAnyVehicle(playerid))
  134.     {
  135.         amount *= 2.5;
  136.         GetVehicleHealth(GetPlayerVehicleID(playerid), health);
  137.         SetVehicleHealth(GetPlayerVehicleID(playerid), health - amount);
  138.         if(health - amount <= 250.0)
  139.         {
  140.             // Damage destroyed the vehicle
  141.             SetPVarInt(playerid, "ExpDamager", damagerid + 1);
  142.             SetPVarInt(playerid, "ExpReason", reason);
  143.             SetTimerEx("ResetCustomDeath", 12500, 0, "i", playerid);
  144.         }
  145.         return;
  146.     }
  147.     GetPlayerHealth(playerid, health);
  148.     GetPlayerArmour(playerid, armour);
  149.    
  150.     if(armour > 0.0)
  151.     {
  152.         if(armour >= amount)
  153.         {
  154.             SetPlayerArmour(playerid, armour - amount);
  155.             amount = 0.0;
  156.         } else
  157.         {
  158.             amount = amount - armour;
  159.             SetPlayerArmour(playerid, 0.0);
  160.         }
  161.     }
  162.     if(amount > 0.0)
  163.     {
  164.         if(amount >= health)
  165.         {
  166.             SetPVarInt(playerid, "ExpDamager", damagerid + 1);
  167.             SetPVarInt(playerid, "ExpReason", reason);
  168.         }
  169.         SetPlayerHealth(playerid, health - amount);
  170.     }
  171. }
  172.  
  173. forward Float:M_GetPlayerToPointSquare(playerid, Float:x, Float:y, Float:z);
  174. stock Float:M_GetPlayerToPointSquare(playerid, Float:x, Float:y, Float:z)
  175. {
  176.     new Float:px, Float:py, Float:pz;
  177.     if(IsPlayerInAnyVehicle(playerid)) GetVehiclePos(GetPlayerVehicleID(playerid), px, py, pz);
  178.         else GetPlayerPos(playerid, px, py, pz);
  179.     px -= x;
  180.     py -= y;
  181.     pz -= z;
  182.  
  183.     return px * px + py + py + pz * pz;
  184. }
  185.  
  186. forward DestroyObjectPub(objectid);
  187. public DestroyObjectPub(objectid)
  188. {
  189.     #if (USE_STREAMER == true)
  190.         DestroyDynamicObject(objectid);
  191.     #else
  192.         DestroyObject(objectid);
  193.     #endif
  194. }
  195.  
  196. forward ResetCustomDeath(playerid);
  197. public ResetCustomDeath(playerid)
  198. {
  199.     SetPVarInt(playerid, "ExpDamager", 0);
  200. }
  201.  
  202. // -----------------------------------------------------------------------------
  203. // --------------------------- CALLBACK HOOKS ----------------------------------
  204.  
  205. /*
  206.     Put this somewhere in your main() function
  207. */
  208. stock EXPL_main()
  209. {
  210.     print("Running Mauzen's \"Explosive Include V1.0\"");
  211.     new text[64];
  212.     format(text, sizeof(text), "MapAndreas: %d, foreach: %d, Streamer: %d", MAPANDREAS_AVAILABLE, FOREACH_AVAILABLE, USE_STREAMER);
  213.     print(text);
  214. }
  215.  
  216. /*
  217.     Put this at the top(!) of your OnPlayerDeath function
  218. */
  219. stock EXPL_OnPlayerDeath(playerid, &killerid, &reason)
  220. {
  221.     if(killerid == INVALID_PLAYER_ID)
  222.     {
  223.         if(GetPVarInt(playerid, "ExpDamager") > 0)
  224.         {
  225.             killerid = GetPVarInt(playerid, "ExpDamager") - 1;
  226.             reason = GetPVarInt(playerid, "ExpReason");
  227.             SetPVarInt(playerid, "ExpDamager", 0);
  228.         }
  229.         if(killerid == playerid) killerid = INVALID_PLAYER_ID;
  230.     }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement