Advertisement
FlacoBey

Untitled

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