C#:
using System.Collections.Generic;
using System.Linq;
using Oxide.Core.Plugins;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Rocket More Ammo", "Assistant", "1.0.0")]
[Description("Increases the base rocket launcher magazine capacity to 8.")]
public partial class RocketMoreAmmo : RustPlugin
{
private const string ROCKET_LAUNCHER_ITEM_SHORTNAME = "rocket.launcher";
private const string ROCKET_LAUNCHER_PREFAB_LOWER = "rocket.launcher";
private const int NEW_CAPACITY = 8;
private const int ORIGINAL_CAPACITY = 1;
private void OnServerInitialized(bool initial)
{
UpdateAllLaunchers(NEW_CAPACITY);
}
private void Unload()
{
UpdateAllLaunchers(ORIGINAL_CAPACITY);
}
private void UpdateAllLaunchers(int targetCapacity)
{
List<BaseProjectile> projectiles = BaseNetworkable
.serverEntities.OfType<BaseProjectile>()
.Where(p => p.ShortPrefabName?.Contains(ROCKET_LAUNCHER_PREFAB_LOWER) == true)
.ToList();
foreach (var projectile in projectiles)
{
if (projectile.primaryMagazine != null)
{
projectile.primaryMagazine.capacity = targetCapacity;
projectile.SendNetworkUpdate(BasePlayer.NetworkQueue.Count);
}
}
if (projectiles.Count > 0)
{
Puts(
$"Updated {projectiles.Count} existing Rocket Launchers to capacity {targetCapacity}."
);
}
}
private void OnItemAddedToContainer(ItemContainer container, Item item)
{
if (
container == null
|| item == null
|| item.info.shortname != ROCKET_LAUNCHER_ITEM_SHORTNAME
)
{
return;
}
BaseProjectile? projectile = item.GetHeldEntity() as BaseProjectile;
if (projectile == null || projectile.primaryMagazine == null)
return;
projectile.primaryMagazine.capacity = NEW_CAPACITY;
projectile.SendNetworkUpdate(BasePlayer.NetworkQueue.Count);
BasePlayer owner = container.playerOwner ?? item.GetOwnerPlayer();
if (owner?.inventory != null)
{
owner.inventory.ServerUpdate(0f);
}
}
private object? OnWeaponReload(BaseProjectile projectile, BasePlayer player)
{
if (projectile == null || projectile.primaryMagazine == null || player == null)
return null;
if (projectile.ShortPrefabName?.Contains(ROCKET_LAUNCHER_PREFAB_LOWER) == true)
{
projectile.primaryMagazine.capacity = NEW_CAPACITY;
projectile.SendNetworkUpdate(BasePlayer.NetworkQueue.Count);
player.inventory?.ServerUpdate(0f);
}
return null;
}
private object? OnMagazineReload(
BaseProjectile projectile,
IAmmoContainer desiredAmount,
BasePlayer player
)
{
return OnWeaponReload(projectile, player);
}
private void OnWeaponFired(
BaseProjectile projectile,
BasePlayer player,
ItemModProjectile mod,
ProtoBuf.ProjectileShoot projectiles
)
{
if (projectile == null || projectile.primaryMagazine == null || player == null)
return;
if (projectile.ShortPrefabName?.Contains(ROCKET_LAUNCHER_PREFAB_LOWER) == true)
{
projectile.primaryMagazine.capacity = NEW_CAPACITY;
projectile.SendNetworkUpdate(BasePlayer.NetworkQueue.Count);
player.inventory?.ServerUpdate(0f);
}
}
}
}