Advertisement
FlacoBey

Untitled

Feb 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.07 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #pragma semicolon 1
  4.  
  5. new g_ActiveWeaponOffset;
  6. static bool:buttondelay[MAXPLAYERS + 1];
  7.  
  8. public Plugin:myinfo =
  9. {
  10.     name = "[L4D2] Prevent M60 Drop on empty clip",
  11.     author = "DeathChaos25",
  12.     description = "Prevents M60s from getting auto deleted when they run empty as well as fixing other various bugs",
  13.     version = "1.0",
  14.     url = "https://forums.alliedmods.net/showthread.php?t=266485"
  15. }
  16.  
  17.  
  18. public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
  19. {
  20.     decl String:s_GameFolder[32];
  21.     GetGameFolderName(s_GameFolder, sizeof(s_GameFolder));
  22.     if (!StrEqual(s_GameFolder, "left4dead2", false))
  23.     {
  24.         strcopy(error, err_max, "This plugin is for Left 4 Dead 2 Only!");
  25.         return APLRes_Failure;
  26.     }
  27.     return APLRes_Success;
  28. }
  29.  
  30. public OnPluginStart()
  31. {
  32.     g_ActiveWeaponOffset = FindSendPropInfo("CBasePlayer", "m_hActiveWeapon");
  33.     HookEvent("upgrade_incendiary_ammo", Event_AmmoUpgrade);
  34.     HookEvent("upgrade_explosive_ammo", Event_AmmoUpgrade);
  35.     HookEvent("receive_upgrade", Event_AmmoUpgrade);
  36.     CreateTimer(0.1, M60AmmoCheck, _, TIMER_REPEAT);
  37. }
  38.  
  39. public Action:M60AmmoCheck(Handle:Timer)
  40. {
  41.     if (!IsServerProcessing())
  42.     {
  43.         return;
  44.     }
  45.     decl String:weaponclass[128];
  46.     for (new client = 1; client <= MaxClients; client++)
  47.     {
  48.         if (IsSurvivor(client) && IsPlayerAlive(client))
  49.         {
  50.             new ReserveAmmo = GetConVarInt(FindConVar("ammo_m60_max"));
  51.             new weapon = GetPlayerWeaponSlot(client, 0);
  52.             if (IsValidEdict(weapon))
  53.             {
  54.                
  55.                 new clip = GetEntProp(weapon, Prop_Data, "m_iClip1");
  56.                 new PrimType = GetEntProp(weapon, Prop_Send, "m_iPrimaryAmmoType");
  57.                 new ammo = GetEntProp(client, Prop_Send, "m_iAmmo", _, PrimType);
  58.                
  59.                 GetEdictClassname(weapon, weaponclass, sizeof(weaponclass));
  60.                
  61.                 if (StrEqual(weaponclass, "weapon_rifle_m60"))
  62.                 {
  63.                     if (clip == 0 && ammo > ReserveAmmo + 150)
  64.                     {
  65.                         SetEntProp(client, Prop_Send, "m_iAmmo", ReserveAmmo + 150, _, PrimType);
  66.                         PrintHintText(client, "No infinite M60 ammo for you :3");
  67.                     }
  68.                     else if (clip > 0 && ammo > ReserveAmmo)
  69.                     {
  70.                         SetEntProp(client, Prop_Send, "m_iAmmo", ReserveAmmo + (150 - clip), _, PrimType);
  71.                         PrintHintText(client, "No infinite M60 ammo for you :3");
  72.                     }
  73.                 }
  74.             }
  75.         }
  76.     }
  77. }
  78.  
  79. public Action:Event_AmmoUpgrade(Handle:event, const String:name[], bool:dontBroadcast)
  80. {
  81.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  82.    
  83.     if (!IsSurvivor(client))
  84.     {
  85.         return;
  86.     }
  87.     new weapon = GetPlayerWeaponSlot(client, 0);
  88.     decl String:s_Weapon[32];
  89.     if (IsValidEntity(weapon))
  90.     {
  91.         GetEdictClassname(weapon, s_Weapon, sizeof(s_Weapon));
  92.     }
  93.    
  94.     if (StrEqual(s_Weapon, "weapon_rifle_m60"))
  95.     {
  96.         new clip = GetEntProp(weapon, Prop_Data, "m_iClip1");
  97.         if (clip == 0)
  98.         {
  99.             SetEntProp(weapon, Prop_Send, "m_nUpgradedPrimaryAmmoLoaded", 150, 1);
  100.             SetEntProp(weapon, Prop_Send, "m_iClip1", 150);
  101.         }
  102.     }
  103. }
  104. public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:f_Velocity[3], Float:f_Angles[3], &weapon)
  105. {
  106.     if (!IsSurvivor(client))
  107.     {
  108.         return;
  109.     }
  110.    
  111.     if (buttons & IN_ATTACK)
  112.     {
  113.         decl String:s_Weapon[32];
  114.         weapon = GetEntDataEnt2(client, g_ActiveWeaponOffset);
  115.        
  116.         if (IsValidEntity(weapon))
  117.         {
  118.             GetEdictClassname(weapon, s_Weapon, sizeof(s_Weapon));
  119.         }
  120.         if (StrEqual(s_Weapon, "weapon_rifle_m60"))
  121.         {
  122.             new clip = GetEntProp(weapon, Prop_Data, "m_iClip1");
  123.             new PrimType = GetEntProp(weapon, Prop_Send, "m_iPrimaryAmmoType");
  124.             new ammo = GetEntProp(client, Prop_Send, "m_iAmmo", _, PrimType);
  125.             new laser = GetEntProp(weapon, Prop_Send, "m_upgradeBitVec");
  126.            
  127.             if (clip <= 1)
  128.             {
  129.                 AcceptEntityInput(weapon, "kill");
  130.                 new M60 = CreateEntityByName("weapon_rifle_m60");
  131.                 DispatchSpawn(M60);
  132.                 EquipPlayerWeapon(client, M60);
  133.                 SetEntProp(M60, Prop_Send, "m_iClip1", 0);
  134.                 SetEntProp(client, Prop_Send, "m_iAmmo", ammo, _, PrimType);
  135.                 SetEntProp(M60, Prop_Send, "m_upgradeBitVec", laser);
  136.                 //AcceptEntityInput(M60, "Use", client);
  137.             }
  138.         }
  139.     }
  140.     else if (buttons & IN_USE && !buttondelay[client])
  141.     {
  142.         new M60 = GetClientAimTarget(client, false);
  143.         decl String:s_Weapon[32];
  144.        
  145.         if (IsValidEntity(M60))
  146.         {
  147.             GetEdictClassname(M60, s_Weapon, sizeof(s_Weapon));
  148.         }
  149.         CreateTimer(2.0, ResetDelay, client);
  150.         if (StrEqual(s_Weapon, "weapon_rifle_m60"))
  151.         {
  152.             EquipPlayerWeapon(client, M60);
  153.         }
  154.         else if (StrEqual(s_Weapon, "weapon_ammo_spawn"))
  155.         {
  156.             new ReserveAmmo = GetConVarInt(FindConVar("ammo_m60_max"));
  157.             weapon = GetPlayerWeaponSlot(client, 0);
  158.            
  159.             if (IsValidEdict(weapon))
  160.             {
  161.                 new PrimType = GetEntProp(weapon, Prop_Send, "m_iPrimaryAmmoType");
  162.                 GetEdictClassname(weapon, s_Weapon, sizeof(s_Weapon));
  163.                 if (StrEqual(s_Weapon, "weapon_rifle_m60"))
  164.                 {
  165.                     SetEntProp(client, Prop_Send, "m_iAmmo", ReserveAmmo, _, PrimType);
  166.                 }
  167.             }
  168.         }
  169.     }
  170. }
  171.  
  172. public Action:ResetDelay(Handle:timer, any:client)
  173. {
  174.     buttondelay[client] = false;
  175. }
  176.  
  177. stock bool:IsSurvivor(client)
  178. {
  179.     return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2;
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement