Advertisement
FlacoBey

Untitled

Jan 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 28.95 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3.  
  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.     int slot = GetPlayerWeaponSlot(client, 0);
  220.     if (slot > 0)
  221.     {
  222.         new String:weapon[32];
  223.         new ammo;
  224.         new clip;
  225.         new upgrade;
  226.         new upammo;
  227.         new ammoOffset = FindSendPropInfo("CTerrorPlayer", "m_iAmmo");
  228.         GetEdictClassname(GetPlayerWeaponSlot(client, slot), weapon, 32);
  229.        
  230.         if (slot == 0)
  231.         {
  232.             clip = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_iClip1");
  233.             upgrade = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_upgradeBitVec");
  234.             upammo = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_nUpgradedPrimaryAmmoLoaded");
  235.             if (StrEqual(weapon, "weapon_rifle") || StrEqual(weapon, "weapon_rifle_sg552") || StrEqual(weapon, "weapon_rifle_desert") || StrEqual(weapon, "weapon_rifle_ak47"))
  236.             {
  237.                 ammo = GetEntData(client, ammoOffset+(12));
  238.                 SetEntData(client, ammoOffset+(12), 0);
  239.             }
  240.             else if (StrEqual(weapon, "weapon_smg") || StrEqual(weapon, "weapon_smg_silenced") || StrEqual(weapon, "weapon_smg_mp5"))
  241.             {
  242.                 ammo = GetEntData(client, ammoOffset+(20));
  243.                 SetEntData(client, ammoOffset+(20), 0);
  244.             }
  245.             else if (StrEqual(weapon, "weapon_pumpshotgun") || StrEqual(weapon, "weapon_shotgun_chrome"))
  246.             {
  247.                 ammo = GetEntData(client, ammoOffset+(28));
  248.                 SetEntData(client, ammoOffset+(28), 0);
  249.             }
  250.             else if (StrEqual(weapon, "weapon_autoshotgun") || StrEqual(weapon, "weapon_shotgun_spas"))
  251.             {
  252.                 ammo = GetEntData(client, ammoOffset+(32));
  253.                 SetEntData(client, ammoOffset+(32), 0);
  254.             }
  255.             else if (StrEqual(weapon, "weapon_hunting_rifle"))
  256.             {
  257.                 ammo = GetEntData(client, ammoOffset+(36));
  258.                 SetEntData(client, ammoOffset+(36), 0);
  259.             }
  260.             else if (StrEqual(weapon, "weapon_sniper_scout") || StrEqual(weapon, "weapon_sniper_military") || StrEqual(weapon, "weapon_sniper_awp"))
  261.             {
  262.                 ammo = GetEntData(client, ammoOffset+(40));
  263.                 SetEntData(client, ammoOffset+(40), 0);
  264.             }
  265.             else if (StrEqual(weapon, "weapon_grenade_launcher"))
  266.             {
  267.                 ammo = GetEntData(client, ammoOffset+(68));
  268.                 SetEntData(client, ammoOffset+(68), 0);
  269.             }
  270.         }
  271.         new index = CreateEntityByName(weapon);
  272.         new Float:origin[3];
  273.         GetEntPropVector(client, Prop_Send, "m_vecOrigin", origin);
  274.         origin[2]+=20;
  275.         TeleportEntity(index, origin, NULL_VECTOR, NULL_VECTOR);
  276.  
  277.         DispatchSpawn(index);
  278.         ActivateEntity(index);
  279.         RemovePlayerItem(client, GetPlayerWeaponSlot(client, slot));
  280.  
  281.         if (slot == 0)
  282.         {
  283.             SetEntProp(index, Prop_Send, "m_iExtraPrimaryAmmo", ammo);
  284.             SetEntProp(index, Prop_Send, "m_iClip1", clip);
  285.             SetEntProp(index, Prop_Send, "m_upgradeBitVec", upgrade);
  286.             SetEntProp(index, Prop_Send, "m_nUpgradedPrimaryAmmoLoaded", upammo);
  287.         }
  288.     }
  289. }
  290.  
  291. public Event_PlayerUse(Handle:event, const String:name[], bool:dontBroadcast)
  292. {
  293.     new playerClient = GetClientOfUserId(GetEventInt(event, "userid"));
  294.    
  295.     new entityId = GetEventInt(event, "targetid");
  296.    
  297.     decl String:ent_name[64];
  298.    
  299.     if (IsValidEdict(entityId))
  300.     {
  301.         GetEdictClassname(entityId, ent_name, sizeof(ent_name)); //get the entities name
  302.        
  303.         if (StrEqual(ent_name, "weapon_ammo_spawn", false))
  304.         {
  305.             new weaponIndex = GetPlayerWeaponSlot(playerClient, 0);
  306.            
  307.             if(weaponIndex == -1)
  308.             return;
  309.            
  310.             new String:classname[64];
  311.            
  312.             GetEdictClassname(weaponIndex, classname, sizeof(classname));
  313.            
  314.             if(StrEqual(classname, "weapon_rifle"))
  315.             {
  316.                 int m16 = 120;
  317.                 SetConVarInt(rifleammo, m16)
  318.             }
  319.             else if(StrEqual(classname, "weapon_rifle_sg552"))
  320.             {
  321.                 int sg552 = 120;
  322.                 SetConVarInt(rifleammo, sg552)
  323.             }
  324.             else if(StrEqual(classname, "weapon_rifle_ak47"))
  325.             {
  326.                 int ak47 = 120;
  327.                 SetConVarInt(rifleammo, ak47)
  328.             }
  329.             else if(StrEqual(classname, "weapon_rifle_desert"))
  330.             {
  331.                 int desert = 120;
  332.                 SetConVarInt(rifleammo, desert)
  333.             }
  334.             else if(StrEqual(classname, "weapon_smg"))
  335.             {
  336.                 int smg = 250;
  337.                 SetConVarInt(smgammo, smg)
  338.             }
  339.             else if(StrEqual(classname, "weapon_smg_mp5"))
  340.             {
  341.                 int smg5 = 250;
  342.                 SetConVarInt(smgammo, smg5)
  343.             }
  344.             else if(StrEqual(classname, "weapon_smg_silenced"))
  345.             {
  346.                 int smgs = 250;
  347.                 SetConVarInt(smgammo, smgs)
  348.             }
  349.             else if(StrEqual(classname, "weapon_pumpshotgun"))
  350.             {
  351.                 int pumpShotgun = 32;
  352.                 SetConVarInt(shotammo, pumpShotgun)
  353.             }
  354.             else if(StrEqual(classname, "weapon_shotgun_chrome"))
  355.             {
  356.                 int shotgunChrome = 32;
  357.                 SetConVarInt(shotammo, shotgunChrome)
  358.             }
  359.             else if(StrEqual(classname, "weapon_autoshotgun"))
  360.             {
  361.                 int autoshotgun = 32;
  362.                 SetConVarInt(autoshotammo, autoshotgun)
  363.             }
  364.             else if(StrEqual(classname, "weapon_shotgun_spas"))
  365.             {
  366.                 int shotgunSpas = 32;
  367.                 SetConVarInt(autoshotammo, shotgunSpas)
  368.             }
  369.             else if(StrEqual(classname, "weapon_sniper_military"))
  370.             {
  371.                 new sniperMilitary = 60;
  372.                 SetConVarInt(sniperammo, sniperMilitary)
  373.             }
  374.             else if(StrEqual(classname, "weapon_sniper_awp"))
  375.             {
  376.                 int sniperAwp = 30;
  377.                 SetConVarInt(m60ammo, sniperAwp)
  378.             }
  379.             else if(StrEqual(classname, "weapon_sniper_scout"))
  380.             {
  381.                 int sniperScout = 60;
  382.                 SetConVarInt(sniperammo, sniperScout)
  383.             }
  384.             else if(StrEqual(classname, "weapon_hunting_rifle"))
  385.             {
  386.                 int huntingRifle = 30;
  387.                 SetConVarInt(m60ammo, huntingRifle)
  388.             }
  389.             else if(StrEqual(classname, "weapon_rifle_m60"))
  390.             {
  391.                 int iClip1 = GetEntProp(weaponIndex, Prop_Send, "m_iClip1");
  392.                 int iPrimType = GetEntProp(weaponIndex, Prop_Send, "m_iPrimaryAmmoType");
  393.                 SetEntProp(playerClient, Prop_Send, "m_iAmmo", (GetConVarInt(m60amount_max)-iClip1), _, iPrimType);
  394.             }
  395.             else if(StrEqual(classname, "weapon_grenade_launcher"))
  396.             {
  397.                 int iClip1 = GetEntProp(weaponIndex, Prop_Send, "m_iClip1");
  398.                 int iPrimType = GetEntProp(weaponIndex, Prop_Send, "m_iPrimaryAmmoType");
  399.                 SetEntProp(playerClient, Prop_Send, "m_iAmmo", (GetConVarInt(glamount_max)-iClip1), _, iPrimType);
  400.             }
  401.         }
  402.     }
  403.     //CreateTimer(30.0, GunTimer, TIMER_FLAG_NO_MAPCHANGE);
  404. }
  405.  
  406.  
  407. public Action:Event_ItemPickup(Handle:event, const String:name[], bool:dontBroadcast)
  408. {
  409.     if(!GetConVarInt(l4d2_LaserEnabled)) return Plugin_Continue;
  410.    
  411.     new client = GetClientOfUserId(GetEventInt(event, "userid"))
  412.    
  413.     if (!client || !IsClientInGame(client)) return Plugin_Continue;
  414.     decl String:weaponname[128]
  415.     GetEventString(event, "item", weaponname, sizeof(weaponname))
  416.    
  417.     new targetgun = GetPlayerWeaponSlot(client, 0)
  418.     if (IsValidEdict(targetgun))
  419.     {
  420.         if (StrEqual(weaponname, "rifle_m60", false))
  421.         {
  422.             new ammmo = GetRandomInt(0, 200);
  423.             new M60 = GetRandomInt(GetConVarInt(m60ammo_min), GetConVarInt(m60ammo_max))
  424.            
  425.             SetConVarInt(huntingrifleammo, M60)
  426.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  427.         }
  428.         else if (StrEqual(weaponname, "grenade_launcher", false))
  429.         {
  430.             new GrenadeLauncher = GetRandomInt(GetConVarInt(glammo_min), GetConVarInt(glammo_max))
  431.            
  432.             SetConVarInt(glammo, GrenadeLauncher)
  433.         }
  434.         else if (StrEqual(weaponname, "rifle", false))
  435.         {
  436.             new ammmo = GetRandomInt(0, 50);
  437.             new M16 = GetRandomInt(GetConVarInt(m16ammo_min), GetConVarInt(m16ammo_max))
  438.        
  439.             SetConVarInt(rifleammo, M16)
  440.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  441.            
  442.             new Handle:chance=l4d2_M16laser_chance;
  443.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  444.             {
  445.                 GiveClientLaser(client);
  446.             }
  447.         }
  448.         else if (StrEqual(weaponname, "rifle_ak47", false))
  449.         {
  450.             new ammmo = GetRandomInt(0, 40);
  451.             new Ak47 = GetRandomInt(GetConVarInt(ak47ammo_min), GetConVarInt(ak47ammo_max))
  452.            
  453.             SetConVarInt(rifleammo, Ak47)
  454.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  455.            
  456.             new Handle:chance=l4d2_AK47laser_chance;
  457.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  458.             {
  459.                 GiveClientLaser(client);
  460.             }
  461.         }
  462.         else if (StrEqual(weaponname, "rifle_desert", false))
  463.         {
  464.             new ammmo = GetRandomInt(0, 60);
  465.             new Desert = GetRandomInt(GetConVarInt(desertammo_min), GetConVarInt(desertammo_max))
  466.            
  467.             SetConVarInt(rifleammo, Desert)
  468.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  469.            
  470.             new Handle:chance=l4d2_DesertRiflelaser_chance;
  471.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  472.             {
  473.                 GiveClientLaser(client);
  474.             }
  475.         }
  476.         else if (StrEqual(weaponname, "rifle_sg552", false))
  477.         {
  478.             new ammmo = GetRandomInt(0, 50);
  479.             new Sg552 = GetRandomInt(GetConVarInt(sg552ammo_min), GetConVarInt(sg552ammo_max))
  480.            
  481.             SetConVarInt(rifleammo, Sg552)
  482.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  483.            
  484.             new Handle:chance=l4d2_SG552laser_chance;
  485.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  486.             {
  487.                 GiveClientLaser(client);
  488.             }
  489.         }
  490.         else if (StrEqual(weaponname, "hunting_rifle", false))
  491.         {
  492.             new ammmo = GetRandomInt(0, 5);
  493.             new Huntingrifle = GetRandomInt(GetConVarInt(huntingrifleammo_min), GetConVarInt(huntingrifleammo_max))
  494.            
  495.             SetConVarInt(m60ammo, Huntingrifle)
  496.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  497.            
  498.             new Handle:chance=l4d2_HuntingRiflelaser_chance;
  499.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  500.             {
  501.                 GiveClientLaser(client);
  502.             }
  503.         }
  504.         else if (StrEqual(weaponname, "sniper_scout", false))
  505.         {
  506.             new ammmo = GetRandomInt(0, 10);
  507.             new SniperScout = GetRandomInt(GetConVarInt(scoutammo_min), GetConVarInt(scoutammo_max))
  508.            
  509.             SetConVarInt(sniperammo, SniperScout)
  510.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  511.         }
  512.         else if(StrEqual(weaponname, "sniper_military", false))
  513.         {
  514.             new ammmo = GetRandomInt(0, 20);
  515.             new SniperMilitary = GetRandomInt(GetConVarInt(militaryammo_min), GetConVarInt(militaryammo_max))
  516.            
  517.             SetConVarInt(sniperammo, SniperMilitary)
  518.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  519.            
  520.             new Handle:chance=l4d2_Militarylaser_chance;
  521.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  522.             {
  523.                 GiveClientLaser(client);
  524.             }
  525.         }
  526.         else if (StrEqual(weaponname, "sniper_awp", false))
  527.         {
  528.             new ammmo = GetRandomInt(0, 5);
  529.             new SniperAwp = GetRandomInt(GetConVarInt(awpammo_min), GetConVarInt(awpammo_max))
  530.            
  531.             SetConVarInt(m60ammo, SniperAwp)
  532.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  533.         }
  534.         else if (StrEqual(weaponname, "autoshotgun", false))
  535.         {
  536.             new ammmo = GetRandomInt(0, 6);
  537.             new AutoShot = GetRandomInt(GetConVarInt(autoshotammo_min), GetConVarInt(autoshotammo_max))
  538.            
  539.             SetConVarInt(autoshotammo, AutoShot)
  540.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  541.         }
  542.         else if (StrEqual(weaponname, "pumpshotgun", false))
  543.         {
  544.             new ammmo = GetRandomInt(0, 6);
  545.             new PumpShotgun = GetRandomInt(GetConVarInt(pumpshotammo_min), GetConVarInt(pumpshotammo_max))
  546.            
  547.             SetConVarInt(shotammo, PumpShotgun)
  548.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  549.         }
  550.         else if (StrEqual(weaponname, "shotgun_chrome", false))
  551.         {
  552.             new ammmo = GetRandomInt(0, 8);
  553.             new ChromeShotgun = GetRandomInt(GetConVarInt(chromeshotammo_min), GetConVarInt(chromeshotammo_max))
  554.        
  555.             SetConVarInt(shotammo, ChromeShotgun)
  556.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  557.         }
  558.         else if (StrEqual(weaponname, "shotgun_spas", false))
  559.         {
  560.             new ammmo = GetRandomInt(0, 8);
  561.             new ShotSpas = GetRandomInt(GetConVarInt(shotspasammo_min), GetConVarInt(shotspasammo_max))
  562.            
  563.             SetConVarInt(autoshotammo, ShotSpas)
  564.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  565.         }
  566.         else if(StrEqual(weaponname, "smg", false))
  567.         {
  568.             new ammmo = GetRandomInt(0, 50);
  569.             new Smg = GetRandomInt(GetConVarInt(smgammo_min), GetConVarInt(smgammo_max))
  570.            
  571.             SetConVarInt(smgammo, Smg)
  572.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  573.            
  574.             new Handle:chance=l4d2_SMGlaser_chance;
  575.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  576.             {
  577.                 GiveClientLaser(client);
  578.             }
  579.         }
  580.         else if (StrEqual(weaponname, "smg_mp5", false))
  581.         {
  582.             new ammmo = GetRandomInt(0, 50);
  583.             new Smg5 = GetRandomInt(GetConVarInt(smg5ammo_min), GetConVarInt(smg5ammo_max))
  584.            
  585.             SetConVarInt(smgammo, Smg5)
  586.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  587.            
  588.             new Handle:chance=l4d2_SMG5laser_chance;
  589.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  590.             {
  591.                 GiveClientLaser(client);
  592.             }
  593.         }
  594.         else if (StrEqual(weaponname, "smg_silenced", false))
  595.         {
  596.             new ammmo = GetRandomInt(0, 50);
  597.             new SmgS = GetRandomInt(GetConVarInt(smgsammo_min), GetConVarInt(smgsammo_max))
  598.            
  599.             SetConVarInt(smgammo, SmgS)
  600.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  601.            
  602.             new Handle:chance=l4d2_SMGSlaser_chance;
  603.             if(GetRandomFloat(0.0,100.0)<GetConVarFloat(chance))
  604.             {
  605.                 GiveClientLaser(client);
  606.             }
  607.         }
  608.     }
  609.     new pistol = GetPlayerWeaponSlot(client, 1)
  610.     if (IsValidEdict(pistol))
  611.     {
  612.         if (StrEqual(weaponname, "pistol", false))
  613.         {
  614.             new ammmo = GetRandomInt(0, 15);
  615.             SetEntProp(pistol, Prop_Send, "m_iClip1", ammmo, 1)
  616.         }
  617.         else if (StrEqual(weaponname, "pistol_magnum", false))
  618.         {
  619.             new ammmo = GetRandomInt(0, 8);
  620.             SetEntProp(pistol, Prop_Send, "m_iClip1", ammmo, 1)
  621.         }
  622.     }
  623.     return Plugin_Continue;
  624. }
  625.  
  626. stock GiveClientLaser(any:client)
  627. {
  628.     new priWeapon = GetPlayerWeaponSlot(client, 0);
  629.     if (priWeapon <= 0 || !IsValidEntity(priWeapon)) return;
  630.  
  631.     new upgrades = L4D2_GetWeaponUpgrades(priWeapon);
  632.     if (upgrades & L4D2_WEPUPGFLAG_LASER) return;
  633.  
  634.     L4D2_SetWeaponUpgrades(priWeapon, upgrades | L4D2_WEPUPGFLAG_LASER);
  635. }
  636.  
  637. stock L4D2_GetWeaponUpgrades(weapon)
  638. {
  639.     return GetEntProp(weapon, Prop_Send, "m_upgradeBitVec");
  640. }
  641.  
  642. stock L4D2_SetWeaponUpgrades(weapon, upgrades)
  643. {
  644.     SetEntProp(weapon, Prop_Send, "m_upgradeBitVec", upgrades);
  645. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement