Иконка ресурса

FREE AutoCooking : 1.0.0 1.0.0

Нет прав для скачивания
C#:
// ╔═══════════════════════════════════════════════════════════════════════════╗
// ║                                                                           
// ║   Plugin : AutoCooking                                                     
// ║   Author : WuyZar                                                          
// ║   Discord : https://discord.gg/NVwRcQwGwh                                  
// ║   Shop : https://codefling.com/wuyzar                                      
// ║                                                                           
// ║   All rights reserved. Redistribution and modification are forbidden !    
// ║                                                                           
// ╚═══════════════════════════════════════════════════════════════════════════╝

using Oxide.Core.Plugins; using System.Collections.Generic;

namespace Oxide.Plugins
{
    [Info("AutoCooking", "WuyZar", "1.0.0")]
    [Description("Discord: https://discord.gg/NVwRcQwGwh")]
    public class AutoCooking : RustPlugin
    {
        private const string permUse = "autocooking.use";
        private Dictionary<ulong, float> charcoalBuffer = new();
        private PluginConfig config;

        private class PluginConfig
        {
            public bool EnableMeatCooking { get; set; } = true;
            public bool EnableOreCooking { get; set; } = true;
            public bool EnableFishCooking { get; set; } = true;
            public bool EnableHumanMeat { get; set; } = true;
            public bool EnableCharcoalBonus { get; set; } = true;
        }

        protected override void LoadDefaultConfig() { config = new PluginConfig(); SaveConfig(); }
        protected override void SaveConfig() => Config.WriteObject(config, true);
        protected override void LoadConfig() { base.LoadConfig(); config = Config.ReadObject<PluginConfig>() ?? new PluginConfig(); }

        private Dictionary<int, int> cookMap = new()
        {
            { -4031221, 69511070 }, { -1157596551, -1581843485 }, { -1982036270, 317398316 },
            { -1440987069, -1848736516 }, { 621915341, -242084766 }, { 1422530437, -1509851560 },
            { -1130350864, -1162759543 }, { -1520560807, 1873897110 }, { -395377963, 813023040 },
            { -2100458529, -170436364 }, { -1081599445, 392828520 }, { -2095813057, -1318837358 },
            { -2063848827, -1728286971 }, { 989925924, 1668129151 }, { -1709878924, 1536610005 }
        };

        private HashSet<int> rawOres = new() { -4031221, -1157596551, -1982036270 };
        private HashSet<int> humanMeat = new() { 989949201 };
        private const int charcoalId = -1938052175;

        private void Init() => permission.RegisterPermission(permUse, this);
        private void OnPlayerConnected(BasePlayer player) => timer.Once(2f, () => ConvertAll(player));

        private object OnItemAddedToContainer(ItemContainer container, Item item)
        {
            if (container?.playerOwner == null || item == null) return null;
            var player = container.playerOwner;
            if (!player.IsConnected || !permission.UserHasPermission(player.UserIDString, permUse)) return null;
            if (!cookMap.ContainsKey(item.info.itemid)) return null;
            timer.Once(0.1f, () => ConvertAll(player));
            return null;
        }

        private void ConvertAll(BasePlayer player)
        {
            if (player == null || !player.IsConnected) return;
            ConvertContainer(player.inventory.containerMain, player);
            ConvertContainer(player.inventory.containerBelt, player);
        }

        private void ConvertContainer(ItemContainer container, BasePlayer player)
        {
            if (container == null) return;
            float totalCharcoal = charcoalBuffer.TryGetValue(player.userID, out var buffer) ? buffer : 0f;

            var items = Facepunch.Pool.Get<List<Item>>();
            items.AddRange(container.itemList);

            foreach (var item in items)
            {
                int rawId = item.info.itemid;
                if (!cookMap.TryGetValue(rawId, out var cookedId)) continue;
                bool isOre = rawOres.Contains(rawId);
                bool isFish = rawId == -106433500;
                bool isHuman = humanMeat.Contains(rawId);
                if (isOre && !config.EnableOreCooking) continue;
                if (!isOre && !isFish && !isHuman && !config.EnableMeatCooking) continue;
                if (isFish && !config.EnableFishCooking) continue;
                if (isHuman && !config.EnableHumanMeat) continue;

                int count = item.amount;
                item.RemoveFromContainer();
                ItemManager.CreateByItemID(cookedId, count)?.MoveToContainer(container);
                if (config.EnableCharcoalBonus && isOre) totalCharcoal += count / 3f;
            }

            Facepunch.Pool.FreeUnmanaged(ref items);

            int charcoalToGive = (int)totalCharcoal;
            if (charcoalToGive > 0)
                ItemManager.CreateByItemID(charcoalId, charcoalToGive)?.MoveToContainer(container);

            charcoalBuffer[player.userID] = totalCharcoal - charcoalToGive;
        }
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху