FlacoBey

Untitled

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