FlacoBey

Untitled

Dec 24th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.14 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. /*[----->|BOT PISTOL AMMO|<-----]*/
  53. public void OnGameFrame()
  54. {
  55.     int iFrameskip = 0;
  56.     iFrameskip = (iFrameskip + 1) % MAX_FRAMECHECK;
  57.     if(iFrameskip != 0 || !IsServerProcessing())
  58.         return;
  59.  
  60.     for (int client = 1; client <= MaxClients; client++)
  61.     {
  62.         if (!IsSurvivor(client) || !IsPlayerAlive(client) || !IsFakeClient(client))
  63.             continue;
  64.        
  65.        
  66.         int Weapon = GetPlayerWeaponSlot(client, 1);
  67.         if (Weapon == -1) continue;
  68.  
  69.         char sWeapon[32];
  70.         GetEntityClassname(Weapon, sWeapon, sizeof(sWeapon));
  71.  
  72.         int AmmoType = GetEntProp(Weapon, Prop_Data, "m_iPrimaryAmmoType");    
  73.         int Ammo = GetEntProp(client, Prop_Send, "m_iAmmo", _, AmmoType);
  74.        
  75.         if (StrEqual(sWeapon, "weapon_pistol"))
  76.         {
  77.             if (AmmoType == -1) continue;
  78.            
  79.             if (Ammo == 0)
  80.                 SetEntProp(client, Prop_Send, "m_iAmmo", 15, _, AmmoType);
  81.         }
  82.         if (StrEqual(sWeapon, "weapon_pistol", false) && GetEntProp(Weapon, Prop_Send, "m_hasDualWeapons"))
  83.         {
  84.             if (AmmoType == -1) continue;
  85.            
  86.             if (Ammo == 0)
  87.             {
  88.                 SetEntProp(client, Prop_Send, "m_iAmmo", 30, _, AmmoType);
  89.             }
  90.         }
  91.         if  (StrEqual(sWeapon, "weapon_pistol_magnum", false))
  92.         {
  93.             SetEntProp(client, Prop_Send, "m_iAmmo", 8, _, AmmoType);
  94.         }
  95.     }
  96. }
  97.  
  98. public Action Event_Ammo_Pickup(Event event, const char[] name, bool dontBroadcast)
  99. {
  100.     int client = GetClientOfUserId(event.GetInt("userid"));
  101.     if (!IsSurvivor(client) || !IsPlayerAlive(client)) return;
  102.  
  103.     int AmmoPile = event.GetInt("targetid");
  104.     if (!IsValidEntity(AmmoPile)) return;
  105.  
  106.     char sWeapon[32];
  107.     GetEntityClassname(AmmoPile, sWeapon, sizeof(sWeapon));
  108.  
  109.     if (!StrEqual(sWeapon, "weapon_ammo_spawn", false))
  110.         return;
  111.  
  112.     int Weapon = GetPlayerWeaponSlot(client, 1);
  113.     if (Weapon == -1) return;
  114.  
  115.     GetEntityClassname(Weapon, sWeapon, sizeof(sWeapon));
  116.  
  117.     if (!(StrEqual(sWeapon, "weapon_pistol", false) || StrEqual(sWeapon, "weapon_pistol_magnum", false)))
  118.         return;
  119.  
  120.     float cPos[3];
  121.     GetEntPropVector(client, Prop_Data, "m_vecAbsOrigin", cPos);
  122.  
  123.     float aPos[3];
  124.     GetEntPropVector(AmmoPile, Prop_Data, "m_vecAbsOrigin", aPos);
  125.  
  126.     if (GetVectorDistance(cPos, aPos) <= 100)
  127.     {
  128.         bPistol[client] = true; //FIXES WEAPON EMPTY MESSAGE IN AMMO LOCK TIMER
  129.  
  130.         int AmmoType = GetEntProp(Weapon, Prop_Data, "m_iPrimaryAmmoType");
  131.         if (AmmoType == -1) return;
  132.        
  133.         int Clip = GetEntProp(Weapon, Prop_Send, "m_iClip1");
  134.  
  135.         if (StrEqual(sWeapon, "weapon_pistol", false) && GetEntProp(Weapon, Prop_Send, "m_hasDualWeapons"))
  136.         {
  137.             SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip);
  138.             SetEntProp(client, Prop_Send, "m_iAmmo", 30, _, AmmoType);
  139.         }
  140.         else if (StrEqual(sWeapon, "weapon_pistol", false))
  141.         {
  142.  
  143.             SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip);
  144.             SetEntProp(client, Prop_Send, "m_iAmmo", 15, _, AmmoType);
  145.         }
  146.  
  147.         if (StrEqual(sWeapon, "weapon_pistol_magnum", false))
  148.         {
  149.             SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip);
  150.             SetEntProp(client, Prop_Send, "m_iAmmo", 16, _, AmmoType);
  151.         }
  152.     }
  153. }
  154.  
  155. stock bool IsValidAdmin(int client)
  156. {
  157.     if (GetUserFlagBits(client) & ADMFLAG_ROOT) return true;
  158.     return false;
  159. }
  160.  
  161. stock bool IsValidClient(int client)
  162. {
  163.     if (client > 0 && client <= MaxClients && IsClientInGame(client)) return true;
  164.     return false;
  165. }
  166.  
  167. stock bool IsSpectator(int client)
  168. {
  169.     if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 1) return true;
  170.     return false;
  171. }
  172.  
  173. stock bool IsSurvivor(int client)
  174. {
  175.     if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2) return true;
  176.     return false;
  177. }
  178.  
  179. stock bool IsInfected(int client)
  180. {
  181.     if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 3) return true;
  182.     return false;
  183. }
Advertisement
Add Comment
Please, Sign In to add comment