Advertisement
FlacoBey

Untitled

Feb 15th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.39 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. new Handle:sniperammo = INVALID_HANDLE;
  18.  
  19. new Handle:glammo_min = INVALID_HANDLE
  20. new Handle:m60ammo_min = INVALID_HANDLE
  21.  
  22. new Handle:glammo_max = INVALID_HANDLE
  23. new Handle:glamount_max = INVALID_HANDLE
  24. new Handle:m60ammo_max = INVALID_HANDLE
  25. new Handle:m60amount_max = INVALID_HANDLE
  26.  
  27. public OnPluginStart()
  28. {
  29.     HookEvent("player_use", Event_PlayerUse, EventHookMode_Pre);
  30.     HookEvent("item_pickup", Event_ItemPickup, EventHookMode_Pre)
  31.     //HookEvent("weapon_drop", Event_WeaponDrop, EventHookMode_Pre);
  32.     HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
  33.    
  34.     sniperammo = 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. }
  55.  
  56. public Action:GunTimer(Handle:timer)
  57. {
  58.     static NumPrinted = 0
  59.     if (NumPrinted++ <= 2)
  60.     {
  61.         new m79 = GetRandomInt(0, 8)
  62.         new sniperAwp = GetRandomInt(0, 200)
  63.        
  64.         SetConVarInt(glammo, m79)
  65.         SetConVarInt(m60ammo, sniperAwp)
  66.         NumPrinted = 0
  67.     }
  68.     return Plugin_Continue
  69. }
  70. /*
  71. public Action:Event_WeaponDrop(Handle:event, const String:name[], bool:dontBroadcast)
  72. {
  73.     new client = GetClientOfUserId(GetEventInt(event, "userid"));
  74.    
  75.     if (client == 0 || !IsClientConnected(client) || !IsClientInGame(client) || GetClientTeam(client) != 2) return;
  76.    
  77.     if (GetPlayerWeaponSlot(client, slot) > 0)
  78.     {
  79.         new String:weapon[32];
  80.         new ammo;
  81.         new clip;
  82.         new upgrade;
  83.         new upammo;
  84.         new ammoOffset = FindSendPropInfo("CTerrorPlayer", "m_iAmmo");
  85.         GetEdictClassname(GetPlayerWeaponSlot(client, slot), weapon, 32);
  86.        
  87.         if (slot == 0)
  88.         {
  89.             clip = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_iClip1");
  90.             upgrade = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_upgradeBitVec");
  91.             upammo = GetEntProp(GetPlayerWeaponSlot(client, 0), Prop_Send, "m_nUpgradedPrimaryAmmoLoaded");
  92.             if (StrEqual(weapon, "weapon_rifle") || StrEqual(weapon, "weapon_rifle_sg552") || StrEqual(weapon, "weapon_rifle_desert") || StrEqual(weapon, "weapon_rifle_ak47"))
  93.             {
  94.                 ammo = GetEntData(client, ammoOffset+(12));
  95.                 SetEntData(client, ammoOffset+(12), 0);
  96.             }
  97.             else if (StrEqual(weapon, "weapon_smg") || StrEqual(weapon, "weapon_smg_silenced") || StrEqual(weapon, "weapon_smg_mp5"))
  98.             {
  99.                 ammo = GetEntData(client, ammoOffset+(20));
  100.                 SetEntData(client, ammoOffset+(20), 0);
  101.             }
  102.             else if (StrEqual(weapon, "weapon_pumpshotgun") || StrEqual(weapon, "weapon_shotgun_chrome"))
  103.             {
  104.                 ammo = GetEntData(client, ammoOffset+(28));
  105.                 SetEntData(client, ammoOffset+(28), 0);
  106.             }
  107.             else if (StrEqual(weapon, "weapon_autoshotgun") || StrEqual(weapon, "weapon_shotgun_spas"))
  108.             {
  109.                 ammo = GetEntData(client, ammoOffset+(32));
  110.                 SetEntData(client, ammoOffset+(32), 0);
  111.             }
  112.             else if (StrEqual(weapon, "weapon_hunting_rifle"))
  113.             {
  114.                 ammo = GetEntData(client, ammoOffset+(36));
  115.                 SetEntData(client, ammoOffset+(36), 0);
  116.             }
  117.             else if (StrEqual(weapon, "weapon_sniper_scout") || StrEqual(weapon, "weapon_sniper_military") || StrEqual(weapon, "weapon_sniper_awp"))
  118.             {
  119.                 ammo = GetEntData(client, ammoOffset+(40));
  120.                 SetEntData(client, ammoOffset+(40), 0);
  121.             }
  122.             else if (StrEqual(weapon, "weapon_grenade_launcher"))
  123.             {
  124.                 ammo = GetEntData(client, ammoOffset+(68));
  125.                 SetEntData(client, ammoOffset+(68), 0);
  126.             }
  127.         }
  128.         new index = CreateEntityByName(weapon);
  129.         new Float:origin[3];
  130.         GetEntPropVector(client, Prop_Send, "m_vecOrigin", origin);
  131.         origin[2]+=20;
  132.         TeleportEntity(index, origin, NULL_VECTOR, NULL_VECTOR);
  133.  
  134.         DispatchSpawn(index);
  135.         ActivateEntity(index);
  136.         RemovePlayerItem(client, GetPlayerWeaponSlot(client, slot));
  137.  
  138.         if (slot == 0)
  139.         {
  140.             SetEntProp(index, Prop_Send, "m_iExtraPrimaryAmmo", ammo);
  141.             SetEntProp(index, Prop_Send, "m_iClip1", clip);
  142.             SetEntProp(index, Prop_Send, "m_upgradeBitVec", upgrade);
  143.             SetEntProp(index, Prop_Send, "m_nUpgradedPrimaryAmmoLoaded", upammo);
  144.         }
  145.     }
  146. }
  147. */
  148. public Event_PlayerUse(Handle:event, const String:name[], bool:dontBroadcast)
  149. {
  150.     new playerClient = GetClientOfUserId(GetEventInt(event, "userid"));
  151.    
  152.     new entityId = GetEventInt(event, "targetid");
  153.    
  154.     decl String:ent_name[64];
  155.    
  156.     if (IsValidEdict(entityId))
  157.     {
  158.         GetEdictClassname(entityId, ent_name, sizeof(ent_name)); //get the entities name
  159.        
  160.         if (StrEqual(ent_name, "weapon_ammo_spawn", false))
  161.         {
  162.             new weaponIndex = GetPlayerWeaponSlot(playerClient, 0);
  163.            
  164.             if(weaponIndex == -1)
  165.             return;
  166.            
  167.             new String:classname[64];
  168.            
  169.             GetEdictClassname(weaponIndex, classname, sizeof(classname));
  170.            
  171.             if(StrEqual(classname, "weapon_rifle_m60"))
  172.             {
  173.                 new iClip1 = GetEntProp(weaponIndex, Prop_Send, "m_iClip1");
  174.                 new iPrimType = GetEntProp(weaponIndex, Prop_Send, "m_iPrimaryAmmoType");
  175.                 SetEntProp(playerClient, Prop_Send, "m_iAmmo", (GetConVarInt(m60amount_max)-iClip1), _, iPrimType);
  176.             }
  177.             else if(StrEqual(classname, "weapon_grenade_launcher"))
  178.             {
  179.                 new iClip1 = GetEntProp(weaponIndex, Prop_Send, "m_iClip1");
  180.                 new iPrimType = GetEntProp(weaponIndex, Prop_Send, "m_iPrimaryAmmoType");
  181.                 SetEntProp(playerClient, Prop_Send, "m_iAmmo", (GetConVarInt(glamount_max)-iClip1), _, iPrimType);
  182.             }
  183.         }
  184.     }
  185.  
  186.     //CreateTimer(30.0, GunTimer, TIMER_FLAG_NO_MAPCHANGE);
  187. }
  188.  
  189.  
  190. public Action:Event_ItemPickup(Handle:event, const String:name[], bool:dontBroadcast)
  191. {
  192.    
  193.     new client = GetClientOfUserId(GetEventInt(event, "userid"))
  194.    
  195.     if (!client || !IsClientInGame(client)) return Plugin_Continue;
  196.     decl String:weaponname[128]
  197.     GetEventString(event, "item", weaponname, sizeof(weaponname))
  198.    
  199.     new targetgun = GetPlayerWeaponSlot(client, 0)
  200.     if (IsValidEdict(targetgun))
  201.     {
  202.         if (StrEqual(weaponname, "rifle_m60", false))
  203.         {
  204.             new ammmo = GetRandomInt(0, 200);
  205.             new M60 = GetRandomInt(GetConVarInt(m60ammo_min), GetConVarInt(m60ammo_max))
  206.            
  207.             SetConVarInt(sniperammo, M60)
  208.             SetEntProp(targetgun, Prop_Send, "m_iClip1", ammmo, 1)
  209.         }
  210.         else if (StrEqual(weaponname, "grenade_launcher", false))
  211.         {
  212.             new GrenadeLauncher = GetRandomInt(GetConVarInt(glammo_min), GetConVarInt(glammo_max))
  213.            
  214.             SetConVarInt(glammo, GrenadeLauncher)
  215.         }
  216.     }
  217.     return Plugin_Continue;
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement