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

FREE Tsunami : 1.0.9 1.0.9

Нет прав для скачивания
C#:
using Newtonsoft.Json;
using Oxide.Core.Plugins;
using Oxide.Core;
using System;
using Network;
using System.Globalization;

namespace Oxide.Plugins
{
    [Info("Tsunami", "https://topplugin.ru/ / https://discord.com/invite/5DPTsRmd3G", "1.0.9")]
    [Description("Интересный плагин на тему наводнения")]
    class Tsunami : RustPlugin
    {
        [PluginReference] Plugin IQChat, XDNotifications;

        private float _currentLevel = 0f;
        private float _WaterLevelMax = 0f;
        private float _SpeedLevel = 0f;
        private Timer StartIvent = null;
        private bool oceanUp = false;

        #region Var
        static DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0);
        static double CurrentTime() => DateTime.UtcNow.Subtract(epoch).TotalSeconds;
        public int InitStart;
        private void AddNotify(BasePlayer player, string title, string description, string command = "", string cmdyes = "", string cmdno = "")
        {
            var Setting = config.xDNotification;
            Interface.Oxide.CallHook("AddNotify", player, title, description, Setting.Color, Setting.AlertDelete, Setting.SoundEffect, command, cmdyes, cmdno);
        }
        #endregion

        #region Configuration
        private static Configuration config = new Configuration();
        private class Configuration
        {
            internal class GlobalSetings
            {
                [JsonProperty("Минимальное время до запуска ивента")]
                public int MinTimeStart;
                [JsonProperty("Максимальное время до запуска ивента")]
                public int MaxTimeStart;
                [JsonProperty("Минимальный уровень воды")]
                public int MinLevel;
                [JsonProperty("Максимальный уровень воды")]
                public int MaxLevel;
                [JsonProperty("Минимальная скорость повышения уровня воды")]
                public float MinSpeed;
                [JsonProperty("Максимальная скорость повышения уровня воды")]
                public float maxSpeed;
                [JsonProperty("Плавность подъема Воды")]
                public float LevelWaterQuality;
                [JsonProperty("Включить ли ухудшения погоды во время Подъема воды")]
                public bool WeatherBad;
                [JsonProperty("Префикс в чате (IQChat)")]
                public string IQCHATPredix;
            }
            internal class XDNotification
            {
                [JsonProperty("Включить поддержку XDNotifications(UI уведомления будут заменены на уведомление с XDNotifications)")]
                public bool UseXDNotifications;
                [JsonProperty("Цвет заднего фона уведомления(HEX)")]
                public string Color;
                [JsonProperty("Через сколько удалиться уведомление")]
                public int AlertDelete;
                [JsonProperty("Звуковой эффект")]
                public string SoundEffect;
            }
            [JsonProperty(PropertyName = "Настройка XDNotifications(Если есть)")]
            public XDNotification xDNotification = new XDNotification();
            [JsonProperty("Основные настройки цунами")]
            public GlobalSetings setings;

            public static Configuration GetNewConfiguration()
            {
                return new Configuration
                {
                    setings = new GlobalSetings
                    {
                       MinTimeStart = 3600,
                       MaxTimeStart = 10800,
                       MinLevel = 5,
                       MaxLevel = 20,
                       MinSpeed = 1,
                       maxSpeed = 3,
                       LevelWaterQuality = 0.010f,
                       WeatherBad = true,
                       IQCHATPredix = "<color=#32a2a8>НАВОДНЕ́НИЕ</color>"
                    },
                    xDNotification = new XDNotification
                    {
                        UseXDNotifications = false, 
                        Color = "#0D698BFF",
                        AlertDelete = 5,
                        SoundEffect = ""
                    }
                };
            }
        }

        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                config = Config.ReadObject<Configuration>();
                if (config == null) LoadDefaultConfig();
            }
            catch
            {
                PrintWarning("Ошибка #1497" + $"чтения конфигурации 'oxide/config/{Name}', создаём новую конфигурацию!!");
                LoadDefaultConfig();
            }
            if (config.xDNotification.AlertDelete == 0) config.xDNotification.AlertDelete = 5;
            if (config.xDNotification.SoundEffect == null) config.xDNotification.SoundEffect = "";
            if (config.xDNotification.Color == null) config.xDNotification.Color = "#0D698BFF";
            NextTick(SaveConfig);
        }

        protected override void LoadDefaultConfig() => config = Configuration.GetNewConfiguration();
        protected override void SaveConfig() => Config.WriteObject(config);

        #endregion

        void OnServerInitialized()
        {
            UpdateOceanLevel();
            GenerateIvent();
        }

        private void OnPlayerConnected(BasePlayer player)
        {
            UpdateOceanLevel();
        }

        int API_GetTimeStartIvent()
        {
            int RealTimeSecond = (int)CurrentTime();
            int LastTime = time - (RealTimeSecond - InitStart);
            return LastTime;
        }

        [ChatCommand("testoceanlevel")]
        void test(BasePlayer player)
        {
            if (!player.IsAdmin) return;
            GenerateIvent(true);
        }
        int time;
        public void GenerateIvent(bool admin = false)
        {
            time = UnityEngine.Random.Range(config.setings.MinTimeStart, config.setings.MaxTimeStart);
            if (!admin)
            {
                InitStart = (int)CurrentTime();
                UpdateOceanLevel();
                _currentLevel = 0f;
                _SpeedLevel = 0;
                _WaterLevelMax = 0;
                _WaterLevelMax = UnityEngine.Random.Range(config.setings.MinLevel, config.setings.MaxLevel);
                _SpeedLevel = UnityEngine.Random.Range(config.setings.MinSpeed, config.setings.maxSpeed);
            }
            else
                time = 0;
            timer.Once(time, () =>
            {
                SendChat($"Ожидается повышения уровня воды в море на {_WaterLevelMax} метров!!!\n\nИгрокам которые живут на побережье нужно запастись баллонами");
                oceanUp = true;
                IventOceanStart();           
            });
        }
        void CreateCustomWeather() 
        {
            ConsoleSystem.Run(ConsoleSystem.Option.Server.Quiet(), $"weather.fog {_currentLevel / _WaterLevelMax}"); 
            ConsoleSystem.Run(ConsoleSystem.Option.Server.Quiet(), $"weather.rain {_currentLevel / _WaterLevelMax}");
            ConsoleSystem.Run(ConsoleSystem.Option.Server.Quiet(), $"weather.wind {_currentLevel / _WaterLevelMax}");
            ConsoleSystem.Run(ConsoleSystem.Option.Server.Quiet(), $"weather.thunder {_currentLevel / _WaterLevelMax}");
        }

        private void IventOceanStart()
        {
            if( oceanUp == false && _currentLevel <= 0)
            {
                StartIvent.Destroy();
                
                _currentLevel = 0f;
                _SpeedLevel = 0;
                _WaterLevelMax = 0;        
                GenerateIvent();
                return;
            }

            if (_currentLevel >= _WaterLevelMax)
            {
                oceanUp = false;
                SendChat($"Уровень воды идет на спад");
            }
            if (oceanUp) { _currentLevel += config.setings.LevelWaterQuality; }
            else { _currentLevel -= config.setings.LevelWaterQuality; }
            if (config.setings.WeatherBad)
                CreateCustomWeather();   
            UpdateOceanLevel();
            StartIvent = timer.Once(_SpeedLevel, IventOceanStart);
        }

        public void SendChat(string Message, ConVar.Chat.ChatChannel channel = ConVar.Chat.ChatChannel.Global)
        {
            if(XDNotifications && config.xDNotification.UseXDNotifications)
            {
                foreach(BasePlayer player in BasePlayer.activePlayerList)
                    AddNotify(player, "ЦУНАМИ", Message.Replace("\n", " "));
                return;
            }
            if (IQChat)
                IQChat?.Call("API_ALERT", Message, channel,  $"{config.setings.IQCHATPredix}\n");
            else
            {
                for (int i = 0; i < BasePlayer.activePlayerList.Count; i++) {
                    BasePlayer.activePlayerList[i].SendConsoleCommand("chat.add", channel, 0, Message); 
                } 
            }
        }
        private const string CommandOceanLevel = "env.oceanlevel";

        private void UpdateOceanLevel()
        {
            WaterSystem.OceanLevel = _currentLevel;
            SendReplicatedCommand(CommandOceanLevel, _currentLevel.ToString(CultureInfo.InvariantCulture));
        }
        private void SendReplicatedCommand(string name, string value)
        {
            if (!Net.sv.write.Start())
                return;

            Net.sv.write.PacketID(Message.Type.ConsoleReplicatedVars);
            Net.sv.write.Int32(1);
            Net.sv.write.String(name);
            Net.sv.write.String(value);
            Net.sv.write.Send(new SendInfo(Net.sv.connections));
        }
    }
}

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

Другие ресурсы пользователя 15FPS

Сверху