Advertisement
FlacoBey

Untitled

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