MP2

OnPlayerGive/TakeDamage with health/armour loss

MP2
Feb 13th, 2013
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.17 KB | None | 0 0
  1. /*
  2. This simple include allows you to detect how much health/armour is lost in
  3. OnPlayerTakeDamage and OnPlayerGiveDamage, instead of overall 'damage'
  4. (health and armour combined).
  5. */
  6.  
  7. // These are the new callbacks
  8. forward OnPlayerTakeDamageEx(playerid, issuerid, Float:healthloss, Float:armourloss, weaponid);
  9. forward OnPlayerGiveDamageEx(playerid, damagedid, Float:healthloss, Float:armourloss, weaponid);
  10.  
  11.  
  12. // ----------------------------------------------------------------------------
  13.  
  14.  
  15. public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid) // Original callback
  16. {
  17.     new Float:armourloss, Float:healthloss, Float:pArmour;
  18.     GetPlayerArmour(playerid, pArmour);
  19.     if(pArmour != 0) // They had armour, so they MUST have lost some.
  20.     {
  21.         if(amount > pArmour) // They took more damage than what armour they had, so they must have lost ALL of their armour and some health too.
  22.         {
  23.             armourloss = pArmour; // We know they lost all of their armour
  24.             healthloss = amount-pArmour; // What ever is left, was health loss
  25.         }
  26.         else // Just lost armour
  27.         {
  28.             armourloss = amount;
  29.         }
  30.     }
  31.     else healthloss = amount; // They had no armour - hence they only lost health
  32.    
  33.     // Call the new function
  34.     CallLocalFunction("OnPlayerTakeDamageEx", "iiffi", playerid, issuerid, healthloss, armourloss, weaponid);
  35.  
  36.     // HOOKERS
  37.     #if defined OPGTD_OnPlayerTakeDamage
  38.         return OPGTD_OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid);
  39.     #else
  40.         return 1;
  41.     #endif
  42. }
  43. #if defined OPGTD_OnPlayerTakeDamage
  44.     forward OPGTD_OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid);
  45. #endif
  46. #if defined _ALS_OnPlayerTakeDamage
  47.     #undef OnPlayerTakeDamage
  48. #else
  49.     #define _ALS_OnPlayerTakeDamage
  50. #endif
  51. #define OnPlayerTakeDamage OPGTD_OnPlayerTakeDamage
  52.  
  53.  
  54. // ----------------------------------------------------------------------------
  55.  
  56.  
  57. public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid) // Original callback
  58. {
  59.     new Float:armourloss, Float:healthloss, Float:pArmour;
  60.     GetPlayerArmour(damagedid, pArmour);
  61.     if(pArmour != 0) // They had armour, so they MUST have lost some.
  62.     {
  63.         if(amount > pArmour) // They took more damage than what armour they had, so they must have lost ALL of their armour and some health too.
  64.         {
  65.             armourloss = pArmour; // We know they lost all of their armour
  66.             healthloss = amount-pArmour; // What ever is left, was health loss
  67.         }
  68.         else // Just lost armour
  69.         {
  70.             armourloss = amount;
  71.         }
  72.     }
  73.     else healthloss = amount; // They had no armour - hence they only lost health
  74.    
  75.     // Call the new function
  76.     CallLocalFunction("OnPlayerGiveDamageEx", "iiffi", playerid, damagedid, healthloss, armourloss, weaponid);
  77.  
  78.     // HOOKERS
  79.     #if defined OPGTD_OnPlayerGiveDamage
  80.         return OPGTD_OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid);
  81.     #else
  82.         return 1;
  83.     #endif
  84. }
  85. #if defined OPGTD_OnPlayerGiveDamage
  86.     forward OPGTD_OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid);
  87. #endif
  88. #if defined _ALS_OnPlayerGiveDamage
  89.     #undef OnPlayerGiveDamage
  90. #else
  91.     #define _ALS_OnPlayerGiveDamage
  92. #endif
  93. #define OnPlayerGiveDamage OPGTD_OnPlayerGiveDamage
Advertisement
Add Comment
Please, Sign In to add comment