FlacoBey

Untitled

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