using System.Linq; using System.Collections.Generic; using UnityEngine; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Oxide.Core; using Oxide.Core.Plugins; using Rust; #region Changelogs and ToDo /********************************************************************** * * 1.0.0 : - Initial release * 1.1.0 : - Optimised simple queue system * - Added Tip duration to the cfg * - API system working for other plugins to use same queue * 1.1.1 : - Updated API - Added show as warning to the cfg - Warning Tips have a max timer of 5 sec * * API void TIP(BasePlayer player, string message, float dur , bool warning) * RandomTips?.Call("TIP", player, "Your text here", 6f ,true); * **********************************************************************/ #endregion namespace Oxide.Plugins { [Info("RandomTips", "Krungh Crow", "1.1.1")] [Description("Send random Gametips to players")] class RandomTips : RustPlugin { #region Variables const string NoTip_Perm = "randomtips.exclude"; bool ActiveTip = false; bool SendAsWarning; #endregion #region Configuration void Init() { if (!LoadConfigVariables()) { Puts("Config file issue detected. Please delete file, or check syntax and fix."); return; } permission.RegisterPermission(NoTip_Perm, this); } private ConfigData configData; class ConfigData { [JsonProperty(PropertyName = "Show Messages")] public bool Use = false; [JsonProperty(PropertyName = "Prefix")] public string prefix = "[YourServer]"; [JsonProperty(PropertyName = "Interval (seconds)")] public int interval = 600; [JsonProperty(PropertyName = "Global Tip Duration (seconds)")] public float GTimer = 5; [JsonProperty(PropertyName = "Show as warning (max 5 sec)")] public bool Warning = false; [JsonProperty(PropertyName = "Messages")] public List Messages = new List(); } class Setup { [JsonProperty(PropertyName = "Use Profile")] public bool Use = false; [JsonProperty(PropertyName = "Messages")] public List Messages = new List(); } private bool LoadConfigVariables() { try { configData = Config.ReadObject(); } catch { return false; } SaveConf(); return true; } protected override void LoadDefaultConfig() { Puts("Fresh install detected Creating a new config file."); configData = new ConfigData(); configData.Messages = new List() { {"Join our Discord ,Click [view webpage] button."}, {"We run several cool Plugins !"}, {"Grab one of our kits using /kit ."}, {"Color code is supported"} }; SaveConf(); } void SaveConf() => Config.WriteObject(configData, true); #endregion #region Hooks void OnServerInitialized() { if(configData.Use == false) { Puts("Send messages is false change the messages to your likings before setting it to true and reload , Unloading Random Tips"); timer.Once(3, () => { Interface.Oxide.UnloadPlugin(nameof(RandomTips)); }); return; } else if (configData.Messages.Count == 0) { Puts("The message list is empty , Unloading Random Tips"); timer.Once(3, () => { Interface.Oxide.UnloadPlugin(nameof(RandomTips)); }); return; } SendArandomMessage(); } void Unload() { foreach (var player in BasePlayer.activePlayerList) { if (player == null) return; player?.SendConsoleCommand("gametip.hidegametip"); } } #endregion #region Helpers private void SendArandomMessage() { timer.Every(configData.interval, () => { RandomMessage(); }); } private void RandomMessage () { string MSG = configData.Messages[new System.Random().Next(configData.Messages.Count())]; string prefix = configData.prefix; SendAsWarning = configData.Warning; foreach (var player in BasePlayer.activePlayerList) { if (player == null) return; if (permission.UserHasPermission(player.UserIDString, NoTip_Perm)) return; TIP(player, prefix + MSG, configData.GTimer, SendAsWarning); } } #endregion #region API void TIP(BasePlayer player, string message, float dur, bool warning) { if (player == null) return; if (!ActiveTip) { int Warn = 0; if (warning == true) Warn = 1; player?.SendConsoleCommand("gametip.hidegametip"); if (warning == true) player.SendConsoleCommand("gametip.showtoast", Warn, message, null, null);//max 5 sec if (warning == false) player?.SendConsoleCommand("gametip.showgametip", message); ActiveTip = true; timer.Once(dur, () => { player?.SendConsoleCommand("gametip.hidegametip"); ActiveTip = false; }); } else timer.Once(1f, () => TIP(player, message, dur, warning)); } #endregion } }