C#:
using System.Linq;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Fix RHIB on Cargoship", "bsdinis", "0.0.8")]
[Description("Adds missing containers to RHIBs on Cargoship")]
class FixCargoshipRHIB : RustPlugin
{
void OnServerInitialized()
{
string output = string.Empty;
foreach (BaseNetworkable entity in BaseNetworkable.serverEntities.ToList())
{
StorageContainer container = entity as StorageContainer;
if (container != null)
{
if ((container.ShortPrefabName != "fuel_storage" && container.ShortPrefabName != "rhib_storage") || container.parentEntity.IsValid(container.isServer) || Vector3.Distance(container.transform.position, Vector3.zero) > 5f) continue;
output += $"\nKilled unparented {container} at {container.transform.position}";
container.Kill();
continue;
}
RHIB rhib = entity as RHIB;
if (rhib != null)
{
CargoShip cargo = rhib.GetParentEntity() as CargoShip;
if (cargo == null || rhib.fuelSystem.fuelStorageInstance.Get(rhib.fuelSystem.isServer) != null) continue;
output += $"\nKilled {rhib} with missing fuel container on {cargo}";
rhib.Kill();
RHIB escapeBoat = GameManager.server.CreateEntity(cargo.escapeBoatPrefab.resourcePath, cargo.escapeBoatPoint.position, cargo.escapeBoatPoint.rotation, true) as RHIB;
if (escapeBoat == null) continue;
output += $"\n Spawned new {escapeBoat} for {cargo}";
escapeBoat.enableSaving = false;
escapeBoat.SetParent(cargo, true, false);
escapeBoat.Spawn();
escapeBoat.rigidBody.isKinematic = true;
timer.Once(0.25f, () =>
{
if (escapeBoat == null) return;
StorageContainer storageContainer = escapeBoat.fuelSystem.fuelStorageInstance.Get(escapeBoat.fuelSystem.isServer);
if (storageContainer == null) return;
ItemContainer itemContainer = storageContainer.inventory;
if (itemContainer == null) return;
Item fuel = ItemManager.CreateByItemID(-946369541, 50);
if (fuel != null && !fuel.MoveToContainer(itemContainer, 0, false, false)) fuel.Remove();
});
}
}
if (output != string.Empty) PrintWarning(output);
}
}
}