using Oxide.Core; using Oxide.Core.Configuration; using Rust; using System.Collections.Generic; using UnityEngine; namespace Oxide.Plugins { [Info("RugSkinner", "Chernarust", "1.0.0")] [Description("Automatically adds a bear rug to the player's inventory when they skin a bear or polar bear, with permissions support and a one-rug limit per bear using data storage.")] public class RugSkinner : RustPlugin { private const string BearRugShortName = "rug.bear"; private const string PermissionUse = "rugskinner.use"; private DynamicConfigFile bearDataFile; private StoredData storedData; private class StoredData { public HashSet SkinnedBearIDs = new HashSet(); } private void Init() { permission.RegisterPermission(PermissionUse, this); bearDataFile = Interface.Oxide.DataFileSystem.GetFile("RugSkinner"); LoadData(); Puts("RugSkinner loaded!"); } private void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item) { if (dispenser == null || entity == null || item == null) return; var player = entity.ToPlayer(); if (player == null || !permission.UserHasPermission(player.UserIDString, PermissionUse)) return; if ((dispenser.name.Contains("bear") || dispenser.name.Contains("polarbear")) && item.info.shortname == "fat.animal") { uint bearID = (uint)dispenser.GetInstanceID(); if (!storedData.SkinnedBearIDs.Contains(bearID)) { storedData.SkinnedBearIDs.Add(bearID); SaveData(); GiveBearRug(player, bearID); } } } private void GiveBearRug(BasePlayer player, uint bearID) { var bearRugDefinition = ItemManager.FindItemDefinition(BearRugShortName); if (bearRugDefinition == null) { Puts("Bear rug item definition not found!"); return; } var bearRug = ItemManager.Create(bearRugDefinition, 1); if (!player.inventory.GiveItem(bearRug)) { DropItem(bearRug, player.transform.position); player.ChatMessage("Your inventory is full. The bear rug has been dropped on the ground."); } else { player.ChatMessage("You received a bear rug!"); } // Remove bear ID from tracking after a short delay to allow future skinning timer.Once(10f, () => RemoveBearID(bearID)); } private void DropItem(Item item, Vector3 position) { var rugEntity = item.Drop(position, Vector3.zero); if (rugEntity == null) { Puts("Failed to drop the bear rug item. Trying again."); // Retry dropping the item item.Drop(position + Vector3.up, Vector3.zero); } } private void RemoveBearID(uint bearID) { storedData.SkinnedBearIDs.Remove(bearID); SaveData(); } private void LoadData() { try { storedData = bearDataFile.ReadObject(); } catch { storedData = new StoredData(); } } private void SaveData() { bearDataFile.WriteObject(storedData); } private void OnServerSave() { SaveData(); // Save data on server save } private void Unload() { SaveData(); // Save data on plugin unload } } }