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

FREE Tsunami : 1.0.2 1.0.2

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

namespace Oxide.Plugins
{
    [Info("Tsunami", "walkinrey", "1.0.2")]
    class Tsunami : RustPlugin
    {
        #region Референсы
        private PluginConfig config;
        private Timer smallerTimer;
        private Timer increaseTimer;
        private Timer onInit;
        private Timer onNewInit;
        #endregion
        #region Методы
        [ChatCommand("tsunamistop")]
        private void fastStop(BasePlayer player)
        {
            if(player.IPlayer.HasPermission("tsunami.admin")) 
            {
               covalence.Server.Command("env.oceanlevel 0");
               StopRain();
               if(smallerTimer != null) smallerTimer.Destroy();
               if(increaseTimer != null) increaseTimer.Destroy();
               SendReply(player, "Ивент остановлен.");
            }
            else
            {
                SendReply(player, "У вас нет разрешения на использование данной команды.");
            }
        }
        [ChatCommand("tsunamistart")]
        private void fastStart(BasePlayer player)
        {
            if(player.IPlayer.HasPermission("tsunami.admin"))
            {
                if(config.SendMessageOnEvent == true)
                {
                   PrintToChat(config.ChatMessage);
                }
                MakeRain();
                TimerIncreaseWater();
                onInit.Destroy();
                SendReply(player, "Если у вас включен авто-ивент, то ивент наступит на несколько минут позже.");
                OnInitTimer();
            }
            else
            {
                SendReply(player, "У вас нет разрешения на использование данной команды.");
            }
        }
        protected override void LoadDefaultConfig()
        {
            Config.WriteObject(GetDefaultConfig(), true);
        }
        private void MakeRain()
        {
            if(config.StartRainOnEvent == true)
            {
                covalence.Server.Command("weather.rain 1");
                covalence.Server.Command("weather.wind 1");
            }
            else
            {
                covalence.Server.Command("weather.rain 0");
                covalence.Server.Command("weather.wind 0");
            }
        }
        private void OnInitTimer()
        {
            if(config.ActiveAutoEvent)
            {
            onNewInit = timer.Every(config.StartEvery, () =>
            {
                if(config.SendMessageOnEvent == true)
                {
                   PrintToChat(config.ChatMessage);
                }
                MakeRain();
                TimerIncreaseWater();
            });
            }
        }
        private void StopRain()
        {
            ConsoleSystem.Run(ConsoleSystem.Option.Server.Quiet(), "weather.rain 0");
        }
        private void TimerIncreaseWater()
        {
            increaseTimer = null;
            float increased = 0f;
            int called = 0;
            increaseTimer = timer.Every(1f, () =>
            {
                increased += config.WaterSmothness;
                if(increased > config.WaterMaxLevel)
                {
                    SmallerWater(increased);
                    increaseTimer.Destroy();
                }
                ConsoleSystem.Run(ConsoleSystem.Option.Server.Quiet(), "env.oceanlevel " + increased);
            });
        }
        private void SmallerWater(float increased)
        {
            smallerTimer = null;
            if(config.SendMessageOnEvent == true)
            {
               PrintToChat(config.MessageWaterDown);
            }
            int calls = 0;
            float smaller;
            smaller = increased;
            smallerTimer = timer.Every(1f, () =>
            {
                calls += 1;
                if(calls > 149)
                {
                    StopRain();
                }
                if(smaller < 0)
                {
                    StopRain();
                    smallerTimer.Destroy();
                    if(config.SendMessageOnEvent == true) PrintToChat(config.EndMessage);
                }
                smaller -= config.WaterSmothness;
                ConsoleSystem.Run(ConsoleSystem.Option.Server.Quiet(), "env.oceanlevel " + smaller);
            });
        }
        #endregion
        #region Конфиг
        private class PluginConfig
        {
            [JsonProperty("Запускать ивент каждые (3600 секунд по умолчанию)")]
            public float StartEvery;
            [JsonProperty("Активировать плохую погоду при начале ивента")]
            public bool StartRainOnEvent;
            [JsonProperty("Плавность подъема воды")]
            public float WaterSmothness;
            [JsonProperty("Отправлять всем игрокам сообщение при начале ивента")]
            public bool SendMessageOnEvent;
            [JsonProperty("Сообщение которое будет отправляться в чат всем игрокам при начале ивента")]
            public string ChatMessage;
            [JsonProperty("Максимальный уровень воды")]
            public float WaterMaxLevel;
            [JsonProperty("Сообщение при уходе воды")]
            public string MessageWaterDown;
            [JsonProperty("Сообщение при окончании ивента")]
            public string EndMessage;
            [JsonProperty("Запускать автоматически ивент?")]
            public bool ActiveAutoEvent;
        }
        private PluginConfig GetDefaultConfig()
        {
            return new PluginConfig
            {
                StartEvery = 3600f,
                StartRainOnEvent = true,
                WaterSmothness = 0.05f,
                SendMessageOnEvent = true,
                WaterMaxLevel = 5f,
                ChatMessage = "<color=blue>Ученые</color>: Обнаружено повышение уровня воды! Игрокам живущим у побережья или моря рекомендуем приготовиться.",
                MessageWaterDown = "<color=blue>Ученые</color>: Вода начала убывать.",
                EndMessage = "<color=blue>Ученые</color>: Наводнение прекратилось.Вода вернулась на прежний уровень.",
                ActiveAutoEvent = true
            };
        }
        #endregion
        #region Хуки
        private void Init()
        {
            permission.RegisterPermission("tsunami.admin", this);
            config = Config.ReadObject<PluginConfig>();
            if(config.ActiveAutoEvent == true)
            {
              onInit = timer.Every(config.StartEvery, () =>
              {
                if(config.SendMessageOnEvent == true)
                {
                   PrintToChat(config.ChatMessage);
                }
                MakeRain();
                TimerIncreaseWater();
              });
            }
        }
        #endregion
    }
}

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

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

Сверху