Lyonkrs

damage system

May 23rd, 2021
915
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=====================INCLUDES=====================
  2.  
  3. #include    <a_samp>
  4. #include    <zcmd>
  5. #include    <sscanf2>
  6.  
  7. //=====================DIALOGS======================
  8.  
  9. #define     DIALOG_DAMAGE       1927
  10.  
  11. //==================CONTROL PANEL===================
  12.  
  13. #define     FILTERSCRIPT
  14. #define     MAX_DAMAGES         10 //Maximum damage, not 1000000000000000.
  15.  
  16. #define     SCM                 SendClientMessage
  17. #define     SNM                 SendNearMessage
  18. #define     FORMAT:%0(%1)       format(%0, sizeof(%0), %1)
  19.  
  20. #define     BODY_PART_TORSO     3
  21. #define     BODY_PART_GROIN     4
  22. #define     BODY_PART_RIGHT_ARM 5
  23. #define     BODY_PART_LEFT_ARM  6
  24. #define     BODY_PART_RIGHT_LEG 7
  25. #define     BODY_PART_LEFT_LEG  8
  26. #define     BODY_PART_HEAD      9
  27.  
  28. //===================ENUMERATORS====================
  29.  
  30. enum dmgInfo
  31. {
  32.     dmgDamage,
  33.     dmgWeapon,
  34.     dmgBodypart,
  35.     dmgKevlarhit,
  36.     dmgSeconds,
  37. }
  38. new DamageInfo[MAX_PLAYERS][MAX_DAMAGES][dmgInfo];
  39.  
  40. public OnFilterScriptInit()
  41. {
  42.     print("\n ==================================");
  43.     print(" |                                |");
  44.     print(" |          Damage System         |");
  45.     print(" |           By Hreesang          |");
  46.     print(" |                                |");
  47.     print(" ==================================\n");
  48.     return 1;
  49. }
  50.  
  51. public OnFilterScriptExit()
  52. {
  53.     return 1;
  54. }
  55.  
  56. stock ResetPlayerDamages(playerid)
  57. {
  58.     for(new id = 0; id < MAX_DAMAGES; id++)
  59.     {
  60.         if(DamageInfo[playerid][id][dmgDamage] != 0)
  61.         {
  62.             DamageInfo[playerid][id][dmgDamage] = 0;
  63.             DamageInfo[playerid][id][dmgWeapon] = 0;
  64.             DamageInfo[playerid][id][dmgBodypart] = 0;
  65.             DamageInfo[playerid][id][dmgKevlarhit] = 0;
  66.             DamageInfo[playerid][id][dmgSeconds] = 0;
  67.         }
  68.     }
  69.     return 1;
  70. }
  71.  
  72. public OnPlayerConnect(playerid)
  73. {
  74.     ResetPlayerDamages(playerid);
  75.     return 1;
  76. }
  77.  
  78. public OnPlayerDeath(playerid, killerid, reason)
  79. {
  80.     ResetPlayerDamages(playerid); //you can delete this if you're want to put on roleplay gamemode
  81.     return 1;
  82. }
  83.  
  84. public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
  85. {
  86.     if(IsPlayerConnected(playerid))
  87.     {
  88.         new
  89.             Float: pHP,
  90.             Float: pArm,
  91.             id;
  92.  
  93.         GetPlayerHealth(playerid, pHP);
  94.         GetPlayerArmour(playerid, pArm);
  95.         for(new i = 0; i < MAX_DAMAGES; i++)
  96.         {
  97.             if(!DamageInfo[playerid][i][dmgDamage])
  98.             {
  99.                 id = i;
  100.                 break;
  101.             }
  102.         }
  103.        
  104.         DamageInfo[playerid][id][dmgDamage] = floatround(amount, floatround_round);
  105.         DamageInfo[playerid][id][dmgWeapon] = weaponid;
  106.         DamageInfo[playerid][id][dmgBodypart] = bodypart;
  107.         if(pArm > 0) DamageInfo[playerid][id][dmgKevlarhit] = 1;
  108.         else if(pArm < 1) DamageInfo[playerid][id][dmgKevlarhit] = 0;
  109.         DamageInfo[playerid][id][dmgSeconds] = gettime();
  110.     }
  111.     return 1;
  112. }
  113.  
  114. stock ShowPlayerDamages(playerid, toid)
  115. {
  116.     new
  117.         str[1000],
  118.         str1[500],
  119.         count = 0,
  120.         name[MAX_PLAYER_NAME];
  121.  
  122.     GetPlayerName(playerid, name, sizeof(name));
  123.     for(new id = 0; id < MAX_DAMAGES; id++)
  124.     {
  125.         if(DamageInfo[playerid][id][dmgDamage] != 0) count++;
  126.     }
  127.     if(count == 0) return ShowPlayerDialog(toid, DIALOG_DAMAGE, DIALOG_STYLE_LIST, name, "There is no damage to display...", "Close", "");
  128.     else if(count > 0)
  129.     {
  130.         for(new id = 0; id < MAX_DAMAGES; id++)
  131.         {
  132.             if(DamageInfo[playerid][id][dmgDamage] != 0)
  133.             {
  134.                 FORMAT:str1("%d dmg from %s to %s (Kevlarhit: %d) %d s ago\n", DamageInfo[playerid][id][dmgDamage], GetWeaponNameEx(DamageInfo[playerid][id][dmgWeapon]), GetBodypartName(DamageInfo[playerid][id][dmgBodypart]), DamageInfo[playerid][id][dmgKevlarhit], gettime() - DamageInfo[playerid][id][dmgSeconds]);
  135.                 strcat(str, str1);
  136.             }
  137.             else if(DamageInfo[playerid][id][dmgDamage] != 0 && id >= MAX_DAMAGES)
  138.             {
  139.                 FORMAT:str1("You seems taking to many damage....");
  140.                 strcat(str, str1);
  141.             }
  142.         }
  143.         ShowPlayerDialog(toid, DIALOG_DAMAGE, DIALOG_STYLE_LIST, name, str, "Close", "");
  144.     }
  145.     return 1;
  146. }
  147.  
  148. stock GetName(playerid)
  149. {
  150.     new name;
  151.     GetPlayerName(playerid, name, sizeof(name));
  152.     return name;
  153. }
  154.  
  155.  
  156. stock GetWeaponNameEx(weaponid)
  157. {
  158.     new weaponname[60];
  159.     GetWeaponName(weaponid, weaponname, sizeof(weaponname));
  160.     return weaponname;
  161. }
  162.  
  163. stock GetBodypartName(bodypart)
  164. {
  165.     new bodyname[60];
  166.     switch(bodypart)
  167.     {
  168.         case BODY_PART_TORSO: FORMAT:bodyname("TORSO");
  169.         case BODY_PART_GROIN: FORMAT:bodyname("GROIN");
  170.         case BODY_PART_RIGHT_ARM: FORMAT:bodyname("RIGHT ARM");
  171.         case BODY_PART_LEFT_ARM: FORMAT:bodyname("LEFT ARM");
  172.         case BODY_PART_RIGHT_LEG: FORMAT:bodyname("RIGHT ARM");
  173.         case BODY_PART_LEFT_LEG: FORMAT:bodyname("LEFT LEG");
  174.         case BODY_PART_HEAD: FORMAT:bodyname("HEAD");
  175.     }
  176.     return bodyname;
  177. }
  178.  
  179. stock SendNearMessage(playerid, Float:range, color, const msg[])
  180. {
  181.     static
  182.          Float: exPos[MAX_PLAYERS][3];
  183.        
  184.     foreach(new i : Player)
  185.     {
  186.         GetPlayerPos(i, exPos[i][0], exPos[i][1], exPos[i][2]);
  187.         if(IsPlayerInRangeOfPoint(i, range, exPos[i][0], exPos[i][1], exPos[i][2]))
  188.             return SendClientMessage(i, color, msg);
  189.     }
  190.     return 1;
  191. }
  192.  
  193. CMD:checkdamages(playerid, params[])
  194. {
  195.     new
  196.         Float: pPos[3],
  197.         id;
  198.  
  199.     if(sscanf(params, "u", id))
  200.         return SCM(playerid, 0xFF6347FF, "USAGE: {FFFFFF}/checkdamages [playerid/PartOfName]");
  201.  
  202.     if(!IsPlayerConnected(id))
  203.         return SCM(playerid, 0xFF6347FF, "Invalid playerid.");
  204.    
  205.     if(IsPlayerAdmin(playerid)) //change this whatever
  206.     {
  207.         ShowPlayerDamages(id, playerid);
  208.         SendClientMessage(playerid, 0xFF6347FF, "Showing a playerID: "id" damages");
  209.     }
  210.     else
  211.     {
  212.         GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
  213.         if(!IsPlayerInRangeOfPoint(playerid, 7.0, pPos[0], pPos[1], pPos[2]))
  214.              return SCM(playerid, 0xB8BAC6FF, "You're too far away.");
  215.  
  216.         ShowPlayerDamages(id, playerid);
  217.     }
  218.     return 1;
  219. }
  220.  
  221. CMD:damages(playerid, params[])
  222. {
  223.     ShowPlayerDamages(playerid, playerid);
  224.     return 1;
  225. }
  226.  
  227. //useful command from medic lol
  228. CMD:beginoperate(playerid, params[])
  229. {
  230.     new rp[64];
  231.     if(sscanf(params, "u", pid))
  232.         return SCM(playerid, 0xFF6347FF, "USAGE: {FFFFFF}/beginoperate [playerid/PartOFName]");
  233.  
  234.     if(!IsPlayerConnected(pid))
  235.         return SCM(playerid, 0xFF6347FF, "Invalid playerid.");
  236.  
  237.     FORMAT:rp("%s began the operation to remove bullets from the patient's body.", GetName(playerid));
  238.     SNM(playerid, 3.0, 0xD0AEEBFF, rp);
  239.  
  240.     /*
  241.     You can just add some timers like below!
  242.     SCM(pid, 0xFF6347FF, "OPERATE: {FFFFFF}Please do not move from your position!");
  243.     SetTimerEx("OnPlayerNotMoving", 5000, false, "i", pid);
  244.     GetPlayerPos(pid, pidPos[pid][0], pidPos[pid][1], pidPos[pid][2]);
  245.     */
  246.     ResetPlayerDamages(pid);
  247.     return 1;
  248. }
  249.  
  250. /*
  251. forward OnPlayerNotMoving(playerid);
  252. public OnPlayerNotMoving(playerid)
  253. {
  254.     if(pidPos[playerid][0] > 2.0 || pidPos[playerid][1] > 2.0 || pidPos[playerid][2] > 2.0)
  255.         return SCM(playerid, 0xFF6347FF, "Failed to began the operation because patient are moving!");
  256.  
  257.     ResetPlayerDamages(playerid);
  258.     return 1;
  259. }
  260. */
RAW Paste Data