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

FREE ReplaceOnBroken : 2.1.0 2.1.0

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
/*
TODO:
- Add weapons option to replace on ammo empty
- Re-activate slot where item was replaced
- Refill candle hat fuel when empty
*/

using System.Collections.Generic;

namespace Oxide.Plugins
{
    [Info("ReplaceOnBroken", "Wulf/lukespragg", "2.1.0", ResourceId = 1173)]
    [Description("Replaces the active broken item with a not broken item if in inventory")]

    class ReplaceOnBroken : RustPlugin
    {
        // Do NOT edit this file, instead edit ReplaceOnBroken.json in oxide/config

        #region Initialization

        const string permAllow = "replaceonbroken.allow";
        bool usePermissions;
        List<object> exclusions;

        protected override void LoadDefaultConfig()
        {
            Config["ItemExclusions"] = exclusions = GetConfig("ItemExclusions", new List<object> { "item.shortname", "otheritem.name" });
            Config["UsePermissions"] = usePermissions = GetConfig("UsePermissions", true);
            SaveConfig();
        }

        void Init()
        {
            LoadDefaultConfig();
            permission.RegisterPermission(permAllow, this);
        }

        #endregion

        #region Item Replacement

        void OnLoseCondition(Item oldItem, ref float amount)
        {
            if (!oldItem.parent.HasFlag(ItemContainer.Flag.IsPlayer)) return;
            if (!(oldItem.condition <= amount)) return;
            if (exclusions.Contains(oldItem.info.shortname)) return;

            var player = oldItem.parent?.playerOwner;
            if (player == null) return;

            if (usePermissions && !permission.UserHasPermission(player.UserIDString, permAllow)) return;

            var main = player.inventory.containerMain;
            foreach (var newItem in main.itemList)
            {
                if (oldItem.info.itemid != newItem.info.itemid || !(newItem.condition > 0f)) continue;

                var newItemPosition = newItem.position;
                timer.Once(0.1f, () => oldItem.MoveToContainer(main, newItemPosition));
                break;
            }
        }

        #endregion

        #region Helpers

        T GetConfig<T>(string name, T value) => Config[name] == null ? value : (T)System.Convert.ChangeType(Config[name], typeof(T));

        #endregion
    }
}

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