FlacoBey

Untitled

Jan 16th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 28.97 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #pragma tabsize 0
  4. #define PLUGIN_VERSION "1.5.3"
  5.  
  6. #define L4D2_WEPUPGFLAG_LASER  (1 << 2)
  7.  
  8. public Plugin:myinfo =
  9. {
  10.     name = "[L4D2] Random Ammunition",
  11.     author = "NoBody",
  12.     description = "Periodically changes the amount of ammo contained in picked up guns",
  13.     version = PLUGIN_VERSION,
  14.     url = ""
  15. };
  16.  
  17. new Handle:smgammo = INVALID_HANDLE;
  18. new Handle:shotammo = INVALID_HANDLE;
  19. new Handle:rifleammo = INVALID_HANDLE;
  20. new Handle:huntingrifleammo = INVALID_HANDLE;
  21. new Handle:autoshotammo = INVALID_HANDLE;
  22. new Handle:glammo = INVALID_HANDLE;
  23. new Handle:m60ammo = INVALID_HANDLE;
  24. new Handle:sniperammo = INVALID_HANDLE;
  25.  
  26. new Handle:pumpshotammo_min = INVALID_HANDLE
  27. new Handle:chromeshotammo_min = INVALID_HANDLE
  28. new Handle:autoshotammo_min = INVALID_HANDLE
  29. new Handle:shotspasammo_min = INVALID_HANDLE
  30. new Handle:smgammo_min = INVALID_HANDLE
  31. new Handle:smg5ammo_min = INVALID_HANDLE
  32. new Handle:smgsammo_min = INVALID_HANDLE
  33. new Handle:m16ammo_min = INVALID_HANDLE
  34. new Handle:sg552ammo_min = INVALID_HANDLE
  35. new Handle:desertammo_min = INVALID_HANDLE
  36. new Handle:ak47ammo_min = INVALID_HANDLE
  37. new Handle:huntingrifleammo_min = INVALID_HANDLE
  38. new Handle:militaryammo_min = INVALID_HANDLE
  39. new Handle:scoutammo_min = INVALID_HANDLE
  40. new Handle:glammo_min = INVALID_HANDLE
  41. new Handle:m60ammo_min = INVALID_HANDLE
  42. new Handle:awpammo_min = INVALID_HANDLE
  43.  
  44. new Handle:pumpshotammo_max = INVALID_HANDLE
  45. new Handle:chromeshotammo_max = INVALID_HANDLE
  46. new Handle:autoshotammo_max = INVALID_HANDLE
  47. new Handle:shotspasammo_max = INVALID_HANDLE
  48. new Handle:smgammo_max = INVALID_HANDLE
  49. new Handle:smg5ammo_max = INVALID_HANDLE
  50. new Handle:smgsammo_max = INVALID_HANDLE
  51. new Handle:m16ammo_max = INVALID_HANDLE
  52. new Handle:sg552ammo_max = INVALID_HANDLE
  53. new Handle:desertammo_max = INVALID_HANDLE
  54. new Handle:ak47ammo_max = INVALID_HANDLE
  55. new Handle:huntingrifleammo_max = INVALID_HANDLE
  56. new Handle:militaryammo_max = INVALID_HANDLE
  57. new Handle:scoutammo_max = INVALID_HANDLE
  58. new Handle:awpammo_max = INVALID_HANDLE
  59. new Handle:glammo_max = INVALID_HANDLE
  60. new Handle:glamount_max = INVALID_HANDLE
  61. new Handle:m60ammo_max = INVALID_HANDLE
  62. new Handle:m60amount_max = INVALID_HANDLE
  63.  
  64. new Handle:l4d2_LaserEnabled = INVALID_HANDLE;
  65. new Handle:l4d2_M16laser_chance = INVALID_HANDLE;
  66. new Handle:l4d2_AK47laser_chance = INVALID_HANDLE;
  67. new Handle:l4d2_DesertRiflelaser_chance = INVALID_HANDLE;
  68. new Handle:l4d2_SG552laser_chance = INVALID_HANDLE;
  69. new Handle:l4d2_HuntingRiflelaser_chance = INVALID_HANDLE;
  70. new Handle:l4d2_Militarylaser_chance = INVALID_HANDLE;
  71. new Handle:l4d2_SMGlaser_chance = INVALID_HANDLE;
  72. new Handle:l4d2_SMG5laser_chance = INVALID_HANDLE;
  73. new Handle:l4d2_SMGSlaser_chance = INVALID_HANDLE;
  74. //new slot;
  75.  
  76. //Create the timer that decides how often to change the gun cvars, edit the number to change the interval, it is 90 at the moment
  77. public OnPluginStart()
  78. {
  79.     decl String:game_name[64]
  80.     GetGameFolderName(game_name, sizeof(game_name))
  81.     if (!StrEqual(game_name, "left4dead2", false))
  82.     SetFailState("Plugin supports Left 4 Dead 2 only.")
  83.     HookEvent("player_use", Event_PlayerUse, EventHookMode_Pre);
  84.     HookEvent("item_pickup", Event_ItemPickup, EventHookMode_Pre)
  85.     //HookEvent("weapon_drop", Event_WeaponDrop, EventHookMode_Pre);
  86.     HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
  87.     HookEvent("round_end", Event_RoundEnd, EventHookMode_Pre);
  88.     CreateConVar("l4d_varyingammo_version", PLUGIN_VERSION, "L4D2 Varying Ammo Version", FCVAR_NONE)
  89.     huntingrifleammo = FindConVar("ammo_huntingrifle_max")
  90.     rifleammo = FindConVar("ammo_assaultrifle_max")
  91.     autoshotammo = FindConVar("ammo_autoshotgun_max")
  92.     shotammo = FindConVar("ammo_shotgun_max")
  93.     smgammo = FindConVar("ammo_smg_max")
  94.     m60ammo = FindConVar("ammo_m60_max")
  95.     glammo = FindConVar("ammo_grenadelauncher_max")
  96.     sniperammo = FindConVar("ammo_sniperrifle_max")
  97.    
  98.     huntingrifleammo_min = CreateConVar("l4d_huntingrifle_ammo_min", "45", "Min Hunting Rifle ammo variation", FCVAR_NOTIFY)
  99.     m16ammo_min = CreateConVar("l4d_rifleammo_min", "150", "Min M16 ammo variation", FCVAR_NOTIFY)
  100.     sg552ammo_min = CreateConVar("l4d_sg552_ammo_min", "150", "Min SG552 ammo variation", FCVAR_NOTIFY)
  101.     desertammo_min = CreateConVar("l4d_desert_ammo_min", "150", "Min Desert Rifle ammo variation", FCVAR_NOTIFY)
  102.     ak47ammo_min = CreateConVar("l4d_ak47_ammo_min", "150", "Min Ak-47 ammo variation", FCVAR_NOTIFY)
  103.     pumpshotammo_min = CreateConVar("l4d_pumpshotgun_ammo_min", "25", "Min Shotgun Pump ammo variation", FCVAR_NOTIFY)
  104.     chromeshotammo_min = CreateConVar("l4d_chromeshotgun_ammo_min", "25", "Min Shotgun Chrome ammo variation", FCVAR_NOTIFY)
  105.     autoshotammo_min = CreateConVar("l4d_autoshot_ammo_min", "25", "Min AutoShotgun ammo variation", FCVAR_NOTIFY)
  106.     shotspasammo_min = CreateConVar("l4d_shotspas_ammo_min", "25", "Min Shotgun Spas ammo variation", FCVAR_NOTIFY)
  107.    
  108.     smgammo_min = CreateConVar("l4d_smg_ammo_min", "250", "Min Smg ammo variation", FCVAR_NOTIFY)
  109.     smg5ammo_min = CreateConVar("l4d_smg5_ammo_min", "250", "Min Smg MP5 ammo variation", FCVAR_NOTIFY)
  110.     smgsammo_min = CreateConVar("l4d_smgs_ammo_min", "250", "Min Smg Silenced ammo variation", FCVAR_NOTIFY)
  111.    
  112.     militaryammo_min = CreateConVar("l4d_military_ammo_min", "25", "Min Sniper Military ammo variation", FCVAR_NOTIFY)
  113.     scoutammo_min = CreateConVar("l4d_scout_ammo_min", "15", "Min Sniper Scout ammo variation", FCVAR_NOTIFY)
  114.     awpammo_min = CreateConVar("l4d_awp_ammo_min", "20", "Min Sniper Awp ammo variation", FCVAR_NOTIFY)
  115.     glammo_min = CreateConVar("l4d_glammo_min", "1", "Min Grenade Launcher ammo variation", FCVAR_NOTIFY)
  116.     m60ammo_min = CreateConVar("l4d_m60ammo_min", "50", "Min M60 ammo variation", FCVAR_NOTIFY)
  117.    
  118.     // max ammo (created own convar to avoid conflicts)
  119.     huntingrifleammo_max = CreateConVar("l4d_huntingrifleammo_max", "135", "Max Hunting Rifle ammo variation", FCVAR_NOTIFY)
  120.     m16ammo_max = CreateConVar("l4d_rifle_ammo_max", "450", "Max M16 ammo variation", FCVAR_NOTIFY)
  121.     sg552ammo_max = CreateConVar("l4d_sg552_ammo_max", "450", "Max SG552 ammo variation", FCVAR_NOTIFY)
  122.     desertammo_max = CreateConVar("l4d_desert_ammo_max", "450", "Max Desert Rifle ammo variation", FCVAR_NOTIFY)
  123.     ak47ammo_max = CreateConVar("l4d_ak47_ammo_max", "450", "Max Ak-47 ammo variation", FCVAR_NOTIFY)
  124.     pumpshotammo_max = CreateConVar("l4d_pumpshotgun_ammo_max", "75", "Max Shotgun Pump ammo variation", FCVAR_NOTIFY)
  125.     chromeshotammo_max = CreateConVar("l4d_chromeshotgun_ammo_max", "75", "Max Shotgun Chrome ammo variation", FCVAR_NOTIFY)
  126.     autoshotammo_max = CreateConVar("l4d_autoshot_ammo_max", "120", "Max AutoShotgun ammo variation", FCVAR_NOTIFY)
  127.     shotspasammo_max = CreateConVar("l4d_shotspas_ammo_max", "120", "Max Shotgun Spas ammo variation", FCVAR_NOTIFY)
  128.     smgammo_max = CreateConVar("l4d_smg_ammo_max", "700", "Max Smg ammo variation", FCVAR_NOTIFY)
  129.     smg5ammo_max = CreateConVar("l4d_smg5_ammo_max", "700", "Max Smg MP5 ammo variation", FCVAR_NOTIFY)
  130.     smgsammo_max = CreateConVar("l4d_smgs_ammo_max", "700", "Max Smg Silenced ammo variation", FCVAR_NOTIFY)
  131.     militaryammo_max = CreateConVar("l4d_military_ammo_max", "180", "Max Sniper Military ammo variation", FCVAR_NOTIFY)
  132.     scoutammo_max = CreateConVar("l4d_scout_ammo_max", "100", "Max Sniper Scout ammo variation", FCVAR_NOTIFY)
  133.     awpammo_max = CreateConVar("l4d_awp_ammo_max", "100", "Max Sniper Awp ammo variation", FCVAR_NOTIFY)
  134.     glammo_max = CreateConVar("l4d_glammo_max", "12", "Max Grenade Launcher ammo variation", FCVAR_NOTIFY)
  135.     glamount_max = CreateConVar("l4d_gl_amount_max", "18", "Maximum Grenade Launcher amount of amunition to picked up", FCVAR_NOTIFY)
  136.     m60ammo_max = CreateConVar("l4d_m60ammo_max", "500", "Max M60 ammo variation", FCVAR_NOTIFY)
  137.     m60amount_max = CreateConVar("l4d_m60_amount_max", "500", "Maximum M60 amount of amunition to picked up", FCVAR_NOTIFY)
  138.    
  139.     l4d2_LaserEnabled = CreateConVar("l4d2_laser_enabled", "1", "Enables - Disables the Heashot Cash plugin", FCVAR_NONE);
  140.     l4d2_M16laser_chance = CreateConVar("l4d2_m16_laser_chance", "5.0", "normal chance [0.0, 100.0]", FCVAR_NONE);
  141.     l4d2_AK47laser_chance = CreateConVar("l4d2_ak47_laser_chance", "5.0", "normal chance [0.0, 100.0]", FCVAR_NONE);
  142.     l4d2_DesertRiflelaser_chance = CreateConVar("l4d2_desert_laser_chance", "5.0", "normal chance [0.0, 100.0]", FCVAR_NONE);
  143.     l4d2_SG552laser_chance = CreateConVar("l4d2_sg552_laser_chance", "5.0", "normal chance [0.0, 100.0]", FCVAR_NONE);
  144.     l4d2_HuntingRiflelaser_chance = CreateConVar("l4d2_hunting_laser_chance", "5.0", "normal chance [0.0, 100.0]", FCVAR_NONE);
  145.     l4d2_Militarylaser_chance = CreateConVar("l4d2_military_laser_chance", "5.0", "normal chance [0.0, 100.0]", FCVAR_NONE);
  146.     l4d2_SMGlaser_chance = CreateConVar("l4d2_SMG_laser_chance", "5.0", "normal chance [0.0, 100.0]", FCVAR_NONE);
  147.     l4d2_SMG5laser_chance = CreateConVar("l4d2_SMG5_laser_chance", "5.0", "normal chance [0.0, 100.0]", FCVAR_NONE);
  148.     l4d2_SMGSlaser_chance = CreateConVar("l4d2_SMGS_laser_chance", "5.0", "normal chance [0.0, 100.0]", FCVAR_NONE);
  149.    
  150.     AutoExecConfig(true, "l4d2_varyingammo", "sourcemod")
  151. }
  152.  
  153. public Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
  154. {
  155.     CreateTimer(4.0, GunTimer, TIMER_REPEAT, TIMER_FLAG_NO_MAPCHANGE);
  156.     CreateTimer(5.0, TimerPluginOn, TIMER_FLAG_NO_MAPCHANGE);
  157. }
  158.  
  159. public Action:Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
  160. {
  161.     SetConVarInt(FindConVar("l4d2_laser_enabled"), 0);
  162. }
  163.  
  164. public Action:TimerPluginOn(Handle:timer)
  165. {
  166.     SetConVarInt(FindConVar("l4d2_laser_enabled"), 1);
  167. }
  168.  
  169. public Action:GunTimer(Handle:timer)
  170. {
  171.     static NumPrinted = 0
  172.     if (NumPrinted++ <= 2)
  173.     {
  174.         new m60 = GetRandomInt(GetConVarInt(m60ammo_min), GetConVarInt(m60ammo_max))
  175.         new m79 = GetRandomInt(GetConVarInt(glammo_min), GetConVarInt(glammo_max))
  176.         new m16 = GetRandomInt(GetConVarInt(m16ammo_min), GetConVarInt(m16ammo_max))
  177.         new ak47 = GetRandomInt(GetConVarInt(ak47ammo_min), GetConVarInt(ak47ammo_max))
  178.         new desert = GetRandomInt(GetConVarInt(desertammo_min), GetConVarInt(desertammo_max))
  179.         new sg552 = GetRandomInt(GetConVarInt(sg552ammo_min), GetConVarInt(sg552ammo_max))
  180.         new huntingRifle = GetRandomInt(GetConVarInt(huntingrifleammo_min), GetConVarInt(huntingrifleammo_max))
  181.         new sniperScout = GetRandomInt(GetConVarInt(scoutammo_min), GetConVarInt(scoutammo_max))
  182.         new sniperMilitary = GetRandomInt(GetConVarInt(militaryammo_min), GetConVarInt(militaryammo_max))
  183.         new sniperAwp = GetRandomInt(GetConVarInt(awpammo_min), GetConVarInt(awpammo_max))
  184.         new autoshotgun = GetRandomInt(GetConVarInt(autoshotammo_min), GetConVarInt(autoshotammo_max))
  185.         new pumpShotgun = GetRandomInt(GetConVarInt(pumpshotammo_min), GetConVarInt(pumpshotammo_max))
  186.         new shotgunChrome = GetRandomInt(GetConVarInt(chromeshotammo_min), GetConVarInt(chromeshotammo_max))
  187.         new shotgunSpas = GetRandomInt(GetConVarInt(shotspasammo_min), GetConVarInt(shotspasammo_max))
  188.         new smg = GetRandomInt(GetConVarInt(smgammo_min), GetConVarInt(smgammo_max))
  189.         new smg5 = GetRandomInt(GetConVarInt(smg5ammo_min), GetConVarInt(smg5ammo_max))
  190.         new smgs = GetRandomInt(GetConVarInt(smgsammo_min), GetConVarInt(smgsammo_max))
  191.        
  192.         SetConVarInt(huntingrifleammo, m60)
  193.         SetConVarInt(glammo, m79)
  194.         SetConVarInt(rifleammo, m16)
  195.         SetConVarInt(rifleammo, ak47)
  196.         SetConVarInt(rifleammo, desert)
  197.         SetConVarInt(rifleammo, sg552)
  198.         SetConVarInt(m60ammo, huntingRifle)
  199.         SetConVarInt(sniperammo, sniperScout)
  200.         SetConVarInt(sniperammo, sniperMilitary)
  201.         SetConVarInt(m60ammo, sniperAwp)
  202.         SetConVarInt(autoshotammo, autoshotgun)
  203.         SetConVarInt(shotammo, pumpShotgun)
  204.         SetConVarInt(shotammo, shotgunChrome)
  205.         SetConVarInt(autoshotammo, shotgunSpas)
  206.         SetConVarInt(smgammo, smg)
  207.         SetConVarInt(smgammo, smg5)
  208.         SetConVarInt(smgammo, smgs)
  209.         NumPrinted = 0
  210.     }
  211.     return Plugin_Continue
  212. }
  213.  
  214. public Action:Event_WeaponDrop(Handle:event, const String:name[], bool:dontBroadcast)
  215. {
  216.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  217.    
  218.     if (client == 0 || !IsClientConnected(client) || !IsClientInGame(client) || GetClientTeam(client) != 2) return;
  219.    
  220.     int slot = GetPlayerWeaponSlot(client, 0);
  221.    
  222.     if (slot > 0)
  223.     {
  224.         new String:weapon[32];
  225.         new ammo;
  226.         new clip;
  227.         new upgrade;
  228.         new upammo;
  229.         new ammoOffset = FindSendPropInfo("CTerrorPlayer", "m_iAmmo");
  230.         GetEdictClassname(GetPlayerWeaponSlot(client, slot), weapon, 32);
  231.        
  232.         if (slot == 0)
  233.         {
  234.             clip = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_iClip1");
  235.             upgrade = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_upgradeBitVec");
  236.             upammo = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_nUpgradedPrimaryAmmoLoaded");
  237.             if (StrEqual(weapon, "weapon_rifle") || StrEqual(weapon, "weapon_rifle_sg552") || StrEqual(weapon, "weapon_rifle_desert") || StrEqual(weapon, "weapon_rifle_ak47"))
  238.             {
  239.                 ammo = GetEntData(client, ammoOffset+(12));
  240.                 SetEntData(client, ammoOffset+(12), 0);
  241.             }
  242.             else if (StrEqual(weapon, "weapon_smg") || StrEqual(weapon, "weapon_smg_silenced") || StrEqual(weapon, "weapon_smg_mp5"))
  243.             {
  244.                 ammo = GetEntData(client, ammoOffset+(20));
  245.                 SetEntData(client, ammoOffset+(20), 0);
  246.             }
  247.             else if (StrEqual(weapon, "weapon_pumpshotgun") || StrEqual(weapon, "weapon_shotgun_chrome"))
  248.             {
  249.                 ammo = GetEntData(client, ammoOffset+(28));
  250.                 SetEntData(client, ammoOffset+(28), 0);
  251.             }
  252.             else if (StrEqual(weapon, "weapon_autoshotgun") || StrEqual(weapon, "weapon_shotgun_spas"))
  253.             {
  254.                 ammo = GetEntData(client, ammoOffset+(32));
  255.                 SetEntData(client, ammoOffset+(32), 0);
  256.             }
  257.             else if (StrEqual(weapon, "weapon_hunting_rifle"))
  258.             {
  259.                 ammo = GetEntData(client, ammoOffset+(36));
  260.                 SetEntData(client, ammoOffset+(36), 0);
  261.             }
  262.             else if (StrEqual(weapon, "weapon_sniper_scout") || StrEqual(weapon, "weapon_sniper_military") || StrEqual(weapon, "weapon_sniper_awp"))
  263.             {
  264.                 ammo = GetEntData(client, ammoOffset+(40));
  265.                 SetEntData(client, ammoOffset+(40), 0);
  266.             }
  267.             else if (StrEqual(weapon, "weapon_grenade_launcher"))
  268.             {
  269.                 ammo = GetEntData(client, ammoOffset+(68));
  270.                 SetEntData(client, ammoOffset+(68), 0);
  271.             }
  272.         }
  273.         new index = CreateEntityByName(weapon);
  274.         new Float:origin[3];
  275.         GetEntPropVector(client, Prop_Send, "m_vecOrigin", origin);
  276.         origin[2]+=20;
  277.         TeleportEntity(index, origin, NULL_VECTOR, NULL_VECTOR);
  278.  
  279.         DispatchSpawn(index);
  280.         ActivateEntity(index);
  281.         RemovePlayerItem(client, GetPlayerWeaponSlot(client, slot));
  282.  
  283.         if (slot == 0)
  284.         {
  285.             SetEntProp(index, Prop_Send, "m_iExtraPrimaryAmmo", ammo);
  286.             SetEntProp(index, Prop_Send, "m_iClip1", clip);
  287.             SetEntProp(index, Prop_Send, "m_upgradeBitVec", upgrade);
  288.             SetEntProp(index, Prop_Send, "m_nUpgradedPrimaryAmmoLoaded", upammo);
  289.         }
  290.     }
  291. }
  292.  
  293. public Event_PlayerUse(Handle:event, const String:name[], bool:dontBroadcast)
  294. {
  295.     new playerClient = GetClientOfUserId(GetEventInt(event, "userid"));
  296.    
  297.     new entityId = GetEventInt(event, "targetid");
  298.    
  299.     decl String:ent_name[64];
  300.    
  301.     if (IsValidEdict(entityId))
  302.     {
  303.         GetEdictClassname(entityId, ent_name, sizeof(ent_name)); //get the entities name
  304.        
  305.         if (StrEqual(ent_name, "weapon_ammo_spawn", false))
  306.         {
  307.             new weaponIndex = GetPlayerWeaponSlot(playerClient, 0);
  308.            
  309.             if(weaponIndex == -1)
  310.             return;
  311.            
  312.             new String:classname[64];
  313.            
  314.             GetEdictClassname(weaponIndex, classname, sizeof(classname));
  315.            
  316.             if(StrEqual(classname, "weapon_rifle"))
  317.             {
  318.                 int m16 = 120;
  319.                 SetConVarInt(rifleammo, m16)
  320.             }
  321.             else if(StrEqual(classname, "weapon_rifle_sg552"))
  322.             {
  323.                 int sg552 = 120;
  324.                 SetConVarInt(rifleammo, sg552)
  325.             }
  326.             else if(StrEqual(classname, "weapon_rifle_ak47"))
  327.             {
  328.                 int ak47 = 120;
  329.                 SetConVarInt(rifleammo, ak47)
  330.             }
  331.             else if(StrEqual(classname, "weapon_rifle_desert"))
  332.             {
  333.                 int desert = 120;
  334.                 SetConVarInt(rifleammo, desert)
  335.             }
  336.             else if(StrEqual(classname, "weapon_smg"))
  337.             {
  338.                 int smg = 250;
  339.                 SetConVarInt(smgammo, smg)
  340.             }
  341.             else if(StrEqual(classname, "weapon_smg_mp5"))
  342.             {
  343.                 int smg5 = 250;
  344.                 SetConVarInt(smgammo, smg5)
  345.             }
  346.             else if(StrEqual(classname, "weapon_smg_silenced"))
  347.             {
  348.                 int smgs = 250;
  349.                 SetConVarInt(smgammo, smgs)
  350.             }
  351.             else if(StrEqual(classname, "weapon_pumpshotgun"))
  352.             {
  353.                 int pumpShotgun = 32;
  354.                 SetConVarInt(shotammo, pumpShotgun)
  355.             }
  356.             else if(StrEqual(classname, "weapon_shotgun_chrome"))
  357.             {
  358.                 int shotgunChrome = 32;
  359.                 SetConVarInt(shotammo, shotgunChrome)
  360.             }
  361.             else if(StrEqual(classname, "weapon_autoshotgun"))
  362.             {
  363.                 int autoshotgun = 32;
  364.                 SetConVarInt(autoshotammo, autoshotgun)
  365.             }
  366.             else if(StrEqual(classname, "weapon_shotgun_spas"))
  367.             {
  368.                 int shotgunSpas = 32;
  369.                 SetConVarInt(autoshotammo, shotgunSpas)
  370.             }
  371.             else if(StrEqual(classname, "weapon_sniper_military"))
  372.             {
  373.                 new sniperMilitary = 60;
  374.                 SetConVarInt(sniperammo, sniperMilitary)
  375.             }
  376.             else if(StrEqual(classname, "weapon_sniper_awp"))
  377.             {
  378.                 int sniperAwp = 30;
  379.                 SetConVarInt(m60ammo, sniperAwp)
  380.             }
  381.             else if(StrEqual(classname, "weapon_sniper_scout"))
  382.             {
  383.                 int sniperScout = 60;
  384.                 SetConVarInt(sniperammo, sniperScout)
  385.             }
  386.             else if(StrEqual(classname, "weapon_hunting_rifle"))
  387.             {
  388.                 int huntingRifle = 30;
  389.                 SetConVarInt(m60ammo, huntingRifle)
  390.             }
  391.             else if(StrEqual(classname, "weapon_rifle_m60"))
  392.             {
  393.                 int iClip1 = GetEntProp(weaponIndex, Prop_Send, "m_iClip1");
  394.                 int iPrimType = GetEntProp(weaponIndex, Prop_Send, "m_iPrimaryAmmoType");
  395.                 SetEntProp(playerClient, Prop_Send, "m_iAmmo", (GetConVarInt(m60amount_max)-iClip1), _, iPrimType);
  396.             }
  397.             else if(StrEqual(classname, "weapon_grenade_launcher"))
  398.             {
  399.                 int iClip1 = GetEntProp(weaponIndex, Prop_Send, "m_iClip1");
  400.                 int iPrimType = GetEntProp(weaponIndex, Prop_Send, "m_iPrimaryAmmoType");
  401.                 SetEntProp(playerClient, Prop_Send, "m_iAmmo", (GetConVarInt(glamount_max)-iClip1), _, iPrimType);
  402.             }
  403.         }
  404.     }
  405.     //CreateTimer(30.0, GunTimer, TIMER_FLAG_NO_MAPCHANGE);
  406. }
  407.  
  408.  
  409. public Action:Event_ItemPickup(Handle:event, const String:name[], bool:dontBroadcast)
  410. {
  411.     if(!GetConVarInt(l4d2_LaserEnabled)) return Plugin_Continue;
  412.    
  413.     new client = GetClientOfUserId(GetEventInt(event, "userid"))
  414.    
  415.     if (!client || !IsClientInGame(client)) return Plugin_Continue;
  416.     decl String:weaponname[128]
  417.     GetEventString(event, "item", weaponname, sizeof(weaponname))
  418.    
  419.     new targetgun = GetPlayerWeaponSlot(client, 0)
  420.     if (IsValidEdict(targetgun))
  421.     {
  422.         if (StrEqual(weaponname, "rifle_m60", false))
  423.         {
  424.             new ammmo = GetRandomInt(0, 150);
  425.             new M60 = GetRandomInt(GetConVarInt(m60ammo_min), GetConVarInt(m60ammo_max))
  426.            
  427.             SetConVarInt(huntingrifleammo, M60)
  428.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  429.         }
  430.         else if (StrEqual(weaponname, "grenade_launcher", false))
  431.         {
  432.             new GrenadeLauncher = GetRandomInt(GetConVarInt(glammo_min), GetConVarInt(glammo_max))
  433.            
  434.             SetConVarInt(glammo, GrenadeLauncher)
  435.         }
  436.         else if (StrEqual(weaponname, "rifle", false))
  437.         {
  438.             new ammmo = GetRandomInt(0, 50);
  439.             new M16 = GetRandomInt(GetConVarInt(m16ammo_min), GetConVarInt(m16ammo_max))
  440.        
  441.             SetConVarInt(rifleammo, M16)
  442.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  443.            
  444.             new Handle:chance=l4d2_M16laser_chance;
  445.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  446.             {
  447.                 GiveClientLaser(client);
  448.             }
  449.         }
  450.         else if (StrEqual(weaponname, "rifle_ak47", false))
  451.         {
  452.             new ammmo = GetRandomInt(0, 40);
  453.             new Ak47 = GetRandomInt(GetConVarInt(ak47ammo_min), GetConVarInt(ak47ammo_max))
  454.            
  455.             SetConVarInt(rifleammo, Ak47)
  456.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  457.            
  458.             new Handle:chance=l4d2_AK47laser_chance;
  459.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  460.             {
  461.                 GiveClientLaser(client);
  462.             }
  463.         }
  464.         else if (StrEqual(weaponname, "rifle_desert", false))
  465.         {
  466.             new ammmo = GetRandomInt(0, 60);
  467.             new Desert = GetRandomInt(GetConVarInt(desertammo_min), GetConVarInt(desertammo_max))
  468.            
  469.             SetConVarInt(rifleammo, Desert)
  470.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  471.            
  472.             new Handle:chance=l4d2_DesertRiflelaser_chance;
  473.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  474.             {
  475.                 GiveClientLaser(client);
  476.             }
  477.         }
  478.         else if (StrEqual(weaponname, "rifle_sg552", false))
  479.         {
  480.             new ammmo = GetRandomInt(0, 50);
  481.             new Sg552 = GetRandomInt(GetConVarInt(sg552ammo_min), GetConVarInt(sg552ammo_max))
  482.            
  483.             SetConVarInt(rifleammo, Sg552)
  484.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  485.            
  486.             new Handle:chance=l4d2_SG552laser_chance;
  487.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  488.             {
  489.                 GiveClientLaser(client);
  490.             }
  491.         }
  492.         else if (StrEqual(weaponname, "hunting_rifle", false))
  493.         {
  494.             new ammmo = GetRandomInt(0, 5);
  495.             new Huntingrifle = GetRandomInt(GetConVarInt(huntingrifleammo_min), GetConVarInt(huntingrifleammo_max))
  496.            
  497.             SetConVarInt(m60ammo, Huntingrifle)
  498.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  499.            
  500.             new Handle:chance=l4d2_HuntingRiflelaser_chance;
  501.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  502.             {
  503.                 GiveClientLaser(client);
  504.             }
  505.         }
  506.         else if (StrEqual(weaponname, "sniper_scout", false))
  507.         {
  508.             new ammmo = GetRandomInt(0, 10);
  509.             new SniperScout = GetRandomInt(GetConVarInt(scoutammo_min), GetConVarInt(scoutammo_max))
  510.            
  511.             SetConVarInt(sniperammo, SniperScout)
  512.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  513.         }
  514.         else if(StrEqual(weaponname, "sniper_military", false))
  515.         {
  516.             new ammmo = GetRandomInt(0, 20);
  517.             new SniperMilitary = GetRandomInt(GetConVarInt(militaryammo_min), GetConVarInt(militaryammo_max))
  518.            
  519.             SetConVarInt(sniperammo, SniperMilitary)
  520.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  521.            
  522.             new Handle:chance=l4d2_Militarylaser_chance;
  523.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  524.             {
  525.                 GiveClientLaser(client);
  526.             }
  527.         }
  528.         else if (StrEqual(weaponname, "sniper_awp", false))
  529.         {
  530.             new ammmo = GetRandomInt(0, 5);
  531.             new SniperAwp = GetRandomInt(GetConVarInt(awpammo_min), GetConVarInt(awpammo_max))
  532.            
  533.             SetConVarInt(m60ammo, SniperAwp)
  534.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  535.         }
  536.         else if (StrEqual(weaponname, "autoshotgun", false))
  537.         {
  538.             new ammmo = GetRandomInt(0, 6);
  539.             new AutoShot = GetRandomInt(GetConVarInt(autoshotammo_min), GetConVarInt(autoshotammo_max))
  540.            
  541.             SetConVarInt(autoshotammo, AutoShot)
  542.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  543.         }
  544.         else if (StrEqual(weaponname, "pumpshotgun", false))
  545.         {
  546.             new ammmo = GetRandomInt(0, 6);
  547.             new PumpShotgun = GetRandomInt(GetConVarInt(pumpshotammo_min), GetConVarInt(pumpshotammo_max))
  548.            
  549.             SetConVarInt(shotammo, PumpShotgun)
  550.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  551.         }
  552.         else if (StrEqual(weaponname, "shotgun_chrome", false))
  553.         {
  554.             new ammmo = GetRandomInt(0, 8);
  555.             new ChromeShotgun = GetRandomInt(GetConVarInt(chromeshotammo_min), GetConVarInt(chromeshotammo_max))
  556.        
  557.             SetConVarInt(shotammo, ChromeShotgun)
  558.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  559.         }
  560.         else if (StrEqual(weaponname, "shotgun_spas", false))
  561.         {
  562.             new ammmo = GetRandomInt(0, 8);
  563.             new ShotSpas = GetRandomInt(GetConVarInt(shotspasammo_min), GetConVarInt(shotspasammo_max))
  564.            
  565.             SetConVarInt(autoshotammo, ShotSpas)
  566.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  567.         }
  568.         else if(StrEqual(weaponname, "smg", false))
  569.         {
  570.             new ammmo = GetRandomInt(0, 50);
  571.             new Smg = GetRandomInt(GetConVarInt(smgammo_min), GetConVarInt(smgammo_max))
  572.            
  573.             SetConVarInt(smgammo, Smg)
  574.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  575.            
  576.             new Handle:chance=l4d2_SMGlaser_chance;
  577.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  578.             {
  579.                 GiveClientLaser(client);
  580.             }
  581.         }
  582.         else if (StrEqual(weaponname, "smg_mp5", false))
  583.         {
  584.             new ammmo = GetRandomInt(0, 50);
  585.             new Smg5 = GetRandomInt(GetConVarInt(smg5ammo_min), GetConVarInt(smg5ammo_max))
  586.            
  587.             SetConVarInt(smgammo, Smg5)
  588.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  589.            
  590.             new Handle:chance=l4d2_SMG5laser_chance;
  591.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  592.             {
  593.                 GiveClientLaser(client);
  594.             }
  595.         }
  596.         else if (StrEqual(weaponname, "smg_silenced", false))
  597.         {
  598.             new ammmo = GetRandomInt(0, 50);
  599.             new SmgS = GetRandomInt(GetConVarInt(smgsammo_min), GetConVarInt(smgsammo_max))
  600.            
  601.             SetConVarInt(smgammo, SmgS)
  602.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  603.            
  604.             new Handle:chance=l4d2_SMGSlaser_chance;
  605.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  606.             {
  607.                 GiveClientLaser(client);
  608.             }
  609.         }
  610.     }
  611.     new pistol = GetPlayerWeaponSlot(client, 1)
  612.     if (IsValidEdict(pistol))
  613.     {
  614.         if (StrEqual(weaponname, "pistol", false))
  615.         {
  616.             new ammmo = GetRandomInt(0, 15);
  617.             SetEntProp(pistol, Prop_Send, "m_iClip1", ammmo, 1)
  618.         }
  619.         else if (StrEqual(weaponname, "pistol_magnum", false))
  620.         {
  621.             new ammmo = GetRandomInt(0, 8);
  622.             SetEntProp(pistol, Prop_Send, "m_iClip1", ammmo, 1)
  623.         }
  624.     }
  625.     return Plugin_Continue;
  626. }
  627.  
  628. stock GiveClientLaser(any:client)
  629. {
  630.     new priWeapon = GetPlayerWeaponSlot(client, 0);
  631.     if (priWeapon <= 0 || !IsValidEntity(priWeapon)) return;
  632.  
  633.     new upgrades = L4D2_GetWeaponUpgrades(priWeapon);
  634.     if (upgrades & L4D2_WEPUPGFLAG_LASER) return;
  635.  
  636.     L4D2_SetWeaponUpgrades(priWeapon, upgrades | L4D2_WEPUPGFLAG_LASER);
  637. }
  638.  
  639. stock L4D2_GetWeaponUpgrades(weapon)
  640. {
  641.     return GetEntProp(weapon, Prop_Send, "m_upgradeBitVec");
  642. }
  643.  
  644. stock L4D2_SetWeaponUpgrades(weapon, upgrades)
  645. {
  646.     SetEntProp(weapon, Prop_Send, "m_upgradeBitVec", upgrades);
  647. }
Advertisement
Add Comment
Please, Sign In to add comment