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

FREE EventManager : 2.2.5 2.2.5

Нет прав для скачивания
C#:
using Newtonsoft.Json;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using UnityEngine;
using Facepunch;
using Oxide.Core;
namespace Oxide.Plugins {
    [Info("EventManager", "senyaa & M&B-Studios", "2.2.5")]
    class EventManager : RustPlugin {
#region Constants
        const string USE_PERMISSION = "eventmanager.use";
        const string SELECTED_CUI_NAME = "EventManager_EventSelected";
        const string EDITENTRY_CUI_NAME = "EventManager_EditEntry";
        const string SELECT_CUI_NAME = "EventManager_SelectUI";
        const string SELECT_CCMD = "EM_SELECT";
        const string SET_ENTRY_CCMD = "EM_SETENTRY";
        const string SAVE_ENTRY_CCMD = "EM_SAVEENTRY";
        const string EDIT_ENTRY_CCMD = "EM_EDITENTRY";
        const string SHOW_PAGE_CCMD = "EM_SHOWPAGE";
        const string DELETE_ENTRY_CCMD = "EM_DELETEENTRY";
        const string NEW_ENTRY_CCMD = "EM_NEWENTRY";
#endregion
#region Fields
        static EventManager Instance;
        EventController controller;
        readonly Dictionary<int, string> DayList = new Dictionary<int, string>() {
            [1]
            = "Monday", [2] = "Tuesday", [3] = "Wednesday", [4] = "Thursday", [5] = "Friday", [6] = "Saturday", [0] = "Sunday",
        }
        ;
        private Dictionary<ulong, NewCreatorData> _creatingCreators = new Dictionary<ulong, NewCreatorData>();
#endregion
        [ConsoleCommand("em_spawn")]
        private void cmdSpawn(ConsoleSystem.Arg arg) {
            if (arg.Player() != null) if (!arg.Player().IsAdmin) return;
            if (arg.Args.IsNullOrEmpty()) return;
            var prefabname = String.Join(" ", arg.Args);
            var baseEntity = GameManager.server.CreateEntity(prefabname);
            if (baseEntity) {
                if (baseEntity.TryGetComponent<CH47HelicopterAIController>(out var ch47)) {
                    ch47.TriggeredEventSpawn();
                }
                if (baseEntity.TryGetComponent<CargoShip>(out var cargo)) {
                    cargo.TriggeredEventSpawn();
                }
                baseEntity.Spawn();
            }
        }
#region Event List
        static readonly EventSettings RandomStartEv = new EventSettings() {
            displayName = "RANDOM START"
        }
        ;
        //
#region Data
        private void SaveData() {
            var eventlistb = EventList.ToDictionary(p => $"{p.Key.Name}|{p.Key.Color}|{Guid.NewGuid().ToString()}", p => p.Value);
            Interface.Oxide.DataFileSystem.WriteObject($"{Title}/events", eventlistb);
        }
        private void TryCreateNewDataFile() {
            if (EventList.IsNullOrEmpty()) {
                EventList = new Dictionary<AuthorName, List<EventSettings>>() {
                    [new AuthorName() {
                        Name = "Facepunch", Color = "1 1 1 1"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "Helicopter", Command = "em_spawn assets/prefabs/npc/patrol helicopter/patrolhelicopter.prefab",
                        }
                        , new EventSettings() {
                            displayName = "Cargoship", Command = "em_spawn assets/content/vehicles/boats/cargoship/cargoshiptest.prefab",
                        }
                        , new EventSettings() {
                            displayName = "Airdrop", Command = "em_spawn assets/prefabs/misc/supply drop/supply_drop.prefab",
                        }
                        , new EventSettings() {
                            displayName = "Chinook 47", Command = "em_spawn assets/prefabs/npc/ch47/ch47scientists.entity.prefab",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "KpucTaJl", Color = "0.733 0.122 0.004 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "Air Event", Command = "airstart",
                        }
                        , new EventSettings() {
                            displayName = "Water Event", Command = "waterstart ",
                        }
                        , new EventSettings() {
                            displayName = "Arctic Base Event", Command = "abstart",
                        }
                        , new EventSettings() {
                            displayName = "Satellite Dish Event", Command = "satdishstart",
                        }
                        , new EventSettings() {
                            displayName = "Junkyard Event", Command = "jstart",
                        }
                        , new EventSettings() {
                            displayName = "Power Plant Event", Command = "ppstart",
                        }
                        , new EventSettings() {
                            displayName = "Harbor Event", Command = "harborstart",
                        }
                        , new EventSettings() {
                            displayName = "Squid Game", Command = "rlglstart",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "KpucTaJl", Color = "0.733 0.122 0.004 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "GasStation Event", Command = "gsstart",
                        }
                        , new EventSettings() {
                            displayName = "Defendable-Bases Start", Command = "warstart",
                        }
                        , new EventSettings() {
                            displayName = "Defendable-Bases Stop", Command = "warstop",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "Adem", Color = "0.424 0.000 0.988 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "Sputnik", Command = "sputnikstart",
                        }
                        , new EventSettings() {
                            displayName = "Armored Train", Command = "atrainstart",
                        }
                        , new EventSettings() {
                            displayName = "Space", Command = "spacestart",
                        }
                        , new EventSettings() {
                            displayName = "Convoy", Command = "convoystart",
                        }
                        , new EventSettings() {
                            displayName = "Shipwreck", Command = "shipwreckstart ",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "Mercury", Color = "1.000 0.573 0.000 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "IQSphereEvent", Command = "iqsp start",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "Yac Vaguer", Color = "1.000 0.573 0.000 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "Water-Treatment-Showdown", Command = "wtestart",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "DezLife", Color = "0.659 1.000 0.000 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "Cobalt Laboratory", Command = "cl start",
                        }
                        , new EventSettings() {
                            displayName = "XDChinookEvent", Command = "chinook call",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "Cashr", Color = "0.000 0.224 0.863 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "Rocket Event", Command = "rocket ||",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "Nikedemos", Color = "1.000 0.000 0.600 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "CargoTrainEvent", Command = "trainevent_now",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "Ridamees", Color = "0.071 0.478 0.059 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "Stone Eventt", Command = "StoneStart",
                        }
                        , new EventSettings() {
                            displayName = "Metal Event", Command = "MetalStart",
                        }
                        , new EventSettings() {
                            displayName = "Sulfur Event", Command = "SulfurStart",
                        }
                        , new EventSettings() {
                            displayName = "RaidRush Event", Command = "raidrush.start",
                        }
                        , new EventSettings() {
                            displayName = "BarrelBash Event", Command = "StartBarrelBash",
                        }
                        , new EventSettings() {
                            displayName = "BoxBattle Event", Command = "StartBoxBattle",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "Fruster", Color = "0.455 0.106 0.059 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "CargoPlaneEvent", Command = "callcargoplane",
                        }
                        , new EventSettings() {
                            displayName = "AirfieldEvent", Command = "afestart",
                        }
                        , new EventSettings() {
                            displayName = "HelipadEvent", Command = "hpestart",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "Bazz3l", Color = "0.075 0.682 0.925 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "GuardedCrate Easy", Command = "gcrate start Easy",
                        }
                        , new EventSettings() {
                            displayName = "GuardedCrate Medium", Command = "gcrate start Medium",
                        }
                        , new EventSettings() {
                            displayName = "GuardedCrate Hard", Command = "gcrate start Hard",
                        }
                        , new EventSettings() {
                            displayName = "GuardedCrate Elite", Command = "gcrate start Elite",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "Nivex", Color = "0.949 0.651 0.996 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "Dangerous Treasures", Command = "dtevent",
                        }
                        , new EventSettings() {
                            displayName = "RaidableBases Easy", Command = "rbevent easy",
                        }
                        , new EventSettings() {
                            displayName = "RaidableBases Medium", Command = "rbevent easy",
                        }
                        , new EventSettings() {
                            displayName = "RaidableBases Hard", Command = "rbevent easy",
                        }
                        , new EventSettings() {
                            displayName = "RaidableBases Nightmare", Command = "rbevent easy",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "Dana", Color = "0.698 0.024 0.678 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "Heli Regular", Command = "heli.call Regular",
                        }
                        , new EventSettings() {
                            displayName = "Heli Millitary", Command = "heli.call Millitary",
                        }
                        , new EventSettings() {
                            displayName = "Heli Elite", Command = "heli.call Elite",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "Razor", Color = "0.243 0.204 0.690 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "Jet Event", Command = "jet event 2 2 10",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "ThePitereq", Color = "0.851 0.612 0.208 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "Meteor-Event-Kill", Command = "ms kill",
                        }
                        , new EventSettings() {
                            displayName = "Meteor-Event-Start-Amount-10", Command = "ms run 10",
                        }
                        , new EventSettings() {
                            displayName = "Meteor-Event-Start-Amount-20", Command = "ms run 20",
                        }
                        , new EventSettings() {
                            displayName = "Meteor-Event-Start-Amount-30", Command = "ms run 30",
                        }
                        , new EventSettings() {
                            displayName = "Meteor-Event-Start-Amount-40", Command = "ms run 40",
                        }
                        , new EventSettings() {
                            displayName = "Meteor-Event-Start-Amount-50", Command = "ms run 50",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = " k1lly0u", Color = "0.455 0.106 0.159 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "PilotEjec", Command = "pe call",
                        }
                        , new EventSettings() {
                            displayName = "HeliRefuel", Command = "hr call",
                        }
                        ,
                    }
                    , [new AuthorName() {
                        Name = "Wrecks", Color = "0.561 0.498 0.718 1.00"
                    }
                    ] = new List<EventSettings>() {
                        new EventSettings() {
                            displayName = "Bot-Purge-Event", Command = "Purge",
                        }
                        , new EventSettings() {
                            displayName = "Eradication Event", Command = "Erad",
                        }
                        ,
                    }
                }
                ;
                SaveData();
            }
        }
        void LoadData() {
            var EventListb = Interface.Oxide?.DataFileSystem?.ReadObject<Dictionary<string, List<EventSettings>>>($"{Title}/events") ?? new Dictionary<string, List<EventSettings>>();
            EventList = EventListb.ToDictionary(p => new AuthorName(p.Key.Split('|')[0], p.Key.Split('|')[1]), p => p.Value);
            TryCreateNewDataFile();
        }
#endregion
        static Dictionary<AuthorName, List<EventSettings>> EventList = new Dictionary<AuthorName, List<EventSettings>>();
        static EventSettings GetEventByName(string name) {
            if (name == "RANDOM START") return RandomStartEv;
            foreach (var events in EventList.Values) {
                foreach (var setting in events) {
                    if (setting.displayName == name) {
                        return setting;
                    }
                }
            }
            return null;
        }
#endregion
#region Configuration
        static Configuration config;
        class Configuration {
            [JsonProperty(PropertyName = "Time Entries", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public Dictionary<string, EventSettingsEntry> Entries = new Dictionary<string, EventSettingsEntry>();
        }
        protected override void LoadConfig() {
            base.LoadConfig();
            try {
                config = Config.ReadObject<Configuration>();
                if (config == null) {
                    throw new Exception();
                }
                SaveConfig();
            }
            catch {
                PrintError("Your configuration file contains an error.Using default configuration values.");
                LoadDefaultConfig();
            }
        }
        protected override void SaveConfig() {
            Config.WriteObject(config);
        }
        protected override void LoadDefaultConfig() {
            config = new Configuration();
        }
#endregion
#region Types
        internal class AuthorName {
            public AuthorName() {
            }
            public AuthorName(string name, string color) {
                this.Name = name;
                this.Color = color;
            }
            public string Name;
            public string Color;
        }
        internal class NewCreatorData {
            public string Name;
            public string Color;
        }
        internal class EventSettings {
            [JsonProperty(PropertyName = "Event name", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string displayName = "Air Event";
            [JsonProperty(PropertyName = "The command to launch the event", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string Command = "airevent start";
            [JsonProperty(PropertyName = "Color", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string Color = "0.1 0.1 0.1 0.95";
            [JsonProperty("Command type", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public string CommandType;
        }
        internal class EventSettingsEntry {
            public string GUID = "";
            public string Name = "";
            public bool StaticTime = true;
            public int Hour = 12;
            public int Minute = 30;
            public int MinPlayers = 0;
            public DateTime LastRun;
            public Dictionary<int, bool> DaysActive = new Dictionary<int, bool>() {
                [1]
                = false, [2] = false, [3] = false, [4] = false, [5] = false, [6] = false, [0] = false,
            }
            ;
            public List<string> RandomStartEvents = new List<string>();
            public string PrevStartedEv = "";
            public EventSettingsEntry(string guid, string name) {
                GUID = guid;
                Name = name;
            }
            public static string NewEntry(string name) {
                var guid = Guid.NewGuid().ToString();
                config.Entries.Add(guid, new EventSettingsEntry(guid, name));
                return guid;
            }
        }
        class EventController : FacepunchBehaviour {
            private void Awake() {
                InvokeRepeating(CheckEvents, 5, 5);
            }
            private List<string> ExecutedEvents = new();
            private void CheckEvents() {
                if (config?.Entries == null) {
                    Instance.PrintError("Configuration entries are not initialized.");
                    return;
                }
                var date = DateTime.Now;
                var day = Convert.ToInt32(date.DayOfWeek);
                var hour = date.Hour;
                var minute = date.Minute;
                foreach (var entry in config.Entries.Values) {
                    if (!entry.StaticTime) {
                        continue;
                    }
                    if (!entry.DaysActive[day]) {
                        continue;
                    }
                    if (entry.Hour == hour && entry.Minute == minute) {
                        if (entry.LastRun.Minute == minute && entry.LastRun.Hour == hour && entry.LastRun.DayOfWeek == date.DayOfWeek) continue;
                        entry.LastRun = date;
                        if (BasePlayer.activePlayerList.Count < entry.MinPlayers) continue;
                        if (entry.Name == "RANDOM START" && entry.RandomStartEvents.Count > 0) {
                            var validEvents = entry.RandomStartEvents.Where(e => !ExecutedEvents.Contains(e)).ToArray();
                            if (validEvents.IsNullOrEmpty()) {
                                if (ExecutedEvents.IsNullOrEmpty()) {
                                    Instance.PrintError("Not founded events to start!");
                                    return;
                                }
                                ExecutedEvents.Clear();
                                CheckEvents();
                                return;
                            }
                            int index = new System.Random().Next(validEvents.Length);
                            var evToRun = validEvents[index];
                            ExecutedEvents.Add(evToRun);
                            entry.PrevStartedEv = evToRun;
                            var eventSettings = GetEventByName(evToRun);
                            if (eventSettings == null) {
                                Instance.PrintError($"Event not found: {evToRun}");
                                continue;
                            }
                            Instance.rust.RunServerCommand(eventSettings.Command);
                            Instance.CallStartedHook(eventSettings.displayName);
                            continue;
                        }
                        var eventSettingsEntry = GetEventByName(entry.Name);
                        if (eventSettingsEntry == null) {
                            Instance.PrintError($"Event not found: {entry.Name}");
                            continue;
                        }
                        Instance.rust.RunServerCommand(eventSettingsEntry.Command);
                        Instance.CallStartedHook(eventSettingsEntry.displayName);
                    }
                }
                foreach (var entry in config.Entries.Values) {
                    if (entry.StaticTime) {
                        continue;
                    }
                    if (!entry.DaysActive[day]) {
                        continue;
                    }
                    if ((date - entry.LastRun).TotalMinutes > ((entry.Hour * 60) + entry.Minute)) {
                        if (entry.LastRun.Minute == minute && entry.LastRun.Hour == hour && entry.LastRun.DayOfWeek == date.DayOfWeek) continue;
                        entry.LastRun = date;
                        if (BasePlayer.activePlayerList.Count < entry.MinPlayers) continue;
                        if (entry.Name == "RANDOM START" && entry.RandomStartEvents.Count > 0) {
                            var validEvents = entry.RandomStartEvents.Where(e => !ExecutedEvents.Contains(e)).ToArray();
                            if (validEvents.IsNullOrEmpty()) {
                                if (ExecutedEvents.IsNullOrEmpty()) {
                                    Instance.PrintError("Not founded events to start!");
                                    return;
                                }
                                ExecutedEvents.Clear();
                                CheckEvents();
                                return;
                            }
                            int index = new System.Random().Next(validEvents.Length);
                            var evToRun = validEvents[index];
                            ExecutedEvents.Add(evToRun);
                            var eventSettings = GetEventByName(evToRun);
                            if (eventSettings == null) {
                                Instance.PrintError($"Event not found: {evToRun}");
                                continue;
                            }
                            Instance.rust.RunServerCommand(eventSettings.Command);
                            Instance.CallStartedHook(eventSettings.displayName);
                            continue;
                        }
                        var eventSettingsEntry = GetEventByName(entry.Name);
                        if (eventSettingsEntry == null) {
                            Instance.PrintError($"Event not found: {entry.Name}");
                            continue;
                        }
                        Instance.rust.RunServerCommand(eventSettingsEntry.Command);
                        Instance.CallStartedHook(eventSettingsEntry.displayName);
                    }
                }
            }
        }
#endregion
#region Oxide Hooks
        void Init() {
            Instance = this;
        }
        void OnServerInitialized() {
            LoadData();
            permission.RegisterPermission(USE_PERMISSION, this);
            timer.Once(3f, () => {
                bool replacedType = false;
                foreach (var x in EventList.ToArray()) foreach (var y in x.Value) if (string.IsNullOrEmpty(y.CommandType)) {
                    EventList[x.Key][EventList[x.Key].IndexOf(y)].CommandType = "console";
                    replacedType = true;
                }
                if (replacedType) SaveData();
                controller = ServerMgr.Instance.gameObject.AddComponent<EventController>();
            }
            );
        }
        private void OnServerSave() => SaveData();
        void Unload() {
            SaveData();
            SaveConfig();
            UnityEngine.Object.DestroyImmediate(controller);
            Instance = null;
        }
        private Vector3 GetRandomSpawnPosCh47() {
            return TerrainMeta.RandomPointOffshore();
        }
#endregion
#region UI
        internal class NewEventData {
            public string Name;
            public string Command;
            public string CommandType = "console";
            // default to console command
            public AuthorName Author;
            public EventSettings ToEntry() {
                var entry = new EventSettings {
                    displayName = Name, Command = Command, Color = "0.1 0.1 0.1 0.95", CommandType = CommandType
                }
                ;
                return entry;
            }
        }
        private Dictionary<ulong, NewEventData> _creatingEvents = new Dictionary<ulong, NewEventData>();
        private const string Layer = "ui.EventManager.bg";
        [ConsoleCommand("em_createconfirm")]
        private void cmdCreateConfirm(ConsoleSystem.Arg arg) {
            if (arg.Player() == null) return;
            if (!arg.Player().IPlayer.HasPermission(USE_PERMISSION)) return;
            if (!_creatingEvents.ContainsKey(arg.Player().userID)) return;
            var e = _creatingEvents[arg.Player().userID];
            EventList[e.Author].Add(e.ToEntry());
            if (e.CommandType == "chat") {
                // Simulate chat command execution
                SimulateChatCommand(arg.Player(), e.Command);
            }
            else {
                // Execute console command
                Server.Command(e.Command);
            }
            _creatingEvents.Remove(arg.Player().userID);
            SaveData();
            CuiHelper.DestroyUi(arg.Player(), Layer);
        }
        private void SimulateChatCommand(BasePlayer player, string command) {
            // Assuming command is like "mychatcommand args"
            var commandParts = command.Split(' ');
            var cmd = commandParts[0];
            var args = commandParts.Skip(1).ToArray();
            // Use the chat command handler to process the command
            var hookResult = Interface.CallHook("OnPlayerCommand", player, cmd, args);
            if (hookResult != null) {
                player.ChatMessage(hookResult.ToString());
            }
            else {
                // If no hook handles the command, send an error message
                player.ChatMessage($"Unknown command: {cmd}");
            }
        }
        [ConsoleCommand("em_cancelcreate")]
        private void cmdCancelCreate(ConsoleSystem.Arg arg) {
            if (arg.Player() == null) return;
            if (!arg.Player().IPlayer.HasPermission(USE_PERMISSION)) return;
            _creatingEvents.Remove(arg.Player().userID);
            CuiHelper.DestroyUi(arg.Player(), Layer);
        }
        [ConsoleCommand("em_setname")]
        private void cmdSetName(ConsoleSystem.Arg arg) {
            if (arg.Player() == null) return;
            if (!arg.Player().IPlayer.HasPermission(USE_PERMISSION)) return;
            if (!_creatingEvents.TryGetValue(arg.Player().userID, out var ev)) return;
            ev.Name = string.Join(" ", arg.Args);
        }
        [ConsoleCommand("em_setcommand")]
        private void cmdSetCommand(ConsoleSystem.Arg arg) {
            if (arg.Player() == null) return;
            if (!arg.Player().IPlayer.HasPermission(USE_PERMISSION)) return;
            if (!_creatingEvents.TryGetValue(arg.Player().userID, out var ev)) return;
            ev.Command = string.Join(" ", arg.Args);
        }
        [ConsoleCommand("em_setauthor")]
        private void cmdSetAuthor(ConsoleSystem.Arg arg) {
            if (arg.Player() == null) return;
            if (!arg.Player().IPlayer.HasPermission(USE_PERMISSION)) return;
            if (!_creatingEvents.TryGetValue(arg.Player().userID, out var ev)) return;
            ev.Author = EventList.Select(x => x.Key).FirstOrDefault(x => x.Name.Contains(arg.Args[0]))!;
            CuiHelper.DestroyUi(arg.Player(), Layer + ".eventcreator.div");
            UI_UpdateCreator(arg.Player());
        }
        [ConsoleCommand("em_drawcreators")]
        private void cmdDrawCreators(ConsoleSystem.Arg arg) {
            if (arg.Player() == null) return;
            UI_DrawCreators(arg.Player());
        }
        [ConsoleCommand("em_startevent")]
        private void StartEvent(ConsoleSystem.Arg arg) {
            Puts("1");
            if (!arg.IsAdmin)  // Stellen Sie sicher, dass der Befehl nur von Admins ausgeführt werden kann
            {
                arg.ReplyWith("You do not have permission to start events.");
                return;
            }
            Puts($"2 {arg.Args.Length}");
            var eventName = string.Join(" ", arg.Args);
            // Der Event-Name wird als erstes Argument übergeben
            var eventSettings = GetEventByName(eventName);
            Puts(eventName);
            if (eventSettings == null) {
                arg.ReplyWith("Event not found.");
                return;
            }
            Puts($"4 {eventSettings.Command}");
            // rust.RunServerCommand(eventSettings.Command);
            switch (eventSettings.CommandType) {
                case "console" : Server.Command(eventSettings.Command);
                break;
                case "chat" : if (arg.Player() == null) arg.ReplyWith("Only in-game executing!");
                arg.Player().SendConsoleCommand($"chat.say \"{eventSettings.Command}\"");
                break;
                default : return;
            }
            arg.ReplyWith($"Event '{eventName}' started.");
        }
        private void UI_UpdateCreator(BasePlayer player) {
            var container = new CuiElementContainer();
            if (!_creatingEvents.TryGetValue(player.userID, out var ev)) return;
            container.Add(new CuiButton {
                Button = {
                    Color = "0.8078431 0.7803922 0.7411765 0.6588235", Command = "em_drawcreators"
                }
                , Text = {
                    Text = ev.Author?.Name ?? "Choose event creator...", Font = "robotocondensed-bold.ttf", FontSize = 21, Align = TextAnchor.MiddleCenter, Color = ev.Author?.Color ?? "0.1 0.1 0.1 0.95" //
                }
                , RectTransform = {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-62.243 95.069", OffsetMax = "172.248 130.901"
                }
            }
            , Layer, Layer + ".eventcreator");
            CuiHelper.DestroyUi(player, Layer + ".eventcreator");
            CuiHelper.AddUi(player, container);
        }
        private void UI_DrawCreateNewCreator(BasePlayer player) {
            var container = new CuiElementContainer();
            // Creating the main panel and storing the returned panel name
            string mainPanel = container.Add(new CuiPanel {
                Image = {
                    Color = "0.8078431 0.7803922 0.7411765 0"
                }
                , RectTransform = {
                    AnchorMin = "0.428 0.35", AnchorMax = "0.623 0.697"
                }
                , CursorEnabled = true
            }
            , "Overlay", "Hud");
            container.Add(new CuiLabel {
                RectTransform = {
                    AnchorMin = "0.05 0.85", AnchorMax = "0.25 0.95"
                }
                , Text = {
                    Text = "New", FontSize = 18, Align = TextAnchor.MiddleLeft
                }
            }
            , mainPanel);
            string nameInput = container.Add(new CuiPanel {
                Image = {
                    Color = "0.8078431 0.7803922 0.7411765 0.6588235"
                }
                ,  // Dark gray color
                RectTransform = {
                    AnchorMin = "0.068 0.576", AnchorMax = "0.9 0.764"
                }
                , CursorEnabled = true
            }
            , mainPanel);
            container.Add(new CuiElement {
                Parent = nameInput, Components = {
                    new CuiInputFieldComponent {
                        Command = "cmdSetCreatorName", FontSize = 14, Align = TextAnchor.MiddleLeft, Text = "Creator Name", NeedsKeyboard = true
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0 0", AnchorMax = "1 1"
                    }
                }
            }
            );
            // Buttons for cancellation and confirmation
            AddButton(container, mainPanel, "0.068 0.332", "0.9 0.52", "cmdShowColorOptions", "choose a colour", 14, "0.2 0.2 0.2 1");
            AddButton(container, mainPanel, "0.06 0.052", "0.416 0.248", "cmdCancelCreation", "Cancel", 14, "0.8156863 0.5568628 0.4745098 1");
            AddButton(container, mainPanel, "0.544 0.06", "0.9 0.256", "cmdConfirmCreator", "Create", 14, "0.8078431 0.8431373 0.5490196 1");
            CuiHelper.AddUi(player, container);
        }
        private void AddButton(CuiElementContainer container, string parent, string anchorMin, string anchorMax, string command, string text, int fontSize, string color) {
            string buttonId = container.Add(new CuiButton {
                Button = {
                    Command = command, Color = color
                }
                , RectTransform = {
                    AnchorMin = anchorMin, AnchorMax = anchorMax
                }
                , Text = {
                    Text = text, FontSize = fontSize, Align = TextAnchor.MiddleCenter
                }
            }
            , parent);
        }
        [ConsoleCommand("em_page")]
        private void cmdPage(ConsoleSystem.Arg arg) {
            if (arg.Player() == null || arg.Args.IsNullOrEmpty()) return;
            if (!int.TryParse(arg.Args[0], out var page)) return;
            UI_DrawCreators(arg.Player(), page);
        }
        private void UI_DrawCreators(BasePlayer player, int page = 0) {
            CuiHelper.DestroyUi(player, Layer + ".eventcreator.div");
            var container = new CuiElementContainer();
            container.Add(new CuiPanel {
                CursorEnabled = false, Image = {
                    Color = "0.8078431 0.7803922 0.7411765 0"
                }
                , RectTransform = {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-62.242 58.184", OffsetMax = "172.248 94.016"
                }
            }
            , Layer, Layer + ".eventcreator.div");
            container.Add(new CuiButton {
                Button = {
                    Color = "0.6470588 0.6235294 0.6 1", Command = (page - 1) >= 0 ? $"em_page {page - 1}" : ""
                }
                , Text = {
                    Text = "<", Font = "robotocondensed-bold.ttf", FontSize = 25, Align = TextAnchor.MiddleCenter, Color = "0.8078431 0.8431373 0.5490196 1"
                }
                , RectTransform = {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "120.6 19.5", OffsetMax = "155.6 54.5"
                }
            }
            , Layer + ".eventcreator.div", Layer + ".eventmanager" + ".eventcreator.div" + ".btn.prev");
            container.Add(new CuiButton {
                Button = {
                    Color = "0.6470588 0.6235294 0.6 1", Command = EventList.Where(x => x.Value.Count < 8).Skip(8 * (page + 1)).Any() ? $"em_page {page + 1}" : ""
                }
                , Text = {
                    Text = ">", Font = "robotocondensed-bold.ttf", FontSize = 25, Align = TextAnchor.MiddleCenter, Color = "0.8078431 0.8431373 0.5490196 1"
                }
                , RectTransform = {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "158.7 19.5", OffsetMax = "193.7 54.5"
                }
            }
            , Layer + ".eventcreator.div", Layer + ".eventmanager" + ".eventcreator.div" + ".btn.next");
            float minx = -117.245f;
            float maxx = 117.245f;
            float miny = -17.91578f;
            float maxy = 5.91522f;
            int i = 0;
            foreach (var x in EventList.Where(x => x.Value.Count < 8).Skip(8 * page).Take(8).Select(x => x.Key)) {
                container.Add(new CuiButton {
                    Button = {
                        Color = "0.8078431 0.7803922 0.7411765 0.6588235", Command = $"em_setauthor {x.Name}"
                    }
                    , Text = {
                        Text = x.Name, Font = "robotocondensed-regular.ttf", FontSize = 14, Align = TextAnchor.MiddleCenter, Color = x.Color
                    }
                    , RectTransform = {
                        AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{minx} {miny}", OffsetMax = $"{maxx} {maxy}"
                    }
                }
                , Layer + ".eventcreator.div", $"creator.{i}");
                i++;
                miny -= 25.04f;
                maxy -= 25.04f;
            }
            CuiHelper.DestroyUi(player, Layer + ".eventcreator.div");
            CuiHelper.AddUi(player, container);
        }
        private void UI_DrawCreateNewEvent(BasePlayer player) {
            _creatingEvents.Remove(player.userID);
            _creatingEvents.Add(player.userID, new NewEventData());
            var container = new CuiElementContainer();
            container.Add(new CuiPanel {
                CursorEnabled = true, Image = {
                    Color = "0.317 0.317 0.317 0.7490196"
                }
                , RectTransform = {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-353.394 -207.674", OffsetMax = "353.394 207.674"
                }
            }
            , "Overlay", Layer);
            container.Add(new CuiElement {
                Name = Layer + ".label", Parent = Layer, Components = {
                    new CuiTextComponent {
                        Text = "NEW EVENT", Font = "robotocondensed-bold.ttf", FontSize = 23, Align = TextAnchor.MiddleLeft, Color = "0.6470588 0.6235294 0.6 1"
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-344 167.364", OffsetMax = "-188.991 200.636"
                    }
                }
            }
            );
            container.Add(new CuiPanel {
                CursorEnabled = false, Image = {
                    Color = "0.8078431 0.7803922 0.7411765 0.6588235"
                }
                , RectTransform = {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-344 95.069", OffsetMax = "-93.687 130.9"
                }
            }
            , Layer, Layer + ".name.bg");
            container.Add(new CuiElement {
                Name = Layer + ".name.bg" + ".name.input", Parent = Layer + ".name.bg", Components = {
                    new CuiInputFieldComponent {
                        Color = "1 1 1 1", Font = "robotocondensed-bold.ttf", FontSize = 18, Align = TextAnchor.MiddleCenter, CharsLimit = 0, IsPassword = false, Text = "Enter event name...", Command = "em_setname "
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-125.155 -17.916", OffsetMax = "125.155 17.916"
                    }
                }
            }
            );
            container.Add(new CuiPanel {
                CursorEnabled = false, Image = {
                    Color = "0.8078431 0.7803922 0.7411765 0.6588235"
                }
                , RectTransform = {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-344 44.584", OffsetMax = "-93.687 80.416"
                }
            }
            , Layer, Layer + ".command.bg");
            container.Add(new CuiElement {
                Name = Layer + ".command.bg" + ".input", Parent = Layer + ".command.bg", Components = {
                    new CuiInputFieldComponent {
                        Color = "1 1 1 1", Font = "robotocondensed-bold.ttf", FontSize = 18, Align = TextAnchor.MiddleCenter, CharsLimit = 0, IsPassword = false, Text = "Enter command...", Command = "em_setcommand "
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-125.155 -17.916", OffsetMax = "125.155 17.916"
                    }
                }
            }
            );
            container.Add(new CuiButton {
                Button = {
                    Color = "0.3882353 0.3960785 0.3098039 1", Command = "em_createconfirm"
                }
                , Text = {
                    Text = "CREATE", Font = "robotocondensed-bold.ttf", FontSize = 22, Align = TextAnchor.MiddleCenter, Color = "0.8078431 0.8431373 0.5490196 1"
                }
                , RectTransform = {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "237.359 -198.4", OffsetMax = "346.2 -165.34"
                }
            }
            , Layer, Layer + ".create.btn");
            container.Add(new CuiButton {
                Button = {
                    Color = "0.4078432 0.3372549 0.3019608 1", Command = "em_cancelcreate"
                }
                , Text = {
                    Text = "CANCEL", Font = "robotocondensed-bold.ttf", FontSize = 22, Align = TextAnchor.MiddleCenter, Color = "0.8156863 0.5568628 0.4745098 1"
                }
                , RectTransform = {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "121.179 -198.4", OffsetMax = "230.021 -165.34"
                }
            }
            , Layer, Layer + ".delete.btn");
            // Toggle Button for Command Type
            container.Add(new CuiButton {
                Button = {
                    Color = "0.5 0.5 0.5 1", Command = "em_togglecommandtype"
                }
                , Text = {
                    Text = "Console Command", Font = "robotocondensed-bold.ttf", FontSize = 18, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1"
                }
                , RectTransform = {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "120 -50", OffsetMax = "280 -20"
                }
            }
            , Layer, Layer + ".togglecommandtype.btn");
            CuiHelper.DestroyUi(player, Layer);
            CuiHelper.AddUi(player, container);
            UI_UpdateCreator(player);
        }
        // Toggle Command Type
        [ConsoleCommand("em_togglecommandtype")]
        private void ToggleCommandType(ConsoleSystem.Arg arg) {
            var player = arg.Player();
            if (player == null) return;
            if (_creatingEvents.TryGetValue(player.userID, out var ev)) {
                ev.CommandType = ev.CommandType == "console" ? "chat" : "console";
            }
            // Update the button text based on the new command type
            var container = new CuiElementContainer();
            container.Add(new CuiButton {
                Button = {
                    Color = "0.5 0.5 0.5 1", Command = "em_togglecommandtype"
                }
                , Text = {
                    Text = ev.CommandType == "console" ? "Console Command" : "Chat Command", Font = "robotocondensed-bold.ttf", FontSize = 18, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1"
                }
                , RectTransform = {
                    AnchorMin = "0.5 0.5", AnchorMax =
// ... [Code preview truncated due to length. Full source in attached file] ...

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