Advertisement
FlacoBey

Untitled

Feb 15th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.82 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3.  
  4. #define PLUGIN_VERSION "1.5.3"
  5.  
  6. public Plugin:myinfo =
  7. {
  8.     name = "[L4D2] Random Ammunition",
  9.     author = "NoBody",
  10.     description = "Periodically changes the amount of ammo contained in picked up guns",
  11.     version = PLUGIN_VERSION,
  12.     url = ""
  13. };
  14.  
  15. new Handle:glammo = INVALID_HANDLE;
  16. new Handle:m60ammo = INVALID_HANDLE;
  17.  
  18. new Handle:glammo_min = INVALID_HANDLE
  19. new Handle:m60ammo_min = INVALID_HANDLE
  20.  
  21. new Handle:glammo_max = INVALID_HANDLE
  22. new Handle:glamount_max = INVALID_HANDLE
  23. new Handle:m60ammo_max = INVALID_HANDLE
  24. new Handle:m60amount_max = INVALID_HANDLE
  25.  
  26. public OnPluginStart()
  27. {
  28.     HookEvent("player_use", Event_PlayerUse, EventHookMode_Pre);
  29.     HookEvent("item_pickup", Event_ItemPickup, EventHookMode_Pre)
  30.     //HookEvent("weapon_drop", Event_WeaponDrop, EventHookMode_Pre);
  31.     HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
  32.     HookEvent("round_end", Event_RoundEnd, EventHookMode_Pre);
  33.    
  34.     m60ammo = FindConVar("ammo_m60_max")
  35.     glammo = FindConVar("ammo_grenadelauncher_max")
  36.    
  37.     glammo_min = CreateConVar("l4d_glammo_min", "1", "Min Grenade Launcher ammo variation", FCVAR_NOTIFY)
  38.     m60ammo_min = CreateConVar("l4d_m60ammo_min", "50", "Min M60 ammo variation", FCVAR_NOTIFY)
  39.    
  40.     // max ammo (created own convar to avoid conflicts)
  41.     glammo_max = CreateConVar("l4d_glammo_max", "12", "Max Grenade Launcher ammo variation", FCVAR_NOTIFY)
  42.     glamount_max = CreateConVar("l4d_gl_amount_max", "18", "Maximum Grenade Launcher amount of amunition to picked up", FCVAR_NOTIFY)
  43.     m60ammo_max = CreateConVar("l4d_m60ammo_max", "500", "Max M60 ammo variation", FCVAR_NOTIFY)
  44.     m60amount_max = CreateConVar("l4d_m60_amount_max", "500", "Maximum M60 amount of amunition to picked up", FCVAR_NOTIFY)
  45.    
  46.  
  47.    
  48.     AutoExecConfig(true, "l4d2_varyingammo", "sourcemod")
  49. }
  50.  
  51. public Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
  52. {
  53.     CreateTimer(4.0, GunTimer, TIMER_REPEAT, TIMER_FLAG_NO_MAPCHANGE);
  54.     CreateTimer(5.0, TimerPluginOn, TIMER_FLAG_NO_MAPCHANGE);
  55. }
  56.  
  57. public Action:Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
  58. {
  59.     SetConVarInt(FindConVar("l4d2_laser_enabled"), 0);
  60. }
  61.  
  62. public Action:TimerPluginOn(Handle:timer)
  63. {
  64.     SetConVarInt(FindConVar("l4d2_laser_enabled"), 1);
  65. }
  66.  
  67. public Action:GunTimer(Handle:timer)
  68. {
  69.     static NumPrinted = 0
  70.     if (NumPrinted++ <= 2)
  71.     {
  72.         new m79 = GetRandomInt(0, 8)
  73.         new huntingRifle = GetRandomInt(0, 200)
  74.         new sniperAwp = GetRandomInt(0, 200)
  75.        
  76.         SetConVarInt(glammo, m79)
  77.         SetConVarInt(m60ammo, huntingRifle)
  78.         SetConVarInt(m60ammo, sniperAwp)
  79.         NumPrinted = 0
  80.     }
  81.     return Plugin_Continue
  82. }
  83. /*
  84. public Action:Event_WeaponDrop(Handle:event, const String:name[], bool:dontBroadcast)
  85. {
  86.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  87.    
  88.     if (client == 0 || !IsClientConnected(client) || !IsClientInGame(client) || GetClientTeam(client) != 2) return;
  89.    
  90.     if (GetPlayerWeaponSlot(client, slot) > 0)
  91.     {
  92.         new String:weapon[32];
  93.         new ammo;
  94.         new clip;
  95.         new upgrade;
  96.         new upammo;
  97.         new ammoOffset = FindSendPropInfo("CTerrorPlayer", "m_iAmmo");
  98.         GetEdictClassname(GetPlayerWeaponSlot(client, slot), weapon, 32);
  99.        
  100.         if (slot == 0)
  101.         {
  102.             clip = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_iClip1");
  103.             upgrade = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_upgradeBitVec");
  104.             upammo = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_nUpgradedPrimaryAmmoLoaded");
  105.             if (StrEqual(weapon, "weapon_rifle") || StrEqual(weapon, "weapon_rifle_sg552") || StrEqual(weapon, "weapon_rifle_desert") || StrEqual(weapon, "weapon_rifle_ak47"))
  106.             {
  107.                 ammo = GetEntData(client, ammoOffset+(12));
  108.                 SetEntData(client, ammoOffset+(12), 0);
  109.             }
  110.             else if (StrEqual(weapon, "weapon_smg") || StrEqual(weapon, "weapon_smg_silenced") || StrEqual(weapon, "weapon_smg_mp5"))
  111.             {
  112.                 ammo = GetEntData(client, ammoOffset+(20));
  113.                 SetEntData(client, ammoOffset+(20), 0);
  114.             }
  115.             else if (StrEqual(weapon, "weapon_pumpshotgun") || StrEqual(weapon, "weapon_shotgun_chrome"))
  116.             {
  117.                 ammo = GetEntData(client, ammoOffset+(28));
  118.                 SetEntData(client, ammoOffset+(28), 0);
  119.             }
  120.             else if (StrEqual(weapon, "weapon_autoshotgun") || StrEqual(weapon, "weapon_shotgun_spas"))
  121.             {
  122.                 ammo = GetEntData(client, ammoOffset+(32));
  123.                 SetEntData(client, ammoOffset+(32), 0);
  124.             }
  125.             else if (StrEqual(weapon, "weapon_hunting_rifle"))
  126.             {
  127.                 ammo = GetEntData(client, ammoOffset+(36));
  128.                 SetEntData(client, ammoOffset+(36), 0);
  129.             }
  130.             else if (StrEqual(weapon, "weapon_sniper_scout") || StrEqual(weapon, "weapon_sniper_military") || StrEqual(weapon, "weapon_sniper_awp"))
  131.             {
  132.                 ammo = GetEntData(client, ammoOffset+(40));
  133.                 SetEntData(client, ammoOffset+(40), 0);
  134.             }
  135.             else if (StrEqual(weapon, "weapon_grenade_launcher"))
  136.             {
  137.                 ammo = GetEntData(client, ammoOffset+(68));
  138.                 SetEntData(client, ammoOffset+(68), 0);
  139.             }
  140.         }
  141.         new index = CreateEntityByName(weapon);
  142.         new Float:origin[3];
  143.         GetEntPropVector(client, Prop_Send, "m_vecOrigin", origin);
  144.         origin[2]+=20;
  145.         TeleportEntity(index, origin, NULL_VECTOR, NULL_VECTOR);
  146.  
  147.         DispatchSpawn(index);
  148.         ActivateEntity(index);
  149.         RemovePlayerItem(client, GetPlayerWeaponSlot(client, slot));
  150.  
  151.         if (slot == 0)
  152.         {
  153.             SetEntProp(index, Prop_Send, "m_iExtraPrimaryAmmo", ammo);
  154.             SetEntProp(index, Prop_Send, "m_iClip1", clip);
  155.             SetEntProp(index, Prop_Send, "m_upgradeBitVec", upgrade);
  156.             SetEntProp(index, Prop_Send, "m_nUpgradedPrimaryAmmoLoaded", upammo);
  157.         }
  158.     }
  159. }
  160. */
  161. public Event_PlayerUse(Handle:event, const String:name[], bool:dontBroadcast)
  162. {
  163.     new playerClient = GetClientOfUserId(GetEventInt(event, "userid"));
  164.    
  165.     new entityId = GetEventInt(event, "targetid");
  166.    
  167.     decl String:ent_name[64];
  168.    
  169.     if (IsValidEdict(entityId))
  170.     {
  171.         GetEdictClassname(entityId, ent_name, sizeof(ent_name)); //get the entities name
  172.        
  173.         if (StrEqual(ent_name, "weapon_ammo_spawn", false))
  174.         {
  175.             new weaponIndex = GetPlayerWeaponSlot(playerClient, 0);
  176.            
  177.             if(weaponIndex == -1)
  178.             return;
  179.            
  180.             new String:classname[64];
  181.            
  182.             GetEdictClassname(weaponIndex, classname, sizeof(classname));
  183.            
  184.             if(StrEqual(classname, "weapon_rifle_m60"))
  185.             {
  186.                 new iClip1 = GetEntProp(weaponIndex, Prop_Send, "m_iClip1");
  187.                 new iPrimType = GetEntProp(weaponIndex, Prop_Send, "m_iPrimaryAmmoType");
  188.                 SetEntProp(playerClient, Prop_Send, "m_iAmmo", (GetConVarInt(m60amount_max)-iClip1), _, iPrimType);
  189.             }
  190.             else if(StrEqual(classname, "weapon_grenade_launcher"))
  191.             {
  192.                 new iClip1 = GetEntProp(weaponIndex, Prop_Send, "m_iClip1");
  193.                 new iPrimType = GetEntProp(weaponIndex, Prop_Send, "m_iPrimaryAmmoType");
  194.                 SetEntProp(playerClient, Prop_Send, "m_iAmmo", (GetConVarInt(glamount_max)-iClip1), _, iPrimType);
  195.             }
  196.         }
  197.     }
  198.  
  199.     //CreateTimer(30.0, GunTimer, TIMER_FLAG_NO_MAPCHANGE);
  200. }
  201.  
  202.  
  203. public Action:Event_ItemPickup(Handle:event, const String:name[], bool:dontBroadcast)
  204. {
  205.    
  206.     new client = GetClientOfUserId(GetEventInt(event, "userid"))
  207.    
  208.     if (!client || !IsClientInGame(client)) return Plugin_Continue;
  209.     decl String:weaponname[128]
  210.     GetEventString(event, "item", weaponname, sizeof(weaponname))
  211.    
  212.     new targetgun = GetPlayerWeaponSlot(client, 0)
  213.     if (IsValidEdict(targetgun))
  214.     {
  215.         if (StrEqual(weaponname, "rifle_m60", false))
  216.         {
  217.             new ammmo = GetRandomInt(0, 200);
  218.             new M60 = GetRandomInt(GetConVarInt(m60ammo_min), GetConVarInt(m60ammo_max))
  219.            
  220.             SetConVarInt(m60ammo, M60)
  221.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  222.         }
  223.         else if (StrEqual(weaponname, "grenade_launcher", false))
  224.         {
  225.             new GrenadeLauncher = GetRandomInt(GetConVarInt(glammo_min), GetConVarInt(glammo_max))
  226.            
  227.             SetConVarInt(glammo, GrenadeLauncher)
  228.         }
  229.     }
  230.     return Plugin_Continue;
  231. }
  232.  
  233. //Done!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement