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

FREE CustomRocketLauncher : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using System.Collections.Generic;
using Newtonsoft.Json;
using System;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("CustomRocketLauncher", "Anarchist", "1.0.0")]
    [Description("Добавляет на сервер кастомную ракетницу с гибкой настройкой характеристик.")]
    public class CustomRocketLauncher : RustPlugin
    {

        
        public class Configuration
        {
            [JsonProperty(RU ? "Кастомные ракетницы" : "Custom Rocket Launchers")]
            public List<Items> description;

            public class Items
            {
		   		 		  						   					  						  		  		  			 		  	  	
                public Item ToItem()
                {
                    Item item = ItemManager.CreateByName(ItemsShortName, 1, skinIDItem);
                    if (item == null) return null;
                    if (!string.IsNullOrEmpty(nameItem)) item.name = nameItem;
                    if (gunshots != 0)
                    {
                        item.condition = Condition * gunshots;
                        item._maxCondition = Condition * gunshots;
                    }
                    return item;
                }
                [JsonProperty(RU ? "Названия предмета" : "Item Name")]
                public string nameItem;

                [JsonProperty(RU ? "SkinID предмета" : "Item SkinID")]
                public ulong skinIDItem;

                [JsonProperty(RU ? "Во сколько раз увеличен урон" : "Damage Multiplier")]
                public float damage;

                [JsonProperty(RU ? "Какие ракеты можно заряжать (ammo.rocket.basic, ammo.rocket.fire, ammo.rocket.hv)" : "Allowed Missiles (ammo.rocket.basic, ammo.rocket.fire, ammo.rocket.hv)")]
                public List<string> missiles;

                [JsonProperty(RU ? "На сколько выстрелов" : "Number of Shots")]
                public int gunshots;
            }

            public static Configuration GetNewConfiguration()
            {
                return new Configuration
                {
                    description = new List<Items>
                    {
                        new Items
                        {
                            nameItem = "KABOOM",
                            skinIDItem = 3634633486,
                            gunshots = 10,
                            damage = 8f,
                            missiles = new List<string> { "ammo.rocket.basic" }
                        }
                    }
                };
            }
        }
		   		 		  						   					  						  		  		  			 		  	  	
        protected override void LoadDefaultConfig() => config = Configuration.GetNewConfiguration();

        private object OnMagazineReload(BaseLauncher weapon, IAmmoContainer desiredAmount, BasePlayer player)
        {
            if (itemsCon.TryGetValue(weapon.skinID, out var item))
            {
                if (!item.missiles.Contains(weapon.primaryMagazine.ammoType.shortname)) return false;
            }
            return null;
        }

        
        
        private void Init()
        {
            _ = this;
            itemsCon = new();
            foreach (var item in config.description)
            {
                itemsCon.Add(item.skinIDItem, item);
            }
        }
        private const float Condition = 1.3f;
        protected override void SaveConfig() => Config.WriteObject(config);

        private void OnRocketLaunched(BasePlayer player, BaseEntity entity)
        {
            Item activeItem = player.GetActiveItem();
            TimedExplosive timedExplosive = entity as TimedExplosive;
            if (activeItem == null || timedExplosive == null) return;
            if (itemsCon.TryGetValue(activeItem.skin, out var item))
            {
                player.Invoke(() => activeItem._maxCondition = activeItem.condition, 0.25f);
                timedExplosive.SetDamageScale(item.damage);
            }
        }
        private Dictionary<ulong, Configuration.Items> itemsCon;
        
        
        
        [ConsoleCommand("give.launcher")]
        private void CustomRocketLauncherCommandConsole(ConsoleSystem.Arg arg)
        {
            if (arg == null || !arg.IsAdmin || arg.Args == null || arg.Args.Length < 1) return;
            if (arg.Args.Length < 2)
            {
                var player = arg.Player();
                if (player == null) return;
                if (itemsCon.TryGetValue(Convert.ToUInt64(arg.Args[0]), out var item))
                {
                    player.GiveItem(item.ToItem());
                }
            }
            else
            {
                BasePlayer player = BasePlayer.Find(arg.Args[1]);
                if (player == null) return;
                if (itemsCon.TryGetValue(Convert.ToUInt64(arg.Args[0]), out var item))
                {
                    player.GiveItem(item.ToItem());
                }
            }
        }
        private const String ItemsShortName = "rocket.launcher";
        
        private void OnServerInitialized()
        {
            PrintWarning(
                "\n\u001b[33m===================================\u001b[0m\n" +
                " \u001b[31mPlugin :\u001b[0m \u001b[36m" + Name + "\u001b[0m\n" +
                "\u001b[33m===================================\u001b[0m\n" +
                " \u001b[31mAuthor :\u001b[0m \u001b[36mAnarchist\u001b[0m\n" +
                " \u001b[31mTelegram :\u001b[0m \u001b[36mhttps://t.me/anarchist_dev_rust\u001b[0m\n" +
                " \u001b[31mDiscord :\u001b[0m \u001b[36mhttps://discord.gg/BAnqhsUeE3\u001b[0m\n" +
                "\u001b[33m===================================\u001b[0m"
            );
        }
        private static Configuration config;
        private const bool RU = true;
        
        private void Unload()
        {
            if (_ == null) return;
            itemsCon = null;
            _ = null;
        }

        private object OnAmmoSwitch(BaseLauncher weapon, BasePlayer player, ItemDefinition itemDefinition)
        {
            if (itemsCon.TryGetValue(weapon.skinID, out var item))
            {
                if (!item.missiles.Contains(itemDefinition.shortname)) return false;
            }
            return null;
        }

        public static CustomRocketLauncher _;

        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                config = Config.ReadObject<Configuration>();
                if (config == null) LoadDefaultConfig();
            }
            catch
            {
                PrintWarning(RU
                    ? $"Ошибка чтения #666 конфигурации 'oxide/config/{Name}', создаём новую конфигурацию!!"
                    : $"Error reading #666 of configuration 'oxide/config/{Name}', create a new configuration!!");
                LoadDefaultConfig();
            }

            NextTick(SaveConfig);
        }

            }
}

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