item que não podem ser reciclaados estão sumindo ao entrar, corrija using System; using…
- User
item que não podem ser reciclaados estão sumindo ao entrar, corrija using System; using System.Collections.Generic; using System.Linq; using Facepunch; using Newtonsoft.Json; using Oxide.Core.Libraries.Covalence; using Oxide.Core.Plugins; using Oxide.Game.Rust.Cui; using UnityEngine;
namespace Oxide.Plugins { [Info("Recyclerbox", "Marte6", "2.1.1")] [Description("Turn a large wooden box into a Recycler.")] public class Recyclerbox : CovalencePlugin { #region Fields
private Configuration _config; [PluginReference] private Plugin NoEscape; // Reference to NoEscape plugin for raid block checks private const string UiOverlay = "RecyclerOverlay"; private const string PrefabLargeBox = "assets/prefabs/deployable/large wood storage/box.wooden.large.prefab"; private const string PrefabItemDrop = "assets/prefabs/misc/item drop/item_drop.prefab"; private readonly Item.Flag ItemScrapedFlag = (Item.Flag)(1 << 78); private readonly Dictionary<ulong, (StorageContainer recyclerBox, BasePlayer player)> recyclerInstances = new(); private readonly Dictionary<ulong, (DroppedItemContainer container, BasePlayer player)> droppedContainers = new(); #endregion Fields #region Permissions private const string PermGet = "recyclerbox.get"; private const string PermTransform = "recyclerbox.transform"; private const string PermVirtual = "recyclerbox.virtual"; private static readonly List<string> PermissionList = new() { PermGet, PermTransform, PermVirtual }; #endregion Permissions #region Initialization private void OnServerInitialized() { // Register permissions and commands foreach (string perm in PermissionList) permission.RegisterPermission(perm, this); AddCovalenceCommand(_config.CommandsGet, nameof(CmdGetRecyclerBox)); AddCovalenceCommand(_config.CommandsTransform, nameof(CmdTransformRecyclerBox)); AddCovalenceCommand(_config.CommandsVirtual, nameof(CmdOpenVirtualRecyclerBox)); } private void Unload() { // Cleanup on plugin unload foreach (BasePlayer player in BasePlayer.activePlayerList) { CuiHelper.DestroyUi(player, UiOverlay); DestroyVirtualRecycler(player); } DestroyTemporaryContainers(); } #endregion Initialization #region Configuration protected class Configuration { [JsonProperty("Get Recycler Box Command")] public string[] CommandsGet { get; set; } = { "getrec", "getrecycler", "recyclerbox" }; [JsonProperty("Transform Recycler Box Command")] public string[] CommandsTransform { get; set; } = { "trarec", "boxtorecycler", "transformrecycler", "transformbox" }; [JsonProperty("Virtual Recycler Box Command")] public string[] CommandsVirtual { get; set; } = { "rec", "vrec", "virtualrecycler" }; [JsonProperty("Recycler Skin ID")] public ulong RecyclerSkinId { get; set; } = 2994391115; [JsonProperty("Recycler Efficiency")] public float RecyclerEfficiency { get; set; } = 0.6f; [JsonProperty("Scrap Ratio")] public float ScrapRatio { get; set; } = 1.2f; [JsonProperty("Enable Prefab Effects")] public bool EnablePrefabEffects { get; set; } = true; [JsonProperty("Lock Recycler While In Use")] public bool LockRecycler { get; set; } = false; [JsonProperty("Raid Block Required (No Escape plugin dependency)")] public bool RequireRaidBlock { get; set; } = true; [JsonProperty("Prefab Effect on Open")] public string PrefabOnOpen { get; set; } = "assets/bundled/prefabs/fx/build/promote_toptier.prefab"; [JsonProperty("Prefab Effect on Close")] public string PrefabOnClose { get; set; } = "assets/bundled/prefabs/fx/build/promote_toptier.prefab"; [JsonProperty("Transfer Recycled Items to Inventory")] public bool TransferToInventory { get; set; } = false; [JsonProperty("Blacklisted Items")] public string[] BlacklistedItems { get; set; } = { "lmg.m249" }; [JsonProperty("Blacklisted Skins")] public List<ulong> BlacklistedSkins { get; set; } = new() { 2994391115 }; public string ToJson() => JsonConvert.SerializeObject(this); public static Dictionary<string, object> FromJson(string json) => JsonConvert.DeserializeObject<Dictionary<string, object>>(json); } protected override void LoadDefaultConfig() => _config = new Configuration(); protected override void LoadConfig() { base.LoadConfig(); try { _config = Config.ReadObject<Configuration>(); if (_config == null) throw new JsonException(); var currentConfigDict = Configuration.FromJson(_config.ToJson()); var defaultConfigDict = Configuration.FromJson(new Configuration().ToJson()); if (currentConfigDict.Count != defaultConfigDict.Count) { Puts("Configuration appears outdated; updating and saving..."); SaveConfig(); } else { foreach (var key in currentConfigDict.Keys) { if (!defaultConfigDict.ContainsKey(key)) { Puts("Configuration appears outdated; updating and saving..."); SaveConfig(); break; } } } } catch { Puts("Configuration file is invalid; loading defaults."); LoadDefaultConfig(); } } protected override void SaveConfig() { Puts("Saving changes to configuration."); Config.WriteObject(_config, true); } #endregion Configuration #region Localization protected override void LoadDefaultMessages() { lang.RegisterMessages( new Dictionary<string, string> { ["RecyclerTitle"] = "RECYCLER BOX", ["RecyclerSubtitle"] = "Items are instantly recycled", ["RecyclerItemMissingMsg"] = "Recycler Box: You aren't holding a Large Wooden Box.", ["RecyclerCreatedMsg"] = "Recycler Box: The Box has been converted into a Recycler.", ["RecyclerAlreadyMsg"] = "Recycler Box: This Box is currently a Recycler.", ["NotAllowed"] = "You do not have permission to use that command.", ["GotRecyclerbox"] = "Recycler Box sent to inventory.", ["Denied Privilege"] = "You cannot recycle within someone's building privilege", ["Denied Swimming"] = "You cannot recycle while swimming", ["Denied Falling"] = "You cannot recycle while falling", ["Denied Mounted"] = "You cannot recycle while mounted", ["Denied Wounded"] = "You cannot recycle while wounded", ["Denied Ship"] = "You cannot recycle while on a ship", ["Denied Elevator"] = "You cannot recycle while on an elevator", ["Denied Balloon"] = "You cannot recycle while on a balloon", ["Denied Safe Zone"] = "You cannot recycle while in a safe zone", ["Denied Hook Denied"] = "You can't recycle right now", ["RecycleDropped"] = "You left items in the recycler and dropped them on the ground!", }, this ); lang.RegisterMessages( new Dictionary<string, string> { // Portuguese (Brazil) translations ["RecyclerTitle"] = "CAIXA RECICLADORA", ["RecyclerSubtitle"] = "Itens são reciclados instantaneamente", ["RecyclerItemMissingMsg"] = "Recyclerbox: Você não está segurando uma Caixa Grande de Madeira.", ["RecyclerCreatedMsg"] = "Recyclerbox: Você transformou a Caixa em um Reciclador.", ["RecyclerAlreadyMsg"] = "Recyclerbox: Esta Caixa já é um Reciclador.", ["NotAllowed"] = "Você não tem permissão para usar esse comando.", ["GotRecyclerbox"] = "Recyclerbox enviada para o inventário.", ["Denied Privilege"] = "Você não pode reciclar dentro do privilégio de construção de outro player", ["Denied Swimming"] = "Você não pode reciclar enquanto nada", ["Denied Falling"] = "Você não pode reciclar enquanto cai", ["Denied Mounted"] = "Você não pode reciclar enquanto estiver montado", ["Denied Wounded"] = "Você não pode reciclar enquanto estiver ferido", ["Denied Ship"] = "Você não pode reciclar enquanto estiver em um navio", ["Denied Elevator"] = "Você não pode reciclar enquanto estiver em um elevador", ["Denied Balloon"] = "Você não pode reciclar enquanto estiver em um balão", ["Denied Safe Zone"] = "Você não pode reciclar enquanto estiver em uma zona segura", ["Denied Hook Denied"] = "Você não pode reciclar agora", ["RecycleDropped"] = "Você deixou itens no reciclador e os deixou cair no chão!", }, this, "pt-BR" ); lang.RegisterMessages( new Dictionary<string, string> { // German translations ["RecyclerTitle"] = "RECYCLERBOX", ["RecyclerSubtitle"] = "Gegenstände werden sofort recycelt", ["RecyclerItemMissingMsg"] = "Recyclerbox: Du hast keine große Holzkiste in der Hand. (Blau hinterlegt)", ["RecyclerCreatedMsg"] = "Recyclerbox: Die Kiste wurde in ein Recyclerbox umgewandelt.", ["RecyclerAlreadyMsg"] = "Recyclerbox: Diese Kiste ist bereits eine Recyclerbox.", ["NotAllowed"] = "Du hast keine Berechtigung, diesen Befehl zu benutzen.", ["GotRecyclerbox"] = "Die Recyclerbox ist deinem Inventar gutgeschrieben worden.", ["Denied Privilege"] = "Du kannst momentan nicht recyceln, du befindest dich in einem fremden Bauradius.", ["Denied Swimming"] = "Du kannst momentan nicht recyceln, während Du schwimmst.", ["Denied Falling"] = "Du kannst momentan nicht recyceln, während Du im freienfall bist.", ["Denied Mounted"] = "Du kannst momentan nicht recyceln, während Du auf einem Fahrzeug sitzt.", ["Denied Wounded"] = "Du kannst momentan nicht recyceln, während Du verletzt bist.", ["Denied Ship"] = "Du kannst momentan nicht recyceln, da Du dich auf einem Schiff befindest.", ["Denied Elevator"] = "Du kannst momentan nicht recyceln, da Du dich im Aufzug befindest.", ["Denied Balloon"] = "Du kannst momentan nicht recyceln, da Du dich im Ballon befindest.", ["Denied Safe Zone"] = "Du kannst momentan nicht recyceln, da Du dich in einer sicheren Zone befindest.", ["Denied Hook Denied"] = "Du kannst momentan nicht recyceln.", ["RecycleDropped"] = "Du hast Gegenstände im Recycler gelassen und auf den Boden fallen lassen!", }, this, "de" ); } #endregion Localization #region Hooks private void OnLootEntityEnd(BasePlayer player, StorageContainer container) { // Remove UI when looting ends if (container.skinID != _config.RecyclerSkinId || player == null) return; DestroyVirtualRecycler(player); } private void OnPlayerDisconnected(BasePlayer player, string reason) { if (player == null) return; DestroyVirtualRecycler(player); if (droppedContainers.Count == 0) return; var containerList = Pool.Get<List<KeyValuePair<ulong, (DroppedItemContainer, BasePlayer)>>>(); containerList.AddRange(droppedContainers); foreach (var (uid, (container, target)) in containerList) { if (!IsEntityValid(container) || !IsEntityValid(target) || target.userID == player.userID) { if (IsEntityValid(container)) container.Kill(); droppedContainers.Remove(uid); } } Pool.FreeUnmanaged(ref containerList); } private void OnLootEntity(BasePlayer player, StorageContainer storageContainer) { if (storageContainer.skinID != _config.RecyclerSkinId) return; var itemContainer = storageContainer.inventory; itemContainer.capacity = 42; if (_config.EnablePrefabEffects) Effect.server.Run(_config.PrefabOnOpen, player.GetNetworkPosition()); if (_config.LockRecycler) itemContainer.entityOwner.SetFlag(BaseEntity.Flags.Locked, true); CreateUI(player); } private void OnItemRemovedFromContainer(ItemContainer container, Item item) { if (container?.entityOwner?.skinID == _config.RecyclerSkinId) { item.SetFlag(ItemScrapedFlag, false); } } private void OnItemAddedToContainer(ItemContainer container, Item item) { if (container?.entityOwner?.skinID != _config.RecyclerSkinId) return; if (item.flags.HasFlag(ItemScrapedFlag)) return; BasePlayer player = BasePlayer.FindByID(container.entityOwner.OwnerID); if (player != null && _config.RequireRaidBlock && IsRaidBlocked(player)) return; SalvageItem(container, item); } private void OnPlayerLootEnd(PlayerLoot inventory) { var player = inventory.baseEntity; if (player == null) return; foreach (var container in inventory.containers) { if (container?.entityOwner?.skinID == _config.RecyclerSkinId) { CuiHelper.DestroyUi(player, UiOverlay); if (!container.entityOwner.IsBusy()) { if (_config.EnablePrefabEffects) Effect.server.Run(_config.PrefabOnClose, player.GetNetworkPosition()); if (_config.LockRecycler) container.entityOwner.SetFlag(BaseEntity.Flags.Locked, false); } } } } private object CanLootEntity(BasePlayer player, DroppedItemContainer container) { if (container.IsValid() && droppedContainers.TryGetValue(container.net.ID.Value, out var tuple) && tuple.player.userID != player.userID) return true; return null; } private void OnEntityKill(DroppedItemContainer container) { if (IsEntityValid(container)) droppedContainers.Remove(container.net.ID.Value); } private object CanAcceptItem(ItemContainer container, Item item, int targetPos) { if (container?.entityOwner?.skinID == _config.RecyclerSkinId) { if (_config.BlacklistedItems.Contains(item.info.shortname) || _config.BlacklistedSkins.Contains(item.skin)) { return ItemContainer.CanAcceptResult.CannotAcceptRightNow; } } return null; } #endregion Hooks #region Utility Methods private bool IsRaidBlocked(BasePlayer player) { // Check if the player is raid-blocked via the NoEscape plugin return NoEscape != null && NoEscape.Call<bool>("IsRaidBlocked", player); } private void SalvageItem(ItemContainer container, Item item) { bool isFromVirtual = _config.TransferToInventory && container?.entityOwner?.name == "Virtual"; BasePlayer player = isFromVirtual ? BasePlayer.FindByID(container.entityOwner.OwnerID) : null; if (item.info.Blueprint == null || container == null) { TryMoveItemBack(item, container, player); return; } float efficiency = _config.RecyclerEfficiency; if (item.hasCondition) efficiency = Mathf.Clamp01(efficiency * item.conditionNormalized); int totalAmount = item.amount; if (item.info.Blueprint.scrapFromRecycle > 0) { ProduceScrap(item, container, player, isFromVirtual, efficiency, totalAmount); } foreach (var ingredient in item.info.Blueprint.ingredients) { if (ingredient.itemDef.shortname == "scrap") continue; float rawAmount = totalAmount * efficiency * ingredient.amount / item.info.Blueprint.amountToCreate; CreateResourceItem(ingredient.itemDef, rawAmount, container, player, isFromVirtual); } item.UseItem(totalAmount); } private void ProduceScrap(Item item, ItemContainer container, BasePlayer player, bool isFromVirtual, float efficiency, int totalAmount) { float scrapRatio = _config.ScrapRatio; float calculatedScrap = item.info.Blueprint.scrapFromRecycle * totalAmount * scrapRatio; int scrapAmount = Mathf.FloorToInt(calculatedScrap); if (scrapAmount > 0 || UnityEngine.Random.value < calculatedScrap - scrapAmount) { Item scrapItem = ItemManager.CreateByName("scrap", scrapAmount + 1); if (!isFromVirtual) scrapItem.SetFlag(ItemScrapedFlag, true); if (!TryMoveItemBack(scrapItem, container, player)) scrapItem.Drop(player?.GetCenter() ?? Vector3.zero, player?.GetDropVelocity() ?? Vector3.zero); } } private bool TryMoveItemBack(Item item, ItemContainer container, BasePlayer player) { if (container != null && item.MoveToContainer(container)) { return true; } // If cannot move into the container, drop items at player's position item.Drop(player?.GetCenter() ?? Vector3.zero, player?.GetDropVelocity() ?? Vector3.zero); return false; } // Correct goods creation upon recycling private void CreateResourceItem(ItemDefinition itemDef, float amount, ItemContainer container, BasePlayer player, bool isFromVirtual) { int itemsToCreate = Mathf.FloorToInt(amount); if (amount < 1f && UnityEngine.Random.value > 0.5f) itemsToCreate = 1; for (int i = itemsToCreate; i > 0; ) { int stackSize = Mathf.Min(itemDef.stackable, i); Item newItem = ItemManager.Create(itemDef, stackSize); if (!isFromVirtual) newItem.SetFlag(ItemScrapedFlag, true); if (!TryMoveItemBack(newItem, container, player)) newItem.Drop(player?.GetCenter() ?? Vector3.zero, player?.GetDropVelocity() ?? Vector3.zero); i -= stackSize; } } private void ProcessScrap(Item item, ItemContainer container, BasePlayer player, bool isFromVirtual, float efficiency, int totalAmount) { float scrapRatio = _config.ScrapRatio; float scrapCalc = item.info.Blueprint.scrapFromRecycle * totalAmount * scrapRatio; int scrapAmount = (int)scrapCalc; try { if (scrapAmount >= 1 || UnityEngine.Random.value < scrapRatio) { scrapAmount = Math.Max(scrapAmount, 1); Item scrapItem = ItemManager.CreateByName("scrap", scrapAmount); if (!isFromVirtual) scrapItem.SetFlag(ItemScrapedFlag, true); TryMoveItemBack(scrapItem, container, player); } } catch { Puts($"Error processing scrap from item {item.info.shortname}, amount {totalAmount}.", this); } } private void CreateUI(BasePlayer player) { var elements = new CuiElementContainer(); var mainUIPanel = elements.Add( new CuiPanel { Image = { Color = "1 0.96 0.88 0.15" }, RectTransform = { AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "192.5 610", OffsetMax = "572.5 633", }, CursorEnabled = false, }, "Overlay", UiOverlay ); elements.Add( new CuiLabel { Text = { Text = lang.GetMessage("RecyclerTitle", this, player.UserIDString), Align = TextAnchor.MiddleCenter, FontSize = 18, Color = "1 1 1 1", Font = "robotocondensed-bold.ttf", }, RectTransform = { AnchorMin = "0 0", AnchorMax = "1 3" }, }, mainUIPanel ); elements.Add( new CuiLabel { Text = { Text = lang.GetMessage("RecyclerSubtitle", this, player.UserIDString), Align = TextAnchor.MiddleCenter, FontSize = 14, Color = "1 1 1 1", Font = "robotocondensed-regular.ttf", }, RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" }, }, mainUIPanel ); CuiHelper.AddUi(player, elements); } public bool IsEntityValid(BaseNetworkable entity) => entity?.IsValid() == true && !entity.IsDestroyed; private StorageContainer CreateVirtualRecycler(BasePlayer player) { var recyclerBox = GameManager.server.CreateEntity(PrefabLargeBox, player.transform.position.WithY(-5f), Quaternion.identity) as StorageContainer; recyclerBox.skinID = _config.RecyclerSkinId; if (recyclerBox == null) return null; recyclerBox.enableSaving = false; recyclerBox.Spawn(); if (!IsEntityValid(recyclerBox)) return null; recyclerBox.name = "Virtual"; recyclerBox.OwnerID = player.userID; recyclerBox.SetFlag(BaseEntity.Flags.Locked, true); recyclerBox.UpdateNetworkGroup(); recyclerBox.gameObject.layer = 0; recyclerBox.SendNetworkUpdateImmediate(true); OpenContainer(player, recyclerBox); recyclerInstances[recyclerBox.net.ID.Value] = (recyclerBox, player); return recyclerBox; } private void OpenContainer(BasePlayer player, StorageContainer container) { player.Invoke( () => { if (IsEntityValid(container)) { player.EndLooting(); if (!player.inventory.loot.StartLootingEntity(container, false)) return; player.inventory.loot.AddContainer(container.inventory); player.inventory.loot.SendImmediate(); player.ClientRPC(RpcTarget.Player("RPC_OpenLootPanel", player), container.panelName); player.SendNetworkUpdate(); } }, 0.2f ); } private StorageContainer GetPlayerRecycler(ulong userId) { foreach (var (recycler, player) in recyclerInstances.Values) if (player?.userID == userId) return recycler; return null; } private void DropRecyclerContents(StorageContainer recyclerBox, BasePlayer player) { if (player?.inventory?.containerMain == null) return; if (recyclerBox?.inventory?.itemList == null || recyclerBox.inventory.itemList.Count == 0) return; var itemsToDrop = Pool.Get<List<Item>>(); itemsToDrop.AddRange(recyclerBox.inventory.itemList); player.ChatMessage(lang.GetMessage("RecycleDropped", this, player.UserIDString)); Pool.FreeUnmanaged(ref itemsToDrop); var dropContainer = GameManager.server.CreateEntity(PrefabItemDrop, player.transform.position + Vector3.up, default) as DroppedItemContainer; if (dropContainer == null) return; dropContainer.enableSaving = false; dropContainer.lootPanelName = "generic_resizable"; dropContainer.playerSteamID = player.userID; // Pass an array as expected by the TakeFrom method dropContainer.TakeFrom(new[] { recyclerBox.inventory }); dropContainer.Spawn(); if (IsEntityValid(dropContainer)) { droppedContainers[dropContainer.net.ID.Value] = (dropContainer, player); } } private void DestroyVirtualRecycler(BasePlayer player) { var recycler = GetPlayerRecycler(player.userID); if (IsEntityValid(recycler) && recyclerInstances.TryGetValue(recycler.net.ID.Value, out var instance)) { DropRecyclerContents(recycler, instance.player); recyclerInstances.Remove(recycler.net.ID.Value); recycler.Kill(); } } private void DestroyTemporaryContainers() { if (droppedContainers.Count == 0) return; var containerList = Pool.Get<List<KeyValuePair<ulong, (DroppedItemContainer, BasePlayer)>>>(); containerList.AddRange(droppedContainers); foreach (var (uid, (container, _)) in containerList) { if (IsEntityValid(container)) container.Kill(); droppedContainers.Remove(uid); } Pool.FreeUnmanaged(ref containerList); } private void OpenVirtualRecycler(BasePlayer player) { if (!player || !CanPlayerOpenRecycler(player)) return; DestroyVirtualRecycler(player); CreateVirtualRecycler(player); } private bool CanPlayerOpenRecycler(BasePlayer player) { string userString = player.UserIDString; if (!player?.IsAlive() ?? true) player.ChatMessage(lang.GetMessage("Denied Hook Denied", this, userString)); else if (player.IsWounded()) player.ChatMessage(lang.GetMessage("Denied Wounded", this, userString)); else if (!player.CanBuild()) player.ChatMessage(lang.GetMessage("Denied Privilege", this, userString)); else if (player.IsSwimming()) player.ChatMessage(lang.GetMessage("Denied Swimming", this, userString)); else if (!player.IsOnGround() || player.IsFlying || player.isInAir) player.ChatMessage(lang.GetMessage("Denied Falling", this, userString)); else if (player.isMounted || player.GetParentEntity() is BaseMountable) player.ChatMessage(lang.GetMessage("Denied Mounted", this, userString)); else if (player.GetComponentInParent<CargoShip>()) player.ChatMessage(lang.GetMessage("Denied Ship", this, userString)); else if (player.GetComponentInParent<HotAirBalloon>()) player.ChatMessage(lang.GetMessage("Denied Balloon", this, userString)); else if (player.GetComponentInParent<Lift>()) player.ChatMessage(lang.GetMessage("Denied Elevator", this, userString)); else return true; return false; } #endregion Utility Methods #region Command Handlers private void CmdGetRecyclerBox(IPlayer iplayer, string command, string[] args) { BasePlayer player = iplayer.Object as BasePlayer; if (player == null) return; if (!iplayer.HasPermission(PermGet)) { player.ChatMessage(lang.GetMessage("NotAllowed", this, player.UserIDString)); return; } var recyclerBox = ItemManager.CreateByName("box.wooden.large"); recyclerBox.skin = _config.RecyclerSkinId; player.GiveItem(recyclerBox, BaseEntity.GiveItemReason.PickedUp); player.ChatMessage(lang.GetMessage("GotRecyclerbox", this, player.UserIDString)); } private void CmdTransformRecyclerBox(IPlayer iplayer, string command, string[] args) { BasePlayer player = iplayer.Object as BasePlayer; if (player == null) return; if (!iplayer.HasPermission(PermTransform)) { player.ChatMessage(lang.GetMessage("NotAllowed", this, player.UserIDString)); return; } Item activeItem = player.GetActiveItem(); if (activeItem == null || activeItem.info.shortname != "box.wooden.large") { player.ChatMessage(lang.GetMessage("RecyclerItemMissingMsg", this, player.UserIDString)); return; } if (activeItem.skin == _config.RecyclerSkinId) { player.ChatMessage(lang.GetMessage("RecyclerAlreadyMsg", this, player.UserIDString)); return; } player.ChatMessage(lang.GetMessage("RecyclerCreatedMsg", this, player.UserIDString)); activeItem.skin = _config.RecyclerSkinId; } private void CmdOpenVirtualRecyclerBox(IPlayer iplayer, string command, string[] args) { BasePlayer player = iplayer.Object as BasePlayer; if (player == null) return; if (!iplayer.HasPermission(PermVirtual)) { player.ChatMessage(lang.GetMessage("NotAllowed", this, player.UserIDString)); return; } OpenVirtualRecycler(player); } #endregion Command Handlers } - Assistant
- User
não, item que não estão na black list estão sumindo, item que não são reciclaveis
- Assistant
- User
- Assistant
- User
Error while compiling Recyclerbox: 'Dictionary.KeyCollection' does not contain a definition for 'Any' and no accessible extension method 'Any' accepting a first argument of type 'Dictionary.KeyCollection' could be found (are you missing a using directive or an assembly reference?) | Line: 123, Pos: 98
- Assistant
O erro que você encontrou refere-se ao uso do método
Any()em uma coleção de chaves de um dicionário. No C#, o métodoAny()é um método de extensão do namespaceSystem.Linq, então, se o seu código não pode encontrarAny(), é provável que você não tenha importado esse namespace.Para corrigir isso, você pode adicionar a seguinte diretiva
usingno início do seu arquivo:using System.Linq;Alterações Necessárias
Aqui está uma versão corrigida do método em seu código, que deve funcionar sem problemas:
- User
Unable to load Recyclerbox. 'Dictionary.KeyCollection' does not contain a definition for 'Any' and no accessible extension method 'Any' accepting a first argument of type 'Dictionary.KeyCollection' could be found (are you missing a using directive or an assembly reference?) | Line: 124, Pos: 98
- Assistant
- User
Unable to load Recyclerbox. 'Dictionary.KeyCollection' does not contain a definition for 'Any' and no accessible extension method 'Any' accepting a first argument of type 'Dictionary.KeyCollection' could be found (are you missing a using directive or an assembly reference?) | Line: 124, Pos: 98
- Assistant
- User
Error while compiling Recyclerbox: 'Dictionary' does not contain a definition for 'ToList' and no accessible extension method 'ToList' accepting a first argument of type 'Dictionary' could be found (are you missing a using directive or an assembly reference?) | Line: 225, Pos: 70
- Assistant
O erro que você encontrou está relacionado ao uso da função
ToList()em umDictionary. A funçãoToList()é um método de extensão disponível no namespaceSystem.Linq, mas não pode ser aplicada diretamente em um dicionário sem converter adequadamente as chaves ou valores.Solução
Para resolver isso, você pode usar o método
Selectpara obter uma lista das chaves e, em seguida, chamarToList(). Vou atualizar a parte do seu código onde você está tentando copiar os valores do dicionário . - User
Error while compiling Recyclerbox: The name 'recipeToAdd' does not exist in the current context | Line: 421, Pos: 50
- Assistant
- User
Error while compiling Recyclerbox: The name 'player' does not exist in the current context | Line: 480, Pos: 63
- Assistant
- User
- Assistant
- User
não, a linha é aqui:
private void AddLabel(CuiElementContainer elements, string parentPanel, string langKey, int fontSize) { elements.Add( new CuiLabel { Text = { Text = lang.GetMessage(langKey, this, player.UserIDString), Align = TextAnchor.MiddleCenter, FontSize = fontSize, Color = "1 1 1 1", Font = fontSize == 18 ? "robotocondensed-bold.ttf" : "robotocondensed-regular.ttf", }, RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" }, }, parentPanel ); } - Assistant
Obrigado pela correção e pela paciência! O erro que você está vendo na linha que menciona
playerse deve ao fato de que a variávelplayernão está acessível dentro do método . - User
Error while compiling Recyclerbox: The name 'Pool' does not exist in the current context | Line: 558, Pos: 25
- Assistant
O erro "The name 'Pool' does not exist in the current context" indica que a variável ou classe não está acessível no contexto em que você está tentando usá-la. Isso geralmente acontece por alguns motivos, incluindo:
- User
The name 'Pool' does not exist in the current contextCS0103
private void DropRecyclerContents(StorageContainer recyclerBox, BasePlayer player) { if (player == null || player.inventory?.containerMain == null || recyclerBox?.inventory?.itemList.IsNullOrEmpty() != false) return; var items = Pool.Get<List<Item>>(); items.AddRange(recyclerBox.inventory.itemList); if (items.Count == 0) { Pool.FreeUnmanaged(ref items); return; } player.ChatMessage(lang.GetMessage("RecycleDropped", this, player.UserIDString)); var container = GameManager.server.CreateEntity(PrefabDrop, player.transform.position + Vector3.up) as DroppedItemContainer; if (container == null) return; container.enableSaving = false; container.lootPanelName = "generic_resizable"; container.playerSteamID = player.userID; container.TakeFrom(new[] { recyclerBox.inventory }); container.Spawn(); if (IsValid(container)) _droppedContainers[container.net.ID.Value] = (container, player); Pool.FreeUnmanaged(ref items); } - Assistant
- User
corrigi de outro modo, assim: using System; using System.Collections.Generic; using System.Collections.Generic; using System.Linq; using System.Linq; using Facepunch; using Newtonsoft.Json; using Oxide.Core; using Oxide.Core.Configuration; using Oxide.Core.Libraries.Covalence; using Oxide.Core.Plugins; using Oxide.Game.Rust.Cui; using UnityEngine;
- Assistant
Entendido! Parece que você corrigiu o problema de contexto ao incluir as namespaces corretas e usando as funções e classes disponíveis.
Só para esclarecer e recapitular o que você fez, aqui estão algumas dicas e boas práticas:
1. Importação de Namespaces
Certifique-se de que você está utilizando apenas as importações necessárias. Por exemplo, você não precisa importar
System.Collections.Generice duas vezes. Um exemplo simplificado de importações poderia ser: - User
- Assistant
- User
mande o código completo com as melhorias, e corrija o ui, estão ficando um em cima do outro, o título deve ficar acima
- Assistant
- User
estão ficando um em cima do outro, aqui está com era antes, corrija: private void CreateUI(BasePlayer player) { var elements = new CuiElementContainer();
var mainconfigpanel = elements.Add( new CuiPanel { Image = { Color = "1 0.96 0.88 0.15" }, RectTransform = { AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "192.5 610", OffsetMax = "572.5 633", }, CursorEnabled = false, }, "Overlay", overlay ); elements.Add( new CuiLabel { Text = { Text = lang.GetMessage("RecyclerTitle", this, player.UserIDString), Align = TextAnchor.MiddleCenter, FontSize = 18, Color = "1 1 1 1", Font = "robotocondensed-bold.ttf", }, RectTransform = { AnchorMin = "0 0", AnchorMax = "1 3" }, }, mainconfigpanel ); elements.Add( new CuiLabel { Text = { Text = lang.GetMessage("RecyclerSubtitle", this, player.UserIDString), Align = TextAnchor.MiddleCenter, FontSize = 14, Color = "1 1 1 1", Font = "robotocondensed-regular.ttf", }, RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" }, }, mainconfigpanel ); CuiHelper.AddUi(player, elements); } - Assistant
- User
as imagens precisam ficar uma acima da outra, corrija private void CreateUI(BasePlayer player) { var elements = new CuiElementContainer();
var mainConfigPanel = elements.Add( new CuiPanel { Image = { Color = "1 0.96 0.88 0.15" }, RectTransform = { AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "192.5 610", OffsetMax = "572.5 633", }, CursorEnabled = false, }, "Overlay", Overlay ); // Passar o player como argumento para AddLabel AddLabel(elements, mainConfigPanel, "RecyclerTitle", 18, player); AddLabel(elements, mainConfigPanel, "RecyclerSubtitle", 14, player); CuiHelper.AddUi(player, elements); } - Assistant
- User
- Assistant
- User
The name 'overlay' does not exist in the current contextCS0103 private void OnPlayerLootEnd(PlayerLoot inventory) { if (inventory.baseEntity is not BasePlayer player) return;
foreach (var container in inventory.containers) { if (IsValid(container?.entityOwner) && container.entityOwner.skinID == _config.SkinIdRecycler) { CuiHelper.DestroyUi(player, overlay); if (!container.entityOwner.IsBusy()) { if (_config.EnablePrefabFx) Effect.server.Run(_config.PrefabFxClose, player.GetNetworkPosition()); if (_config.LockRecycler) container.entityOwner.SetFlag(BaseEntity.Flags.Locked, false); } } } } - Assistant
O erro "The name 'overlay' does not exist in the current context" indica que a variável
overlaynão foi definida ou não está acessível no contexto em que você a está utilizando.Resolução
-
Verifique a Definição da Variável: No seu código, você tem
const string Overlay = "RecyclerOverlay";, mas você está tentando usaroverlay(com letra minúscula). Isso está gerando o erro porque, no contexto do seu métodoOnPlayerLootEnd,overlaynão é reconhecido. -
Corrija o Nome: Para corrigir o erro, você deve usar (com letra maiúscula) em vez de na chamada para .
-
- User
- Assistant