FlacoBey

Untitled

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