hi
- User
hi
- Assistant
Hello! How can I assist you today?
- User
using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using Oxide.Core; using Oxide.Game.Rust.Cui; using UnityEngine;
namespace Oxide.Plugins { [Info("IndustrialRecycler", "Marte6", "1.4.0")] [Description("Automate recycling by attaching storage and adapters to recyclers.")] class IndustrialRecycler : RustPlugin { #region Fields private static IndustrialRecycler _instance; private Configuration _config; private const string RecyclerPrefabPath = "assets/bundled/prefabs/static/recycler_static.prefab"; private const string InputStoragePrefabPath = "assets/content/vehicles/boats/rowboat/subents/rowboat_storage.prefab"; private const string OutputStoragePrefabPath = "assets/prefabs/deployable/hot air balloon/subents/hab_storage.prefab"; private const string AdapterPrefabPath = "assets/prefabs/deployable/playerioents/industrialadaptors/storageadaptor.deployed.prefab"; private const string SmallGeneratorItemName = "electric.generator.small"; private const string PermissionUseRecycler = "industrialrecycler.give"; private const string PermissionVip = "industrialrecycler.vip"; private const string PermissionAdmin = "industrialrecycler.admin"; private const string UiOverlayName = "IndustrialRecyclerMainPanel"; #endregion
#region Cache private readonly Dictionary<ulong, ulong> _recyclerOwners = new(); private readonly HashSet<ulong> _recyclerItemContainers = new(); private readonly HashSet<ulong> _inputItemContainers = new(); private readonly HashSet<ulong> _storageAdapters = new(); private readonly HashSet<ulong> _playersWithUi = new(); #endregion #region Game Hooks private void Init() { permission.RegisterPermission(PermissionUseRecycler, this); permission.RegisterPermission(PermissionVip, this); permission.RegisterPermission(PermissionAdmin, this); foreach (var command in _config.Commands) { cmd.AddChatCommand(command, this, nameof(CommandGetRecycler)); } cmd.AddChatCommand("upgraderecycler", this, nameof(CommandUpgradeRecycler)); cmd.AddConsoleCommand("industrialrecycler.openinput", this, nameof(OpenInputStorage)); cmd.AddConsoleCommand("industrialrecycler.openoutput", this, nameof(OpenOutputStorage)); } private void OnServerInitialized() { _instance = this; foreach (var recycler in UnityEngine.Object.FindObjectsOfType<Recycler>()) { if (recycler.OwnerID != 0UL) { recycler.gameObject.AddComponent<RecyclerComponent>(); } } } private void Unload() { foreach (var recyclerComponent in UnityEngine.Object.FindObjectsOfType<RecyclerComponent>()) { UnityEngine.Object.Destroy(recyclerComponent); } foreach (var player in BasePlayer.activePlayerList) { CuiHelper.DestroyUi(player, UiOverlayName); } } private void OnItemAddedToContainer(ItemContainer container, Item item) { Recycler recycler = container.entityOwner as Recycler ?? container.entityOwner?.GetParentEntity() as Recycler; if (recycler == null) return; var recyclerComponent = recycler.GetComponent<RecyclerComponent>(); if (recyclerComponent == null) return; bool isMainRecycler = container.entityOwner is Recycler; ulong containerUid = container.uid.Value; if (isMainRecycler && _recyclerItemContainers.Contains(containerUid)) { ProcessRecyclerItems(recyclerComponent, item); } else if (!isMainRecycler && _inputItemContainers.Contains(containerUid)) { recyclerComponent.HandleItemTransfers(); } } private void OnEntityBuilt(Planner planner, GameObject entityObject) { var player = planner?.GetOwnerPlayer(); var baseEntity = entityObject.GetComponent<BaseEntity>(); if (player == null || baseEntity == null || baseEntity.ShortPrefabName != "generator.small" || baseEntity.skinID != _config.RecyclerSkinId) return; int maxRecyclers = _config.MaxRecyclersPerPlayer; if (permission.UserHasPermission(player.UserIDString, PermissionAdmin)) { maxRecyclers = int.MaxValue; } else if (permission.UserHasPermission(player.UserIDString, PermissionVip)) { maxRecyclers = _config.MaxRecyclersVip; } if (_recyclerOwners.Count(entry => entry.Value == player.userID) >= maxRecyclers) { player.ChatMessage(lang.GetMessage("RecyclerLimitReached", this, player.UserIDString)); timer.Once(1, () => GiveRecyclerItem(player)); NextTick(() => baseEntity?.Kill()); return; } if (!InitializeRecyclerPlacement(player, baseEntity)) { player.ChatMessage(lang.GetMessage("InvalidPlacement", this, player.UserIDString)); timer.Once(1, () => GiveRecyclerItem(player)); } else { player.ChatMessage(lang.GetMessage("RecyclerPlaced", this, player.UserIDString)); } NextTick(() => baseEntity?.Kill()); } private object CanPickupEntity(BasePlayer player, IndustrialStorageAdaptor adapter) { if (adapter?.net?.ID.Value != null && _storageAdapters.Contains(adapter.net.ID.Value)) { adapter.GetParentEntity()?.GetParentEntity()?.Kill(); GiveRecyclerItem(player); player.ChatMessage(lang.GetMessage("RecyclerPickedUp", this, player.UserIDString)); return false; } return null; } private object OnEntityKill(Recycler recycler) { if (recycler.OwnerID != 0UL && _recyclerOwners.ContainsKey(recycler.net.ID.Value)) { _recyclerOwners.Remove(recycler.net.ID.Value); } return null; } void OnLootEntity(BasePlayer player, Recycler recycler) { if (recycler == null || player == null) return; if (recycler.OwnerID != 0UL && _recyclerOwners.ContainsKey(recycler.net.ID.Value)) { _playersWithUi.Add(player.userID); string recyclerId = recycler.net.ID.Value.ToString(); CreateUi(player, recyclerId); } } private void OnPlayerLootEnd(PlayerLoot playerLoot) { BasePlayer player = playerLoot.GetComponentInParent<BasePlayer>(); if (player == null) return; if (_playersWithUi.Contains(player.userID)) { _playersWithUi.Remove(player.userID); CuiHelper.DestroyUi(player, UiOverlayName); } } #endregion #region UI private void CreateUi(BasePlayer player, string recyclerId) { var container = new CuiElementContainer(); container.Add( new CuiPanel { CursorEnabled = true, Image = { Color = "0.3333333 0.3215686 0.2941177 1" }, RectTransform = { AnchorMin = _config.AnchorMin, AnchorMax = _config.AnchorMax, OffsetMin = "341.64 405.595", OffsetMax = "554.76 486.605", }, }, "Overlay", UiOverlayName ); container.Add( new CuiElement { Name = "Text", Parent = UiOverlayName, Components = { new CuiTextComponent { Text = "Industrial Recycler", Font = "robotocondensed-bold.ttf", FontSize = 20, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1", }, new CuiOutlineComponent { Color = "0 0 0 1", Distance = "1 1" }, new CuiRectTransformComponent { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-86.493 0", OffsetMax = "86.492 34.875", }, }, } ); container.Add( new CuiButton { Button = { Color = "0.3960785 0.4666667 0.2627451 1", Command = $"industrialrecycler.openinput {recyclerId}", Close = UiOverlayName, }, Text = { Text = "Input", Font = "robotocondensed-regular.ttf", FontSize = 18, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1", }, RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-104.206 -34.58", OffsetMax = "-2.394 -2.22", }, }, UiOverlayName, "Input" ); container.Add( new CuiButton { Button = { Color = "0.3960785 0.4666667 0.2627451 1", Command = $"industrialrecycler.openoutput {recyclerId}", Close = UiOverlayName, }, Text = { Text = "Output", Font = "robotocondensed-regular.ttf", FontSize = 18, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1", }, RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "1.994 -34.58", OffsetMax = "103.806 -2.22", }, }, UiOverlayName, "Output" ); CuiHelper.DestroyUi(player, UiOverlayName); CuiHelper.AddUi(player, container); } private void OpenInputStorage(ConsoleSystem.Arg arg) { OpenStorage(arg, true); } private void OpenOutputStorage(ConsoleSystem.Arg arg) { OpenStorage(arg, false); } private void OpenStorage(ConsoleSystem.Arg arg, bool isInput) { var player = arg.Player(); if (player == null) { return; } if (arg.Args.Length == 0) { return; } if (!uint.TryParse(arg.Args[0], out uint recyclerId)) { return; } var networkableId = new NetworkableId(recyclerId); var recycler = BaseNetworkable.serverEntities.Find(networkableId) as Recycler; if (recycler != null) { var recyclerComponent = recycler.GetComponent<RecyclerComponent>(); if (recyclerComponent != null) { var storage = isInput ? recyclerComponent.InputStorage : recyclerComponent.OutputStorage; player.inventory.loot.StartLootingEntity(storage, true); player.inventory.loot.AddContainer(storage.inventory); player.inventory.loot.SendImmediate(); player.ClientRPCPlayer(null, player, "RPC_OpenLootPanel", storage.panelName); } } } #endregion #region Main private void CommandGetRecycler(BasePlayer player, string command, string[] args) { if (player == null) return; if (!permission.UserHasPermission(player.UserIDString, PermissionUseRecycler)) { player.ChatMessage(lang.GetMessage("NoPermission", this, player.UserIDString)); return; } BasePlayer targetPlayer = player; if (args != null && args.Length > 0) { targetPlayer = BasePlayer.Find(args[0]); if (targetPlayer == null) { player.ChatMessage(lang.GetMessage("PlayerNotFound", this, player.UserIDString)); return; } } if (GiveRecyclerItem(targetPlayer)) { player.ChatMessage(lang.GetMessage("RecyclerGiven", this, player.UserIDString)); if (targetPlayer != player) { targetPlayer.ChatMessage(lang.GetMessage("RecyclerReceived", this, targetPlayer.UserIDString)); } } else { player.ChatMessage(lang.GetMessage("RecyclerNotGiven", this, player.UserIDString)); if (targetPlayer != player) { targetPlayer.ChatMessage(lang.GetMessage("RecyclerNotReceived", this, targetPlayer.UserIDString)); } } } private bool GiveRecyclerItem(BasePlayer player) { var recyclerItem = ItemManager.CreateByName(SmallGeneratorItemName, 1, _config.RecyclerSkinId); if (recyclerItem == null) return false; recyclerItem.name = "Recycler"; return player.inventory.GiveItem(recyclerItem); } private void CommandUpgradeRecycler(BasePlayer player, string command, string[] args) { if (!permission.UserHasPermission(player.UserIDString, PermissionUseRecycler)) { player.ChatMessage(lang.GetMessage("NoPermission", this, player.UserIDString)); return; } int maxRecyclers = _config.MaxRecyclersPerPlayer; if (permission.UserHasPermission(player.UserIDString, PermissionAdmin)) { maxRecyclers = int.MaxValue; } else if (permission.UserHasPermission(player.UserIDString, PermissionVip)) { maxRecyclers = _config.MaxRecyclersVip; } if (_recyclerOwners.Count(entry => entry.Value == player.userID) >= maxRecyclers) { player.ChatMessage(lang.GetMessage("RecyclerLimitReached", this, player.UserIDString)); return; } if (!UpgradeToIndustrialRecycler(player)) { player.ChatMessage(lang.GetMessage("NoRecyclerInView", this, player.UserIDString)); } else { player.ChatMessage(lang.GetMessage("RecyclerUpgraded", this, player.UserIDString)); } } private bool InitializeRecyclerPlacement(BasePlayer player, BaseEntity baseEntity, int turn = 0) { var supportingFoundation = FindSupportingFoundation(baseEntity); if (supportingFoundation == null) return false; var spawnedRecycler = SpawnRecyclerWithComponents(player, baseEntity, supportingFoundation, turn); if (spawnedRecycler == null) return false; spawnedRecycler.gameObject.AddComponent<RecyclerComponent>(); return true; } private bool InitializeUpgradeRecycler(BasePlayer player, Recycler recycler, int turn = 0) { var spawnedRecycler = UpgradeRecyclerWithComponents(player, recycler, turn); if (spawnedRecycler == null) return false; spawnedRecycler.gameObject.AddComponent<RecyclerComponent>(); return true; } private BuildingBlock FindSupportingFoundation(BaseEntity baseEntity) { Vector3 origin = baseEntity.transform.position + Vector3.up * 0.1f; if (Physics.Raycast(origin, Vector3.down, out RaycastHit hitData, 4f, LayerMask.GetMask("Construction"))) { return hitData.GetEntity() as BuildingBlock; } return null; } private Recycler SetupStorageAndAdapters(Recycler recycler, BasePlayer player, bool hideBoxes) { Vector3 inputOffset, inputAdapterOffset, outputOffset, outputAdapterOffset; Quaternion inputRotation, outputRotation, inputAdapterRotation, outputAdapterRotation; if (!hideBoxes) { inputOffset = new Vector3(-1.0f, 0.72f, 0.31f); inputAdapterOffset = new Vector3(0.00f, -0.15f, -0.25f); outputOffset = new Vector3(-0.9f, 0.72f, -0.09f); outputAdapterOffset = new Vector3(0.00f, 0.26f, -0.05f); inputRotation = Quaternion.Euler(90, 90, 180); outputRotation = Quaternion.Euler(180, 90, 180); inputAdapterRotation = Quaternion.Euler(180, 90, 270); outputAdapterRotation = Quaternion.Euler(0, 90, 0); } else { inputOffset = new Vector3(0.0f, 0.72f, 0.11f); inputAdapterOffset = new Vector3(0.836f, -0.3301f, 0.18f); outputOffset = new Vector3(-0.4f, 0.72f, 0.2f); outputAdapterOffset = new Vector3(-0.227f, 0.33f, 0.434f); inputRotation = Quaternion.Euler(0, 0, 180); outputRotation = Quaternion.Euler(180, 90, 180); inputAdapterRotation = Quaternion.Euler(0, 0, 0); outputAdapterRotation = Quaternion.Euler(180, 90, 0); } var inputStorage = SpawnEntity(InputStoragePrefabPath, recycler, player, inputOffset, inputRotation); SpawnEntity(AdapterPrefabPath, inputStorage, player, inputAdapterOffset, inputAdapterRotation); var outputStorage = SpawnEntity(OutputStoragePrefabPath, recycler, player, outputOffset, outputRotation); SpawnEntity(AdapterPrefabPath, outputStorage, player, outputAdapterOffset, outputAdapterRotation); return recycler; } private Recycler UpgradeRecyclerWithComponents(BasePlayer player, Recycler recycler, int turn = 0) { return SetupStorageAndAdapters(recycler, player, _config.HideBoxes); } private Recycler SpawnRecyclerWithComponents(BasePlayer player, BaseEntity baseEntity, BuildingBlock foundation, int turn = 0) { var recycler = SpawnEntity(RecyclerPrefabPath, foundation, player, baseEntity.transform.position, baseEntity.transform.rotation * Quaternion.Euler(0, 270 + turn, 0)) as Recycler; if (recycler == null) return null; return SetupStorageAndAdapters(recycler, player, _config.HideBoxes); } private BaseEntity SpawnEntity(string prefabPath, BaseEntity parent, BasePlayer player, Vector3 position, Quaternion rotation) { var entity = GameManager.server.CreateEntity(prefabPath, Vector3.zero, Quaternion.identity, true); if (entity == null) return null; entity.OwnerID = player.userID; if (parent != null) { entity.SetParent(parent, true); } if (parent is BuildingBlock) { entity.transform.position = position; entity.transform.rotation = rotation; } else { entity.transform.localPosition = position; entity.transform.localRotation = rotation; } entity.Spawn(); entity.SendNetworkUpdateImmediate(); return entity; } private void ProcessRecyclerItems(RecyclerComponent recyclerComponent, Item item) { if (item.position < 6) { recyclerComponent.Recycler.StartRecycling(); } else { if (!item.MoveToContainer(recyclerComponent.OutputStorage.inventory)) { recyclerComponent.Recycler.StopRecycling(); } } } private bool UpgradeToIndustrialRecycler(BasePlayer player) { if (Physics.Raycast(player.eyes.HeadRay(), out RaycastHit hit, 5f)) { BaseEntity baseEntity = hit.GetEntity(); if (baseEntity is Recycler recycler && recycler.OwnerID == player.userID) { if (!InitializeUpgradeRecycler(player, baseEntity as Recycler, 90)) { player.ChatMessage(lang.GetMessage("InvalidPlacement", this, player.UserIDString)); timer.Once(1, () => GiveRecyclerItem(player)); return false; } else { player.ChatMessage(lang.GetMessage("RecyclerPlaced", this, player.UserIDString)); } return true; } } return false; } #endregion #region Configuration private class Configuration { [JsonProperty("Commands")] public List<string> Commands { get; set; } [JsonProperty("Max Recyclers Per Player")] public int MaxRecyclersPerPlayer { get; set; } [JsonProperty("Max Recyclers Vip (industrialrecycler.vip)")] public int MaxRecyclersVip { get; set; } [JsonProperty("Recycler Item SkinId")] public ulong RecyclerSkinId { get; set; } [JsonProperty("Hide Boxes")] public bool HideBoxes { get; set; } [JsonProperty("AnchorMin")] public string AnchorMin { get; set; } [JsonProperty("AnchorMax")] public string AnchorMax { get; set; } [JsonProperty("Version")] public VersionNumber Version { get; set; } } protected override void LoadConfig() { base.LoadConfig(); try { _config = Config.ReadObject<Configuration>() ?? throw new Exception(); if (_config.Version < Version) { UpdateConfigVersion(); } if (string.IsNullOrEmpty(_config.AnchorMin)) { _config.AnchorMin = "0.5 0"; } if (string.IsNullOrEmpty(_config.AnchorMax)) { _config.AnchorMax = "0.5 0"; } SaveConfig(); } catch { PrintError("There is an error in your configuration file. Default values will be used."); LoadDefaultConfig(); } } protected override void LoadDefaultConfig() { _config = GetDefaultConfig(); } protected override void SaveConfig() { Config.WriteObject(_config); } private void UpdateConfigVersion() { PrintWarning("Configuration change detected! Updating settings."); _config.Version = Version; PrintWarning("Configuration update completed!"); } private Configuration GetDefaultConfig() { return new Configuration { Commands = new List<string> { "getrecycler", "irecycler", "giverecycler" }, MaxRecyclersPerPlayer = 1, MaxRecyclersVip = 2, RecyclerSkinId = 3357927081, HideBoxes = false, AnchorMin = "0.5 0", AnchorMax = "0.5 0", Version = Version, }; } #endregion #region Localization protected override void LoadDefaultMessages() { lang.RegisterMessages( new Dictionary<string, string> { ["NoPermission"] = "You do not have permission to use this command.", ["RecyclerLimitReached"] = "You have reached the recycler limit.", ["InvalidPlacement"] = "The recycler must be placed on a construction block.", ["RecyclerPlaced"] = "Recycler placed successfully.", ["RecyclerPickedUp"] = "Recycler picked up, item returned to inventory.", ["RecyclerGiven"] = "Recycler given to your inventory.", ["RecyclerReceived"] = "You have received a recycler.", ["RecyclerNotGiven"] = "Failed to give recycler.", ["RecyclerNotReceived"] = "Failed to receive recycler.", ["NoRecyclerInView"] = "No recycler in sight to upgrade.", ["PlayerNotFound"] = "The specified player could not be found.", }, this ); lang.RegisterMessages( new Dictionary<string, string> { ["NoPermission"] = "Você não tem permissão para usar este comando.", ["RecyclerLimitReached"] = "Você atingiu o limite de recicladores.", ["InvalidPlacement"] = "O reciclador deve ser colocado sobre um bloco de construção.", ["RecyclerPlaced"] = "Reciclador colocado com sucesso.", ["RecyclerPickedUp"] = "Reciclador recolhido, item devolvido ao inventário.", ["RecyclerGiven"] = "Reciclador fornecido ao seu inventário.", ["RecyclerReceived"] = "Você recebeu um reciclador.", ["RecyclerNotGiven"] = "Falha ao fornecer o reciclador.", ["RecyclerNotReceived"] = "Falha ao receber o reciclador.", ["NoRecyclerInView"] = "Nenhum reciclador à vista para atualizar.", ["PlayerNotFound"] = "O jogador especificado não pôde ser encontrado.", }, this, "pt-BR" ); lang.RegisterMessages( new Dictionary<string, string> { ["NoPermission"] = "Sie haben keine Erlaubnis, diesen Befehl zu verwenden.", ["RecyclerLimitReached"] = "Sie haben die Grenze für Recycler erreicht.", ["InvalidPlacement"] = "Der Recycler muss auf einem Baublock platziert werden.", ["RecyclerPlaced"] = "Recycler erfolgreich platziert.", ["RecyclerPickedUp"] = "Recycler aufgenommen, Artikel in das Inventar zurückgegeben.", ["RecyclerGiven"] = "Recycler wurde Ihrem Inventar hinzugefügt.", ["RecyclerReceived"] = "Sie haben einen Recycler erhalten.", ["RecyclerNotGiven"] = "Recycle fehlerhaft vorhanden.", ["RecyclerNotReceived"] = "Falschen Empfang des Recyclers.", ["NoRecyclerInView"] = "Kein Recycler in Sicht, um aufzurüsten.", ["PlayerNotFound"] = "Der angegebene Spieler konnte nicht gefunden werden.", }, this, "de" ); lang.RegisterMessages( new Dictionary<string, string> { ["NoPermission"] = "No tienes permiso para usar este comando.", ["RecyclerLimitReached"] = "Has alcanzado el límite de recicladores.", ["InvalidPlacement"] = "El reciclador debe colocarse en un bloque de construcción.", ["RecyclerPlaced"] = "Reciclador colocado con éxito.", ["RecyclerPickedUp"] = "Reciclador recogido, artículo devuelto al inventario.", ["RecyclerGiven"] = "Reciclador dado a tu inventario.", ["RecyclerReceived"] = "Has recibido un reciclador.", ["RecyclerNotGiven"] = "Fallo al dar el reciclador.", ["RecyclerNotReceived"] = "Fallo al recibir el reciclador.", ["NoRecyclerInView"] = "No hay reciclador a la vista para mejorar.", ["PlayerNotFound"] = "No se pudo encontrar al jugador especificado.", }, this, "es" ); } #endregion #region Component private class RecyclerComponent : MonoBehaviour { public Recycler Recycler { get; private set; } public StorageContainer InputStorage { get; private set; } public StorageContainer OutputStorage { get; private set; } private const int MaxStorageCapacity = 48; private const float TransferInterval = 10f; private void Awake() { foreach (MonoBehaviour mb in GetComponents<MonoBehaviour>()) { var type = mb.GetType(); if (type != typeof(Recycler) && type != typeof(RecyclerComponent) && type.Name != "Ground_Watch") { Destroy(mb); } } InitializeRecyclerComponents(); if (ValidateStorageContainers()) { RegisterEntities(); SetupRecycler(); InvokeRepeating(nameof(HandleItemTransfers), 0f, TransferInterval); } else { enabled = false; } } private void InitializeRecyclerComponents() { Recycler = GetComponent<Recycler>(); InputStorage = Recycler.children.OfType<StorageContainer>().FirstOrDefault(c => c?.name == InputStoragePrefabPath); OutputStorage = Recycler.children.OfType<StorageContainer>().FirstOrDefault(c => c?.name == OutputStoragePrefabPath); } private bool ValidateStorageContainers() { if (InputStorage == null || OutputStorage == null) { return false; } return true; } private void RegisterEntities() { _instance._inputItemContainers.Add(InputStorage.inventory.uid.Value); _instance._recyclerItemContainers.Add(Recycler.inventory.uid.Value); var inputAdapter = InputStorage.children.OfType<IndustrialStorageAdaptor>().FirstOrDefault(); if (inputAdapter != null) _instance._storageAdapters.Add(inputAdapter.net.ID.Value); var outputAdapter = OutputStorage.children.OfType<IndustrialStorageAdaptor>().FirstOrDefault(); if (outputAdapter != null) _instance._storageAdapters.Add(outputAdapter.net.ID.Value); } private void SetupRecycler() { _instance._recyclerOwners[Recycler.net.ID.Value] = Recycler.OwnerID; InputStorage.inventory.capacity = MaxStorageCapacity; OutputStorage.inventory.capacity = MaxStorageCapacity; } public void HandleItemTransfers() { int availableRecyclerSlots = 6 - Recycler.inventory.itemList.Count; if (OutputStorage.inventory.IsFull()) { Recycler.StopRecycling(); return; } TransferItemsFromRecyclerToOutput(ref availableRecyclerSlots); TransferItemsFromInputToRecycler(ref availableRecyclerSlots); if (availableRecyclerSlots < 6 && Recycler.inventory.itemList.Count > 0) { Recycler.StartRecycling(); } } private void TransferItemsFromRecyclerToOutput(ref int availableRecyclerSlots) { for (int slot = 6; slot < Recycler.inventory.capacity; slot++) { var itemInRecycler = Recycler.inventory.GetSlot(slot); if (itemInRecycler != null && itemInRecycler.MoveToContainer(OutputStorage.inventory)) { availableRecyclerSlots++; } } } private void TransferItemsFromInputToRecycler(ref int availableRecyclerSlots) { var inputItems = new List<Item>(InputStorage.inventory.itemList); foreach (var item in inputItems) { if (item.info.Blueprint != null) { MoveItemToRecycler(item, ref availableRecyclerSlots); } else { item.MoveToContainer(OutputStorage.inventory); } } } private void MoveItemToRecycler(Item item, ref int availableRecyclerSlots) { if (availableRecyclerSlots <= 0) return; for (int slot = 0; slot < 6; slot++) { if (Recycler.inventory.GetSlot(slot) == null && item.MoveToContainer(Recycler.inventory, slot)) { availableRecyclerSlots--; break; } } } private void OnDestroy() { CancelInvoke(nameof(HandleItemTransfers)); } } #endregion }}
- Assistant
The code you've shared is for an Oxide plugin designed for the game Rust. This specific plugin, called "IndustrialRecycler," automates the recycling process by allowing players to attach storage and adapters to recyclers. Here's a brief overview of its functionality:
-
Permissions and Commands:
- The plugin registers permissions (
PermissionUseRecycler,PermissionVip,PermissionAdmin) to control which players can use, upgrade, or administer the recyclers. - It allows configuring chat and console commands via the
_config.Commandslist. Basic commands include getting a recycler, upgrading it, and opening storage containers.
- The plugin registers permissions (
-
Game Hooks and Events:
- On server initialization, it attaches a
RecyclerComponentto each recycler, assuming it has an owner. - It handles events such as item additions to containers (
OnItemAddedToContainer), entity building (OnEntityBuilt), item looting (OnLootEntity), and more. - Allows upgrading existing recyclers and spawning new ones with attached storage and adapters.
- On server initialization, it attaches a
-
Recycling Logic:
- The
RecyclerComponentfacilitates item transfers between input storage, the recycler itself, and output storage. - The component runs at regular intervals to automate recycling, starting and stopping the recycler as needed based on available space and item types.
- The
-
User Interface (UI):
- The plugin provides a UI overlay to allow players to interact with the input and output storage through buttons.
-
Configuration:
- The plugin supports configuration, which can set parameters like the maximum number of recyclers per player, VIP allowances, skin IDs, UI anchor positions, etc.
-
Localization:
- It provides support for multiple languages, allowing for easy translation and customization of messages displayed to players.
-
Deployment:
- This code is deployed as part of a modded Rust server and requires Oxide to be installed. It involves creating prefabs for the recycler and connected items and providing appropriate permissions and configurations for users.
If there are specific aspects of the code you would like to discuss or need help with, feel free to ask!
-
- User
update this description with the new code: About Industrial Recycler The plugin automates the standard recycler in Rust by introducing two inventories: an input inventory, for manual or industrial item placement, automatically feeding the recycler, and an output inventory for auto-transferring recycled items. This setup enables automatic start and continuous recycling without interruptions, preventing items from being locked or dropped. The automation ensures a seamless, efficient process, enhancing resource management for players.
Chat Command (Customizable): /getrecycler
Permission Required to Use Command: industrialrecycler.give
Dual Inventory System: An input inventory for item placement, either manually or via industrial methods, automatically feeds items into the recycler.
Automated Recycling Start: The recycler begins processing automatically upon receiving items, eliminating the need for manual activation.
Continuous Operation: Ensures seamless recycling without interruptions, maintaining a fluid process and preventing item backlog.
Automatic Output Transfer: Recycled items are transferred directly to the output inventory, avoiding item lock or ground drops.
Enhanced Resource Management: Streamlines the recycling process, saving players time and optimizing resource handling within the game.
- Assistant
Here's an updated description for the Industrial Recycler plugin, incorporating the new code:
About Industrial Recycler
The Industrial Recycler plugin enhances the recycling process in Rust by introducing additional functionalities to the standard recycler. It provides two separate inventories: an input inventory for manually or industrially feeding items into the recycler and an output inventory for automatically transferring recycled items. This setup allows for automatic start and continuous, uninterrupted recycling, which prevents items from being locked or dropped. The automated process ensures efficiency, improving resource management for players and streamlining in-game activities.
Features:
-
Chat Command (Customizable):
/getrecycler- Permission Required to Use Command:
industrialrecycler.give
- Permission Required to Use Command:
-
Dual Inventory System:
- An input inventory accepts items placed manually or via industrial methods, automatically feeding them into the recycler.
-
Automated Recycling Start:
- The recycler starts processing automatically upon receiving items, removing the need for manual activation.
-
Continuous Operation:
- Ensures seamless recycling without interruptions, maintaining a fluid process and preventing item backlog.
-
Automatic Output Transfer:
- Recycled items are directly transferred to the output inventory, preventing item lock-ups or ground drops.
-
Enhanced Resource Management:
- Streamlines the recycling process, saving players time and optimizing resource handling within the game.
This plugin offers an efficient recycling solution, making it a vital tool for players seeking to optimize their resource management strategies in Rust.
-
- User
Chat Command can accept player to give, updade
- Assistant
Certainly! Here's the updated description, including the ability for the chat command to accept a player target for giving a recycler:
About Industrial Recycler
The Industrial Recycler plugin enhances the recycling process in Rust by introducing additional functionalities to the standard recycler. It provides two separate inventories: an input inventory for manually or industrially feeding items into the recycler and an output inventory for automatically transferring recycled items. This setup allows for automatic start and continuous, uninterrupted recycling, which prevents items from being locked or dropped. The automated process ensures efficiency, improving resource management for players and streamlining in-game activities.
Features:
-
Chat Command (Customizable):
/getrecycler [player]- Allows players with the necessary permissions to give a recycler to themselves or specify another player as the target.
- Permission Required to Use Command:
industrialrecycler.give
-
Dual Inventory System:
- An input inventory accepts items placed manually or via industrial methods, automatically feeding them into the recycler.
-
Automated Recycling Start:
- The recycler starts processing automatically upon receiving items, removing the need for manual activation.
-
Continuous Operation:
- Ensures seamless recycling without interruptions, maintaining a fluid process and preventing item backlog.
-
Automatic Output Transfer:
- Recycled items are directly transferred to the output inventory, preventing item lock-ups or ground drops.
-
Enhanced Resource Management:
- Streamlines the recycling process, saving players time and optimizing resource handling within the game.
This plugin offers an efficient recycling solution, making it a vital tool for players seeking to optimize their resource management strategies in Rust.
This updated description clarifies the functionality of the
/getrecyclercommand, including its ability to give a recycler to a specified player. -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-3.5-turbo-0301Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →
- gpt-4-0314Compare side by side →