IlanZiin

[FS] System MedKit 1.0V (English)

Jan 4th, 2018
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.21 KB | None | 0 0
  1. /* ***********************************************************************************************************
  2.  
  3.                                     FilterScript created by: IlanZ
  4.  
  5.                                     Skype: ilan.silva11
  6.  
  7.                                     (Do not take the credits)
  8.  
  9.    ***********************************************************************************************************
  10. */
  11. #include <a_samp>
  12. #include <zcmd>
  13.  
  14. #define MAX_MEDKITS         (10)
  15. #define DURABILITY_MEDKIT (10)
  16.  
  17. public OnFilterScriptInit()
  18. {
  19.     print("\n--------------------------------------");
  20.     print(" FilterScript MedKit 1.0v Uploaded. By: IlanZ");
  21.     print("--------------------------------------\n");
  22.  
  23.     SetTimer("MedKit", 1000, true);
  24.     return 1;
  25. }
  26.  
  27. enum MedKitEnum
  28. {
  29.     mID,
  30.     mOwner[MAX_PLAYER_NAME],
  31.     Float:mX,
  32.     Float:mY,
  33.     Float:mZ,
  34.     mDurability, // default: 10
  35.     mObjects[2],
  36.     bool:mActive
  37. }
  38.  
  39. new MedKitData[MAX_MEDKITS][MedKitEnum];
  40. new bool:MedKitZ[MAX_PLAYERS], MedKitZID[MAX_PLAYERS];
  41.  
  42. public OnPlayerConnect(playerid)
  43. {
  44.     SpawnPlayer(playerid);
  45.     return 1;
  46. }
  47. public OnPlayerDisconnect(playerid, reason)
  48. {
  49.     DestroyMedKit(MedKitZID[playerid]);
  50.     return 1;
  51. }
  52.  
  53. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  54. {
  55.     if(newkeys == KEY_SECONDARY_ATTACK)
  56.     {
  57.         cmd_infomedkit(playerid);
  58.     }
  59.     return 1;
  60. }
  61.  
  62. forward MedKit();
  63. public MedKit()
  64. {
  65.     for(new i, z = GetPlayerPoolSize(); i <= z; ++i)
  66.     {
  67.         DetectMedKit(i);
  68.     }
  69.     return 1;
  70. }
  71.  
  72. DetectMedKit(playerid)
  73. {
  74.     new Float:Health, Float:Armour;
  75.     GetPlayerHealth(playerid, Health);
  76.     GetPlayerArmour(playerid, Armour);
  77.     for(new i; i < MAX_MEDKITS; i++)
  78.     {
  79.         if(IsPlayerInRangeOfPoint(playerid, 1.0, MedKitData[i][mX], MedKitData[i][mY], MedKitData[i][mZ]) && MedKitData[i][mActive])
  80.         {
  81.             if(Health >= 100 && Armour >= 100) continue;
  82.             else if(Health < 100)
  83.             {
  84.                 SetPlayerHealth(playerid, (Health+7));
  85.                 PlayerPlaySound(playerid, 5202, 0.0, 0.0, 0.0);
  86.                 MedKitData[i][mDurability]--;
  87.             }
  88.             else if(Health >= 100)
  89.             {
  90.                 SetPlayerArmour(playerid, (Armour+7));
  91.                 PlayerPlaySound(playerid, 5202, 0.0, 0.0, 0.0);
  92.                 MedKitData[i][mDurability]--;
  93.             }
  94.  
  95.             if(MedKitData[i][mDurability] == 0)
  96.             {
  97.                 DestroyMedKit(MedKitData[i][mID]);
  98.                 MedKitZ[playerid] = false;
  99.                 PlayerPlaySound(playerid, 6402, 0.0, 0.0, 0.0);
  100.                 SendClientMessage(playerid, -1, "Medkit broke!");
  101.             }
  102.         }
  103.     }
  104.     return 1;
  105. }
  106.  
  107. CMD:medkit(playerid)
  108. {
  109.     new Float:X, Float:Y, Float:Z, medkitid;
  110.     if(MedKitZ[playerid])
  111.         return SendClientMessage(playerid, -1, "You can only create a medkit");
  112.     if(GetTotalMedKits() > MAX_MEDKITS)
  113.         return SendClientMessage(playerid, -1, "You can not create now, you have reached the limit");
  114.     GetPlayerPos(playerid,X,Y,Z);
  115.     MedKitData[medkitid][mID] = playerid;
  116.     medkitid = MedKitData[medkitid][mID];
  117.  
  118.     MedKitData[medkitid][mActive] = true;
  119.     MedKitData[medkitid][mX] = X;
  120.     MedKitData[medkitid][mY] = Y;
  121.     MedKitData[medkitid][mZ] = Z;
  122.     MedKitData[medkitid][mDurability] = DURABILITY_MEDKIT; // default
  123.     MedKitData[medkitid][mObjects][0] = CreateObject(19605, X, Y, Z-2.0, 0, 0, 0);
  124.     MedKitData[medkitid][mObjects][1] = CreatePickup(1240, 1, X, Y, Z);
  125.     MedKitZ[playerid] = true;
  126.     MedKitZID[playerid] = medkitid;
  127.     strcat(MedKitData[medkitid][mOwner], PlayerName(playerid), MAX_PLAYER_NAME);
  128.  
  129.     SendClientMessage(playerid, -1, "Medkit created");
  130.     return 1;
  131. }
  132.  
  133. CMD:infomedkit(playerid)
  134. {
  135.     for(new i; i < MAX_MEDKITS; i++)
  136.     {
  137.         if(IsPlayerInRangeOfPoint(playerid, 1.0, MedKitData[i][mX], MedKitData[i][mY], MedKitData[i][mZ]) && MedKitData[i][mActive])
  138.         {
  139.             new str[138];
  140.             format(str, sizeof(str), "Medkit ID: %d\nMedKit X: %.2f\nMedKit Y: %.2f\nMedKit Z: %.2f\nMedKit Durability: (%d/10)\nMedKit Owner: %s",
  141.             MedKitData[i][mID],
  142.             MedKitData[i][mX],
  143.             MedKitData[i][mY],
  144.             MedKitData[i][mZ],
  145.             MedKitData[i][mDurability],
  146.             MedKitData[i][mOwner]);
  147.             ShowPlayerDialog(playerid, 666, DIALOG_STYLE_MSGBOX, "MedKit Information", str, "Exit", "");
  148.         }
  149.     }
  150.     return 1;
  151. }
  152.  
  153. CMD:destroymedkit(playerid)
  154. {
  155.     DestroyMedKit(playerid);
  156.     MedKitZ[playerid] = false;
  157.  
  158.     SendClientMessage(playerid, -1, "You've destroyed your medkit");
  159.     return 1;
  160. }
  161.  
  162. DestroyMedKit(medkitid)
  163. {
  164.     MedKitData[medkitid][mID] = -1;
  165.     MedKitData[medkitid][mActive] = false;
  166.     MedKitData[medkitid][mOwner][0] = EOS;
  167.  
  168.     DestroyObject(MedKitData[medkitid][mObjects][0]);
  169.     DestroyPickup(MedKitData[medkitid][mObjects][1]);
  170.     return 1;
  171. }
  172.  
  173. GetTotalMedKits()
  174. {
  175.     new total;
  176.     for(new i; i < MAX_MEDKITS; i++)
  177.     {
  178.         if(MedKitData[i][mActive]) total++;
  179.     }
  180.     return total;
  181. }
  182.  
  183. PlayerName(playerid)
  184. {
  185.     new nome[24];
  186.     GetPlayerName(playerid, nome, sizeof(nome));
  187.     return nome;
  188. }
Advertisement
Add Comment
Please, Sign In to add comment