Advertisement
FlacoBey

Untitled

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