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

FREE OreEvent : 2.0.0 2.0.0

Нет прав для скачивания
C#:
// ╔═══════════════════════════════════════════════════════════════════════════╗
// ║
// ║   Plugin : OreEvent
// ║   Author : WuyZar
// ║   Discord : https://discord.gg/NVwRcQwGwh
// ║   Shop : https://codefling.com/wuyzar
// ║
// ║   All rights reserved. Redistribution and modification are forbidden !
// ║
// ╚═══════════════════════════════════════════════════════════════════════════╝
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using System.Collections.Generic;
namespace Oxide.Plugins {
    [Info("OreEvent", "WuyZar", "2.0.0")]
    [Description("Discord: https://discord.gg/NVwRcQwGwh")]
    public class OreEvent : RustPlugin {
        private PluginConfig config;
        private Timer eventTimer;
        private Timer updateTimer;
        private bool eventRunning;
        private int currentTime;
        private int multiplier;
        private string displayName;
        private HashSet<string> activeShortnames = new HashSet<string>();
        private class OreDefinition {
            public string DisplayName;
            public string[] Shortnames;
        }
        private static readonly Dictionary<string, OreDefinition> OreItems = new Dictionary<string, OreDefinition> {
            {
                "stone", new OreDefinition {
                    DisplayName = "Stone", Shortnames = new[] {
                        "stones"
                    }
                }
            }
            , {
                "metal", new OreDefinition {
                    DisplayName = "Metal", Shortnames = new[] {
                        "metal.ore"
                    }
                }
            }
            , {
                "sulfur", new OreDefinition {
                    DisplayName = "Sulfur", Shortnames = new[] {
                        "sulfur.ore"
                    }
                }
            }
            , {
                "hq", new OreDefinition {
                    DisplayName = "HQM", Shortnames = new[] {
                        "hq.metal.ore"
                    }
                }
            }
            , {
                "all", new OreDefinition {
                    DisplayName = "All Ores", Shortnames = new[] {
                        "stones", "metal.ore", "sulfur.ore", "hq.metal.ore"
                    }
                }
            }
        }
        ;
        private const string UiPanelColor = "0.102 0.110 0.133 1";
        private const string UiWhite = "1 1 1 1";
        private const string UiGray = "0.353 0.369 0.416 1";
        private class PluginConfig {
            public bool EnableAnnouncements {
                get;
                set;
            }
            = false;
            public string TimerRectColor {
                get;
                set;
            }
            = "0.910 0.784 0.416";
        }
        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 void Init() {
            eventRunning = false;
            activeShortnames = new HashSet<string>();
        }
        private void Unload() {
            eventTimer?.Destroy();
            updateTimer?.Destroy();
            DestroyUiForAllPlayers();
        }
        private void OnPlayerConnected(BasePlayer player) {
            if (eventRunning && player != null) {
                timer.Once(1f, () => {
                    if (player != null && player.IsConnected) ShowUIForPlayer(player);
                }
                );
            }
        }
        private void OnDispenserGather(ResourceDispenser dispenser, BasePlayer player, Item item) {
            if (!eventRunning || item == null || item.info == null) return;
            if (activeShortnames.Contains(item.info.shortname)) item.amount *= multiplier;
        }
        private void OnDispenserBonus(ResourceDispenser dispenser, BasePlayer player, Item item) {
            if (!eventRunning || item == null || item.info == null) return;
            if (activeShortnames.Contains(item.info.shortname)) item.amount *= multiplier;
        }
        private void OnCollectiblePickup(CollectibleEntity collectible, BasePlayer player) {
            if (!eventRunning || collectible == null || collectible.itemList == null) return;
            foreach (var amount in collectible.itemList) {
                if (amount?.itemDef == null) continue;
                if (activeShortnames.Contains(amount.itemDef.shortname)) amount.amount *= multiplier;
            }
        }
        [ConsoleCommand("oe.start")]
        private void CmdStart(ConsoleSystem.Arg arg) {
            if (arg.Player() != null && !arg.Player().IsAdmin) {
                arg.ReplyWith("<color=#E8736A>ORE EVENT</color> <color=#1A1C22>»</color> You do not have permission to use this command.");
                return;
            }
            if (arg.Args == null || arg.Args.Length < 3) {
                arg.ReplyWith("<color=#E8736A>ORE EVENT</color> <color=#1A1C22>»</color> Usage : oe.start <item> <duration> <multiplier>\nItems : stone, metal, sulfur, hq, all");
                return;
            }
            string key = arg.GetString(0).ToLower();
            int duration;
            int multi;
            if (!OreItems.ContainsKey(key)) {
                arg.ReplyWith("<color=#E8736A>ORE EVENT</color> <color=#1A1C22>»</color> Invalid item. Valid : stone, metal, sulfur, hq, all");
                return;
            }
            if (!int.TryParse(arg.GetString(1), out duration) || duration <= 0) {
                arg.ReplyWith("<color=#E8736A>ORE EVENT</color> <color=#1A1C22>»</color> The duration must be a positive number.");
                return;
            }
            if (!int.TryParse(arg.GetString(2), out multi) || multi < 1) {
                arg.ReplyWith("<color=#E8736A>ORE EVENT</color> <color=#1A1C22>»</color> The multiplier must be at least 1.");
                return;
            }
            StopEvent(false);
            StartEvent(key, duration, multi);
            arg.ReplyWith($"<color=#E8736A>ORE EVENT</color> <color=#1A1C22>»</color> Event started : x{multi} on {OreItems[key].DisplayName} for {duration}s.");
        }
        [ConsoleCommand("oe.stop")]
        private void CmdStop(ConsoleSystem.Arg arg) {
            if (arg.Player() != null && !arg.Player().IsAdmin) {
                arg.ReplyWith("<color=#E8736A>ORE EVENT</color> <color=#1A1C22>»</color> You do not have permission to use this command.");
                return;
            }
            if (!eventRunning) {
                arg.ReplyWith("<color=#E8736A>ORE EVENT</color> <color=#1A1C22>»</color> No event is currently running.");
                return;
            }
            StopEvent(true);
            if (config.EnableAnnouncements) rust.RunServerCommand("sm Ore Event has been stopped ! 10 yellow");
            else PrintToChat("<color=#E8736A>ORE EVENT</color> <color=#1A1C22>»</color> Ore Event has been stopped !");
            arg.ReplyWith("<color=#E8736A>ORE EVENT</color> <color=#1A1C22>»</color> Event stopped.");
        }
        private void StartEvent(string key, int duration, int multi) {
            displayName = OreItems[key].DisplayName;
            multiplier = multi;
            currentTime = duration;
            activeShortnames = new HashSet<string>(OreItems[key].Shortnames);
            eventRunning = true;
            if (config.EnableAnnouncements) rust.RunServerCommand($"sm Ore Event has started, x{multi} on {displayName} for {duration}s, enjoy ! 10 yellow");
            else PrintToChat($"<color=#E8736A>ORE EVENT</color> <color=#1A1C22>»</color> Ore Event has started, x{multi} on {displayName} for {duration}s, enjoy !");
            ShowUIForAllPlayers();
            updateTimer = timer.Repeat(1f, duration, () => {
                currentTime--;
                if (currentTime >= 0) UpdateTimerUI();
            }
            );
            eventTimer = timer.Once(duration, () => {
                StopEvent(true);
                if (config.EnableAnnouncements) rust.RunServerCommand("sm Ore Event is now over, see you soon ! 10 yellow");
                else PrintToChat("<color=#E8736A>ORE EVENT</color> <color=#1A1C22>»</color> Ore Event is now over, see you soon !");
            }
            );
        }
        private void StopEvent(bool destroyUi) {
            eventTimer?.Destroy();
            updateTimer?.Destroy();
            eventRunning = false;
            activeShortnames.Clear();
            if (destroyUi) DestroyUiForAllPlayers();
        }
        private void ShowUIForAllPlayers() {
            foreach (var player in BasePlayer.activePlayerList) ShowUIForPlayer(player);
        }
        private void ShowUIForPlayer(BasePlayer player) {
            if (player == null || !player.IsConnected) return;
            DestroyUiForPlayer(player);
            var elements = new CuiElementContainer();
            elements.Add(new CuiElement {
                Name = "OreEvent_Root", Parent = "Overlay", Components = {
                    new CuiImageComponent {
                        Color = UiPanelColor
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "1 1", AnchorMax = "1 1", OffsetMin = "-256 -106", OffsetMax = "-16 -16"
                    }
                }
            }
            );
            elements.Add(new CuiElement {
                Name = "OreEvent_Title", Parent = "OreEvent_Root", Components = {
                    new CuiTextComponent {
                        Text = "ORE EVENT", FontSize = 15, Align = TextAnchor.MiddleLeft, Color = UiWhite
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.5 1", AnchorMax = "0.5 1", OffsetMin = "-110 -30", OffsetMax = "30 -5"
                    }
                }
            }
            );
            elements.Add(new CuiElement {
                Name = "OreEvent_Divider", Parent = "OreEvent_Root", Components = {
                    new CuiImageComponent {
                        Color = UiWhite
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.5 1", AnchorMax = "0.5 1", OffsetMin = "-110 -37", OffsetMax = "110 -35"
                    }
                }
            }
            );
            elements.Add(new CuiElement {
                Name = "OreEvent_Subtitle", Parent = "OreEvent_Root", Components = {
                    new CuiTextComponent {
                        Text = "Mine to enjoy the bonus !", FontSize = 10, Align = TextAnchor.MiddleLeft, Color = UiGray
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.5 1", AnchorMax = "0.5 1", OffsetMin = "-110 -85", OffsetMax = "110 -70"
                    }
                }
            }
            );
            elements.Add(new CuiElement {
                Name = "OreEvent_Label", Parent = "OreEvent_Root", Components = {
                    new CuiTextComponent {
                        Text = $"{displayName} {multiplier}x :", FontSize = 12, Align = TextAnchor.MiddleLeft, Color = UiWhite
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.5 1", AnchorMax = "0.5 1", OffsetMin = "-110 -65", OffsetMax = "0 -45"
                    }
                }
            }
            );
            elements.Add(new CuiElement {
                Name = "OreEvent_TimerBg", Parent = "OreEvent_Root", Components = {
                    new CuiImageComponent {
                        Color = $"{config.TimerRectColor} 0.5"
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.5 1", AnchorMax = "0.5 1", OffsetMin = "0 -65", OffsetMax = "110 -45"
                    }
                }
            }
            );
            int mins = currentTime / 60;
            int secs = currentTime % 60;
            string timeText = $"{mins:D2}:{secs:D2}";
            elements.Add(new CuiElement {
                Name = "OreEvent_Timer", Parent = "OreEvent_TimerBg", Components = {
                    new CuiTextComponent {
                        Text = timeText, FontSize = 12, Align = TextAnchor.MiddleCenter, Color = $"{config.TimerRectColor} 1"
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0 0", AnchorMax = "1 1"
                    }
                }
            }
            );
            CuiHelper.AddUi(player, elements);
        }
        private void UpdateTimerUI() {
            foreach (var player in BasePlayer.activePlayerList) {
                if (player == null || !player.IsConnected) continue;
                CuiHelper.DestroyUi(player, "OreEvent_Timer");
                int mins = currentTime / 60;
                int secs = currentTime % 60;
                string timeText = $"{mins:D2}:{secs:D2}";
                var element = new CuiElementContainer();
                element.Add(new CuiElement {
                    Name = "OreEvent_Timer", Parent = "OreEvent_TimerBg", Components = {
                        new CuiTextComponent {
                            Text = timeText, FontSize = 12, Align = TextAnchor.MiddleCenter, Color = $"{config.TimerRectColor} 1"
                        }
                        , new CuiRectTransformComponent {
                            AnchorMin = "0 0", AnchorMax = "1 1"
                        }
                    }
                }
                );
                CuiHelper.AddUi(player, element);
            }
        }
        private void DestroyUiForPlayer(BasePlayer player) {
            CuiHelper.DestroyUi(player, "OreEvent_Root");
        }
        private void DestroyUiForAllPlayers() {
            foreach (var player in BasePlayer.activePlayerList) DestroyUiForPlayer(player);
        }
    }
}

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