FlacoBey

Untitled

Feb 17th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.28 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.     if(IsValidEntity(iCurrentWeapon))
  61.     {
  62.         char sWeaponEx[32];
  63.         GetEntityClassname(iCurrentWeapon, sWeaponEx, sizeof(sWeaponEx));
  64.         if(StrEqual(sWeaponEx, "weapon_pistol") || StrEqual(sWeaponEx, "weapon_pistol_magnum"))
  65.         {
  66.             for(new iChannel = 0; iChannel < MAX_CHANNELS; iChannel++)
  67.             {
  68.                 char sAmmoEx[32];
  69.                 int AmmoType = GetEntProp(iCurrentWeapon, Prop_Data, "m_iPrimaryAmmoType");    
  70.                 int Ammo = GetEntProp(client, Prop_Send, "m_iAmmo", _, AmmoType);
  71.                 int Clip = GetEntProp(iCurrentWeapon, Prop_Send, "m_iClip1");
  72.                 Format(sAmmoEx, sizeof(sAmmoEx), "Обойма: %i Запасе:%i", Clip, Ammo);
  73.                 SetHudTextParams(-1.0, -1.0, 10.0, 255, 64, 64, 255, 2);
  74.                 g_hHudSync[iChannel] = CreateHudSynchronizer();
  75.                 ShowSyncHudText(client, g_hHudSync[iChannel], "%i");
  76.             }
  77.         }
  78.     }
  79. }
  80.  
  81. /*[----->|BOT PISTOL AMMO|<-----]*/
  82. public void OnGameFrame()
  83. {
  84.     int iFrameskip = 0;
  85.     iFrameskip = (iFrameskip + 1) % MAX_FRAMECHECK;
  86.     if(iFrameskip != 0 || !IsServerProcessing())
  87.         return;
  88.  
  89.     for (int client = 1; client <= MaxClients; client++)
  90.     {
  91.         if (!IsSurvivor(client) || !IsPlayerAlive(client) || !IsFakeClient(client))
  92.             continue;
  93.        
  94.        
  95.         int Weapon = GetPlayerWeaponSlot(client, 1);
  96.         if (Weapon == -1) continue;
  97.  
  98.         char sWeapon[32];
  99.         GetEntityClassname(Weapon, sWeapon, sizeof(sWeapon));
  100.  
  101.         int AmmoType = GetEntProp(Weapon, Prop_Data, "m_iPrimaryAmmoType");    
  102.         int Ammo = GetEntProp(client, Prop_Send, "m_iAmmo", _, AmmoType);
  103.        
  104.         if (StrEqual(sWeapon, "weapon_pistol"))
  105.         {
  106.             if (AmmoType == -1) continue;
  107.            
  108.             if (Ammo == 0)
  109.                 SetEntProp(client, Prop_Send, "m_iAmmo", 15, _, AmmoType);
  110.         }
  111.         if (StrEqual(sWeapon, "weapon_pistol", false) && GetEntProp(Weapon, Prop_Send, "m_hasDualWeapons"))
  112.         {
  113.             if (AmmoType == -1) continue;
  114.            
  115.             if (Ammo == 0)
  116.             {
  117.                 SetEntProp(client, Prop_Send, "m_iAmmo", 30, _, AmmoType);
  118.             }
  119.         }
  120.         if  (StrEqual(sWeapon, "weapon_pistol_magnum", false))
  121.         {
  122.             SetEntProp(client, Prop_Send, "m_iAmmo", 8, _, AmmoType);
  123.         }
  124.     }
  125. }
  126.  
  127. public Action Event_Ammo_Pickup(Event event, const char[] name, bool dontBroadcast)
  128. {
  129.     int client = GetClientOfUserId(event.GetInt("userid"));
  130.     if (!IsSurvivor(client) || !IsPlayerAlive(client)) return;
  131.  
  132.     int AmmoPile = event.GetInt("targetid");
  133.     if (!IsValidEntity(AmmoPile)) return;
  134.  
  135.     char sWeapon[32];
  136.     GetEntityClassname(AmmoPile, sWeapon, sizeof(sWeapon));
  137.  
  138.     if (!StrEqual(sWeapon, "weapon_ammo_spawn", false))
  139.         return;
  140.  
  141.     int Weapon = GetPlayerWeaponSlot(client, 1);
  142.     if (Weapon == -1) return;
  143.  
  144.     GetEntityClassname(Weapon, sWeapon, sizeof(sWeapon));
  145.  
  146.     if (!(StrEqual(sWeapon, "weapon_pistol", false) || StrEqual(sWeapon, "weapon_pistol_magnum", false)))
  147.         return;
  148.  
  149.     float cPos[3];
  150.     GetEntPropVector(client, Prop_Data, "m_vecAbsOrigin", cPos);
  151.  
  152.     float aPos[3];
  153.     GetEntPropVector(AmmoPile, Prop_Data, "m_vecAbsOrigin", aPos);
  154.  
  155.     if (GetVectorDistance(cPos, aPos) <= 100)
  156.     {
  157.         bPistol[client] = true; //FIXES WEAPON EMPTY MESSAGE IN AMMO LOCK TIMER
  158.  
  159.         int AmmoType = GetEntProp(Weapon, Prop_Data, "m_iPrimaryAmmoType");
  160.         if (AmmoType == -1) return;
  161.        
  162.         int Clip = GetEntProp(Weapon, Prop_Send, "m_iClip1");
  163.  
  164.         if (StrEqual(sWeapon, "weapon_pistol", false) && GetEntProp(Weapon, Prop_Send, "m_hasDualWeapons"))
  165.         {
  166.             SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip);
  167.             SetEntProp(client, Prop_Send, "m_iAmmo", 120, _, AmmoType);
  168.         }
  169.         else if (StrEqual(sWeapon, "weapon_pistol", false))
  170.         {
  171.  
  172.             SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip);
  173.             SetEntProp(client, Prop_Send, "m_iAmmo", 120, _, AmmoType);
  174.         }
  175.  
  176.         if (StrEqual(sWeapon, "weapon_pistol_magnum", false))
  177.         {
  178.             SetEntProp(Weapon, Prop_Send, "m_iClip1", Clip);
  179.             SetEntProp(client, Prop_Send, "m_iAmmo", 32, _, AmmoType);
  180.         }
  181.     }
  182. }
  183.  
  184. stock bool IsValidAdmin(int client)
  185. {
  186.     if (GetUserFlagBits(client) & ADMFLAG_ROOT) return true;
  187.     return false;
  188. }
  189.  
  190. stock bool IsValidClient(int client)
  191. {
  192.     if (client > 0 && client <= MaxClients && IsClientInGame(client)) return true;
  193.     return false;
  194. }
  195.  
  196. stock bool IsSpectator(int client)
  197. {
  198.     if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 1) return true;
  199.     return false;
  200. }
  201.  
  202. stock bool IsSurvivor(int client)
  203. {
  204.     if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2) return true;
  205.     return false;
  206. }
  207.  
  208. stock bool IsInfected(int client)
  209. {
  210.     if (client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 3) return true;
  211.     return false;
  212. }
Advertisement
Add Comment
Please, Sign In to add comment