Guest User

Untitled

a guest
Jul 14th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.50 KB | None | 0 0
  1. #pragma semicolon 1
  2. #pragma newdecls required
  3.  
  4. #include <sourcemod>
  5. #include <sdktools>
  6. #include <sdkhooks>
  7.  
  8. #define MAX_FRAMECHECK 10
  9.  
  10. bool bPistol[MAXPLAYERS+1] = {true, ...};
  11. bool bPistolFix[MAXPLAYERS+1] = {true, ...};
  12.  
  13. public void OnPluginStart()
  14. {
  15. HookEvent("player_use", Event_Ammo_Pickup);
  16. HookEvent("item_pickup", OnItemPickup);
  17. RegConsoleCmd("sm_ammo", iViewAmmo);
  18. AutoExecConfig(true, "l4d_pistol_reloading");
  19. }
  20.  
  21. public Action iViewAmmo(int client, int args)
  22. {
  23. int iCurrentWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
  24. if(!IsValidEntity(iCurrentWeapon)) return Plugin_Handled;
  25.  
  26. char iEntName[56];
  27. GetEdictClassname(iCurrentWeapon, iEntName, sizeof(iEntName));
  28. if (strcmp(iEntName, "weapon_pistol") == 0 || strcmp(iEntName, "weapon_pistol_magnum") == 0)
  29. {
  30. int AmmoSmgType = GetEntProp(iCurrentWeapon, Prop_Data, "m_iPrimaryAmmoType");
  31. if (AmmoSmgType == -1) return Plugin_Continue;
  32. int AmmoSmg = GetEntProp(client, Prop_Send, "m_iAmmo", _, AmmoSmgType);
  33. PrintHintText(client, "Патроны - %i", AmmoSmg);
  34. }
  35. return Plugin_Handled;
  36. }
  37.  
  38. public Action OnItemPickup(Handle event, const char[] name, bool dontBroadcast)
  39. {
  40. int client = GetClientOfUserId(GetEventInt(event, "userid"));
  41.  
  42. char item[36];
  43. GetEventString(event, "item", item, sizeof(item));
  44. if(StrEqual(item ,"grenade_launcher"))
  45. {
  46. PrintHintText(client, "Вы можете восполнить гранаты для гранатамёта из стопки патронов.");
  47. }
  48. else if(StrEqual(item ,"rifle_m60"))
  49. {
  50. PrintHintText(client, "Вы можете восполнить патроны для M60 из стопки патронов.");
  51. }
  52. }
  53.  
  54. public void ConvarChanged(Handle hCvar, const char[] sOldVal, const char[] sNewVal)
  55. {
  56. CvarsChanged();
  57. }
  58.  
  59. public void OnMapStart()
  60. {
  61. CvarsChanged();
  62. }
  63.  
  64. void CvarsChanged()
  65. {
  66. SetConVarInt(FindConVar("ammo_pistol_max"), 0);
  67. }
  68.  
  69. public void OnClientPostAdminCheck(int client)
  70. {
  71. if (IsFakeClient(client)) return;
  72.  
  73. bPistol[client] = true;
  74. bPistolFix[client] = true;
  75.  
  76. SDKHook(client, SDKHook_WeaponEquip, Hook_WeaponEquip);
  77. }
  78.  
  79. public Action Hook_WeaponEquip(int client, int weapon)
  80. {
  81. if (!IsSurvivor(client) || !bPistolFix[client])
  82. return;
  83.  
  84. bPistolFix[client] = false;
  85. }
  86.  
  87. public void OnGameFrame()
  88. {
  89. int iFrameskip = 0;
  90. iFrameskip = (iFrameskip + 1) % MAX_FRAMECHECK;
  91. if(iFrameskip != 0 || !IsServerProcessing())
  92. return;
  93.  
  94. for (int client = 1; client <= MaxClients; client++)
  95. {
  96. if (!IsSurvivor(client) || !IsPlayerAlive(client) || !IsFakeClient(client))
  97. continue;
  98.  
  99.  
  100. int Weapon = GetPlayerWeaponSlot(client, 1);
  101. if (Weapon == -1) continue;
  102.  
  103. char sWeapon[32];
  104. GetEntityClassname(Weapon, sWeapon, sizeof(sWeapon));
  105.  
  106. int AmmoType = GetEntProp(Weapon, Prop_Data, "m_iPrimaryAmmoType");
  107. int Ammo = GetEntProp(client, Prop_Send, "m_iAmmo", _, AmmoType);
  108.  
  109. if (StrEqual(sWeapon, "weapon_pistol"))
  110. {
  111. if (AmmoType == -1) continue;
  112.  
  113. if (Ammo == 0)
  114. SetEntProp(client, Prop_Send, "m_iAmmo", 15, _, AmmoType);
  115. }
  116. if (StrEqual(sWeapon, "weapon_pistol", false) && GetEntProp(Weapon, Prop_Send, "m_hasDualWeapons"))
  117. {
  118. if (AmmoType == -1) continue;
  119.  
  120. if (Ammo == 0)
  121. {
  122. SetEntProp(client, Prop_Send, "m_iAmmo", 30, _, AmmoType);
  123. }
  124. }
  125. if (StrEqual(sWeapon, "weapon_pistol_magnum", false))
  126. {
  127. SetEntProp(client, Prop_Send, "m_iAmmo", 8, _, AmmoType);
  128. }
  129. }
  130. }
  131.  
  132. public Action Event_Ammo_Pickup(Event event, const char[] name, bool dontBroadcast)
  133. {
  134. int client = GetClientOfUserId(event.GetInt("userid"));
  135. if (!IsSurvivor(client) || !IsPlayerAlive(client)) return;
  136.  
  137. int AmmoPile = event.GetInt("targetid");
  138. if (!IsValidEntity(AmmoPile)) return;
  139.  
  140. char sWeapon[32];
  141. GetEntityClassname(AmmoPile, sWeapon, sizeof(sWeapon));
  142.  
  143. if (!StrEqual(sWeapon, "weapon_ammo_spawn", false))
  144. return;
  145.  
  146. int Weapon = GetPlayerWeaponSlot(client, 1);
  147. if (Weapon == -1) return;
  148.  
  149. GetEntityClassname(Weapon, sWeapon, sizeof(sWeapon));
  150.  
  151. if (!(StrEqual(sWeapon, "weapon_pistol", false) || StrEqual(sWeapon, "weapon_pistol_magnum", false)))
  152. return;
  153.  
  154. float cPos[3];
  155. GetEntPropVector(client, Prop_Data, "m_vecAbsOrigin", cPos);
  156.  
  157. float aPos[3];
  158. GetEntPropVector(AmmoPile, Prop_Data, "m_vecAbsOrigin", aPos);
  159.  
  160. if (GetVectorDistance(cPos, aPos) <= 150)
  161. {
  162. bPistol[client] = true;
  163.  
  164. int AmmoType = GetEntProp(Weapon, Prop_Data, "m_iPrimaryAmmoType");
  165. if (AmmoType == -1) return;
  166.  
  167. int Clip = GetEntProp(Weapon, Prop_Send, "m_iClip1");
  168.  
  169. if (StrEqual(sWeapon, "weapon_pistol", false) && GetEntProp(Weapon, Prop_Send, "m_hasDualWeapons"))
  170. {
  171. SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip);
  172. SetEntProp(client, Prop_Send, "m_iAmmo", 150, _, AmmoType);
  173. }
  174. else if (StrEqual(sWeapon, "weapon_pistol", false))
  175. {
  176.  
  177. SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip);
  178. SetEntProp(client, Prop_Send, "m_iAmmo", 150, _, AmmoType);
  179. }
  180.  
  181. if (StrEqual(sWeapon, "weapon_pistol_magnum", false))
  182. {
  183. SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip);
  184. SetEntProp(client, Prop_Send, "m_iAmmo", 32, _, AmmoType);
  185. }
  186. }
  187. }
  188.  
  189. stock bool IsValidAdmin(int client)
  190. {
  191. if (GetUserFlagBits(client) & ADMFLAG_ROOT) return true;
  192. return false;
  193. }
  194.  
  195. stock bool IsValidClient(int client)
  196. {
  197. if (client > 0 && client <= MaxClients && IsClientInGame(client)) return true;
  198. return false;
  199. }
  200.  
  201. stock bool IsSpectator(int client)
  202. {
  203. if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 1) return true;
  204. return false;
  205. }
  206.  
  207. stock bool IsSurvivor(int client)
  208. {
  209. if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2) return true;
  210. return false;
  211. }
  212.  
  213. stock bool IsInfected(int client)
  214. {
  215. if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 3) return true;
  216. return false;
  217. }
Advertisement
Add Comment
Please, Sign In to add comment