using System; using System.Collections.Generic; using Newtonsoft.Json; using Oxide.Core; using Oxide.Core.Plugins; using UnityEngine; using System.Linq; using Oxide.Core.Libraries.Covalence; namespace Oxide.Plugins { [Info("Timed Commands", "Bilumer", "1.0.3")] [Description("Run commands at a random time")] class TimedCommands : RustPlugin { public int numberOfEvents = 1; public int eventNumber = 0; private ConfigData config; protected override void LoadDefaultConfig() { Puts("Creating new config file."); config = ConfigData.BaseConfig(); numberOfEvents = config.ComList.Count; } protected override void LoadConfig() { base.LoadConfig(); config = Config.ReadObject(); numberOfEvents = config.ComList.Count; } protected override void SaveConfig() { Config.WriteObject(config); } private class ConfigData { [JsonProperty(PropertyName = "Command List")] public List ComList = new List(); [JsonProperty(PropertyName = "Longest Time In Seconds")] public float upper; [JsonProperty(PropertyName = "Shortest Time In Seconds")] public float lower; [JsonProperty(PropertyName = "In Order")] public bool order; public static ConfigData BaseConfig() { return new ConfigData() { ComList = new List{"randomCommand", "randomCommand1", "randomCommand2"}, upper = 500, lower = 200, order = true }; } } void Loaded() { Timer() ; } void Timer() { float TimedCommands = UnityEngine.Random.Range(config.lower, config.upper); timer.Once(TimedCommands, () => { CallCom(); }); } void CallCom() { eventNumber++; eventNumber = eventNumber % numberOfEvents; if (config.order) { var command = config.ComList[eventNumber]; covalence.Server.Command(command); Puts($"Command called '{command}'"); Timer(); } else { var command = config.ComList[new System.Random().Next(config.ComList.Count())]; covalence.Server.Command(command); Puts($"Command called '{command}'"); Timer(); } } } }