FlacoBey

Untitled

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