using Oxide.Core.Plugins; using Oxide.Core; using UnityEngine; namespace Oxide.Plugins { [Info("InventoryCleaner", " F3 ♥", "1.0.1")] [Description("A plugin to clear and manage player inventories.")] class InventoryCleaner : RustPlugin { private const string PermissionName = "inventorycleaner.use"; private void Init() { permission.RegisterPermission(PermissionName, this); Puts("InventoryCleaner initialized."); } [ChatCommand("cl")] private void ClearPlayerInventory(BasePlayer player, string command, string[] args) { if (!HasPermission(player)) { player.ChatMessage("You do not have permission to use this command."); return; } if (args.Length == 0) { player.ChatMessage("Usage: /cl "); return; } BasePlayer target = FindPlayer(args[0]); if (target == null) { player.ChatMessage("Player not found."); return; } ClearInventory(target); player.ChatMessage($"Cleared inventory of {target.displayName}."); } [ChatCommand("cc")] private void ClearSelfInventory(BasePlayer player, string command, string[] args) { if (!HasPermission(player)) { player.ChatMessage("You do not have permission to use this command."); return; } ClearInventory(player); player.ChatMessage("Your inventory has been cleared."); } [ChatCommand("cw")] private void ClearLookedAtInventory(BasePlayer player, string command, string[] args) { if (!HasPermission(player)) { player.ChatMessage("You do not have permission to use this command."); return; } BasePlayer target = GetLookedAtPlayer(player); if (target == null) { player.ChatMessage("No player found in your line of sight."); return; } DropInventory(target); player.ChatMessage($"Dropped all items from {target.displayName}'s inventory."); } private void ClearInventory(BasePlayer target) { if (target?.inventory?.containerMain != null) { target.inventory.containerMain.Clear(); } if (target?.inventory?.containerBelt != null) { target.inventory.containerBelt.Clear(); } if (target?.inventory?.containerWear != null) { target.inventory.containerWear.Clear(); } } private void DropInventory(BasePlayer target) { if (target == null) return; foreach (var item in target.inventory.containerMain.itemList.ToArray()) { item.Drop(target.transform.position, Vector3.zero); } foreach (var item in target.inventory.containerBelt.itemList.ToArray()) { item.Drop(target.transform.position, Vector3.zero); } foreach (var item in target.inventory.containerWear.itemList.ToArray()) { item.Drop(target.transform.position, Vector3.zero); } } private bool HasPermission(BasePlayer player) { return permission.UserHasPermission(player.UserIDString, PermissionName); } private BasePlayer FindPlayer(string identifier) { foreach (BasePlayer player in BasePlayer.activePlayerList) { if (player.UserIDString == identifier || player.displayName.ToLower().Contains(identifier.ToLower())) { return player; } } return null; } private BasePlayer GetLookedAtPlayer(BasePlayer player) { RaycastHit hit; if (Physics.Raycast(player.eyes.HeadRay(), out hit)) { BasePlayer target = hit.GetEntity() as BasePlayer; return target; } return null; } // Plugin Logo [ConsoleCommand("inventorycleaner.logo")] private void ShowLogo(ConsoleSystem.Arg arg) { Puts(@" _____ _ _ |_ _| (_) (_) | | _ __ ___ _ _ __ _ _ __ __ _ _ __ _ _ | | | '_ \/ __| | '_ \| | '_ \ / _` | '__| | | | _| |_| | | \__ \ | | | | | | | | (_| | | | |_| | |_____|_| |_|___/_|_| |_|_|_| |_|\__,_|_| \__, | __/ | |___/ "); } } }