/***********************************************************************************************************************/ /*** DO NOT edit this file! Edit the files under `oxide/config` and/or `oxide/lang`, created once plugin has loaded. ***/ /***********************************************************************************************************************/ /*** Developed and maintained by netch.dev ***/ /*** Copyright, All rights reserved. ***/ /*** Permission is granted to use this on your server only. You do not have permission to re-sell or steal code. ***/ /*** Website: https://www.modpulse.com ***/ /*** Support Discord: https://discord.com/invite/yz5D3PBXa8 ***/ /***********************************************************************************************************************/ using Newtonsoft.Json; using System.Collections.Generic; namespace Oxide.Plugins { [Info("AnnouncerPlus", "Netch", "1.1.0")] [Description("Announces separate messages to default and VIP players")] public class AnnouncerPlus : RustPlugin { #region Vars private const string VIP_PERM = "announcerplus.vip"; // Receive VIP messages instead of default private int _defaultMessageIndex = 0; private int _vipMessageIndex = 0; #endregion #region Oxide Hooks private void OnServerInitialized() { if (!permission.PermissionExists(VIP_PERM, this)) permission.RegisterPermission(VIP_PERM, this); timer.Every(config.MessageInterval, () => SendGlobalMessages()); } #endregion #region Config private ConfigData config; private class ConfigData { [JsonProperty("Message Interval (s)")] public int MessageInterval; [JsonProperty("Default Message Lang IDs [EDIT MESSAGES IN /OXIDE/LANG/]")] public List DefaultMessages; [JsonProperty("VIP Message Lang IDs (announcerplus.vip) [EDIT MESSAGES IN /OXIDE/LANG/]")] public List VipMessages; [JsonProperty("Chat Settings")] public ChatSettings ChatSettings; } public class ChatSettings { [JsonProperty("Message Icon (Steam64 ID)")] public ulong SteamIDIcon = 0; [JsonProperty("Message Color")] public string MessageColour = "#FFFFFF"; } private ConfigData GetDefaultConfig() { return new ConfigData { MessageInterval = 600, DefaultMessages = new List { "M1", "M2", "M3", "[EXAMPLE] Add as many messages as you need just make sure the ID is unique." }, VipMessages = new List { "V1", "V2", "V3", "V4", }, ChatSettings = new ChatSettings() }; } protected override void LoadConfig() { base.LoadConfig(); try { config = Config.ReadObject(); if (config == null) { LoadDefaultConfig(); } } catch { LoadDefaultConfig(); } SaveConfig(); } protected override void LoadDefaultConfig() { PrintError("Configuration file is corrupt(or doesn't exist), creating a new one!"); config = GetDefaultConfig(); } protected override void SaveConfig() { Config.WriteObject(config); } #endregion #region Localization private void SendGlobalMessages() { string defaultMessageID = config.DefaultMessages[_defaultMessageIndex]; string vipMessageID = config.VipMessages.Count > 0 ? config.VipMessages[_vipMessageIndex] : defaultMessageID; _defaultMessageIndex++; if (_defaultMessageIndex >= config.DefaultMessages.Count) _defaultMessageIndex = 0; _vipMessageIndex++; if (_vipMessageIndex >= config.VipMessages.Count) _vipMessageIndex = 0; foreach (BasePlayer player in BasePlayer.activePlayerList) { if (permission.UserHasPermission(player.UserIDString, VIP_PERM)) Print(player, Lang(vipMessageID, player.UserIDString)); else Print(player, Lang(defaultMessageID, player.UserIDString)); } } private void Print(BasePlayer player, string message) { if (string.IsNullOrEmpty(message)) return; player.SendConsoleCommand("chat.add", 2, config.ChatSettings.SteamIDIcon, $"{Lang("P", player.UserIDString)} {message}"); } private string Lang(string key, string playerID = null, params object[] args) { return string.Format(lang.GetMessage(key, this, playerID), args); } protected override void LoadDefaultMessages() { Dictionary messages = new Dictionary { { "P", "[Announcer]" } }; foreach (string item in config.DefaultMessages) { if (item.StartsWith("[EXAMPLE]")) continue; if (!messages.ContainsKey(item)) messages.Add(item, $"Update message {item} in the oxide/lang/ files"); } foreach (string item in config.VipMessages) { if (!messages.ContainsKey(item)) messages.Add(item, $"Update message {item} in the oxide/lang/ files"); } lang.RegisterMessages(messages, this); } #endregion } }