Information Announcer

Join/leave messages, rules, broadcasts & custom commands

Total Downloads: 2,609 - First Release: May 5, 2015 - Last Update: May 23, 2015

4.73333/5, 15 likes
  1. Wulf

    Wulf Community Admin

    I'd recommend creating a new thread in the appropriate forum section, that isn't exactly on topic for this thread. ;)
     
  2. Where should I post it?
     
  3. Everytime I configure the folder and change the default and restart server. The config always bugs back to the original. After numerous attempts it ends up making all my mos useless so i have to delete and start over. Any tricks to configuring it once and for all or will i always have to ask how high when mughisi says jump?
     
  4. Wulf

    Wulf Community Admin

    That means it isn't being edited right. Make sure it is valid JSON after you edit it.
     
  5. Hey guys, brand new to all of this stuff :) I'm curious how/where I find the file to customize the rules on this plugin that get's posted. I would love to get my own set of rules implemented so when people type /rules it shows the ones' that I have.. So can anyone tell me where/how to go and change that? Thanks!
     
  6. Go announcer confic files
    There you see default messages and rules. You can mod these text and make More lines.when add New lines end need To be samekind what default lines. Or announcer reset all you lines and go back To default config.when you are ready and saying files.type console or game /reload Announcer. Then /rules.if all its right you see you server rules
     
  7. Here is a copy of my .json file. It was working perfectly fine, i add one rule and now it wont stop reverting to default. Does anything look wrong here?
    Code:
    {
      "BroadcasterSettings": {
        "Enabled": true,
        "Interval": 120,
        "Messages": [
         "You can join our forums at middleearthroleplay.enjin.com.",
         "You can join our TeamSpeak by connecting to middleearthroleplay.teamspeak3.com in the teamspeak client.",
         "Type /rules to see our server's rules!",
         "Type /kit starterkit to redeem your starter kit.",
         "Type /ooc for Out Of Character chat.",
         "Type /xp to check your level stats.",
         "Type /declarewar and a playername to declare war against that persons guild.",
         "Type /alliancecommands to view all commands to form alliances with other guilds!",
         "Type /defy and a playername to start a duel with that person."
        ],
        "ShowChatPrefix": true,
        "ShowInRandomOrder": false
      },
      "ConnectionSettings": {
        "Enabled": true,
        "ExcludePlayers": [],
        "Log": true,
        "ShowChatPrefix": true,
        "ShowJoinMessages": true,
        "ShowLeaveMessages": true
      },
      "CustomCommands": {
        "Commands": {},
        "ShowChatPrefix": true
      },
      "Messages": {
        "PlayerJoined": "{0} has joined the server!",
        "PlayerLeft": "{0} has left the server"
      },
      "RulesSettings": {
        "Enabled": true,
        "Rules": [
          "1. Do not cheat on our server.",
          "2. No KoS under any circumstance.",
          "3. This is a STRICT roleplay server. Please stay in character.",
          "4. Thieving is allowed at night and must be roleplayed. Do not go out at night with stuff you want to lose and be prepared to defend yourself.",
          "5. You must go to war with the king and his guild and be the victor to claim the throne.",
          "6. Obey admins at all times.",
          "7. Keep profanity and racism out of chat.",
          "8. NO offline raiding of bases. There must be RP reasoning to raid a base.",
          "9. Please use a roleplay name consistent with the medieval era. A PoA can be provided to you to change your name if needed.",
          "10. If you die in a war with another guild, you must come back as a new character. A PoA can be provided.",
          "11. Do NOT block roads or resource nodes.",
          "12. Only 3 crests can be placed per guild. Conquering the map will not be allowed.",
          "13. Skybridging to get into a base is not allowed!",
          "14. Kings must set taxes to 3% or under when logging off if they wish to have tyranical taxes while they are online.",
          "15. Killing sleepers is allowed, do NOT log out outside of your base and expect to be safe.",
          "Not complying with these rules may result in a ban at any given time."
        ],
        "ShowChatPrefix": true
      },
      "Settings": {
        "ChatPrefix": "Server",
        "ChatPrefixColor": "950415"
      }
    }
     
  8. Wulf

    Wulf Community Admin

    Is that the exactly content from your modified version?
     
  9. Yes it is, i copy and paste that in there but when i restart it reverts to default.
     
  10. Wulf

    Wulf Community Admin

    I'd try running it through jsonlint.com and then copying the content from that. When a config file reverts, it is generally because it isn't formatted right.
     
  11. after adding my rules and restarting my server the config file keeps going back to its default state and removing my stuff.
    any help?
     
  12. i try using that jsonlint.com but 1. i don't understand what it is telling me and 2. i don't see what wrong ive been trying for ages now....
     
  13. Wulf

    Wulf Community Admin

    Could you upload the file you currently have right now?
     
  14. So I've had my server going for a while (three weeks) and I did manage to make the announcements work. When I leave my home to move to another place, a week later the announcements from completely. I've since restarted the server, ended the server, removed all plugins and configs, downloaded them again (I did transfer the text over to the announcer) and still unable to get this to work. Is there something I am missing, or is the plugin now bugged?
    [DOUBLEPOST=1470454681][/DOUBLEPOST]Figured out the issue. All I did was uninstall oxide from the server, then reinstalled it. I think it had something to do with the update RoK had.
     
  15. I do not understand why this doesn't work for me. I've put the config through jsonlint.com and it still refuses to work. Can anyone spot what I've done wrong here?

    Any help would be greatly appreciated :)
     
    Last edited by a moderator: Sep 17, 2016
  16. Wulf

    Wulf Community Admin

    Edit the config, not the plugin itself. The config is found under oxide/config.
     
  17. I was posting before this but I've edited the entire thing out. Once I had moved my files over to the .json I just validated it, missed out a few commas, corrected it and it's working perfectly. Sorry for my noobiness :D
    Thanks for the help.
     
    Last edited by a moderator: Sep 17, 2016
  18. Wulf

    Wulf Community Admin

    You're missing about 4 commas. You can check using JSONLint - The JSON Validator..
     
  19. So i want to change the rules but i cant find it and struggling
     
  20. Im trying to set it up to where i can send custom messages, i want to let people know i spawned in custom nodes on the map and want that to show up in the messages, i uploaded the plugin and restarted several times, but it uses the default settings for the plugin everytime.
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using CodeHatch.Build;
    using CodeHatch.Engine.Networking;namespace Oxide.Plugins
    {
        [Info("Announcer", "Mughisi", "1.1.1", ResourceId = 1003)]
        public class Announcer : ReignOfKingsPlugin
        {        #region Configuration Data
            // Do not modify these values, to configure this plugin edit
            // 'Announcer.json' in your server's config folder.
            // <drive>:\...\save\oxide\config\        bool configChanged;        // Plugin settings
            private const string DefaultChatPrefix = "Server";
            private const string DefaultChatPrefixColor = "950415";        public string ChatPrefix { get; private set; }
            public string ChatPrefixColor { get; private set; }        // Join/Leave watcher settings
            private const bool DefaultWatcherEnabled = true;
            private const bool DefaultJoinEnabled = true;
            private const bool DefaultLeaveEnabled = true;
            private const bool DefaultShowChatPrefixW = true;
            private const bool DefaultLog = true;
            private static readonly List<object> DefaultHideList = new List<object>();        public bool WatcherEnabled { get; private set; }
            public bool JoinEnabled { get; private set; }
            public bool LeaveEnabled { get; private set; }
            public bool ShowChatPrefixW { get; private set; }
            public bool LogToConsole { get; private set; }
            public List<string> HideList { get; private set; }        // Broadcaster settings
            private const bool DefaultBroadcasterEnabled = true;
            private static readonly List<object> DefaultBroadcasts = new List<object> { "There are additional Iron and Stone resource nodes placed around the map!", "Don't forget to bring your friends!", "Type /rules to see our server's rules!" };
            private const int DefaultBroadcastInterval = 120;
            private const bool DefaultShowChatPrefixB = true;
            private const bool DefaultShowRandom = false;        public bool BroadcasterEnabled { get; private set; }
            public List<string> Broadcasts { get; private set; }
            public int BroadcastInterval { get; private set; }
            public bool ShowChatPrefixB { get; private set; }        public bool ShowRandom { get; private set; }        // Rules settings
            private const bool DefaultRulesEnabled = true;
            private static readonly List<object> DefaultRules = new List<object> { "1. Do not cheat on our server.", "2. Speak English in chat at all times.", "3. No More Than 1 Wall on King's Bridge, No Sky Bases , No Bases Over Village", "Not complying with these rules may result in a ban at any given time." };
            private const bool DefaultShowChatPrefixR = true;        public bool RulesEnabled { get; private set; }
            public List<string> Rules { get; private set; }
            public bool ShowChatPrefixR { get; private set; }        // Custom commands
            private const bool DefaultShowChatPrefixC = true;
            private static readonly Dictionary<string, object> DefaultCustomCommands = new Dictionary<string, object>();        public bool ShowChatPrefixC { get; private set; }
            public Dictionary<string, CustomCommand> CustomCommands { get; private set; }        // Plugin messages
            private const string DefaultJoined = "{0} has joined the server!";
            private const string DefaultLeft = "{0} has left the server!";        public string Joined { get; private set; }
            public string Left { get; private set; }        #endregion        public class CustomCommand
            {
                public string Command;
                public List<string> Messages;            public CustomCommand()
                {
                }            public CustomCommand(string command, List<string> messages)
                {
                    Command = command;
                    Messages = messages;
                }
            }        readonly Random random = new Random();        int previouslyBroadcastedMessage = -1;        void Loaded()
            {
                LoadConfigData();
               
                if (BroadcasterEnabled)
                    timer.Repeat(BroadcastInterval, 0, BroadcastMessage);            if (RulesEnabled)
                    cmd.AddChatCommand("rules", this, "ShowRules");
            }        protected override void LoadDefaultConfig() => Warning("New configuration file created.");        private void CustomChatCommand(Player player, string command, string[] args)
            {
                foreach (var msg in CustomCommands[command.ToLower()].Messages)
                {
                    var message = msg;
                    if (ShowChatPrefixC)
                        message = $"[{ChatPrefixColor}]{ChatPrefix}[FFFFFF]: {message}";                PrintToChat(player, message);
                }
            }        private void OnPlayerConnected(Player player)
            {
                if (player.Name == "Server" && player.Id == 9999999999) return;            if (!WatcherEnabled) return;
                var message = string.Format(Joined, player.Name);            if (LogToConsole)
                    Log(message);            if (!JoinEnabled) return;            if (HideList.Contains(player.Id.ToString())) return;            if (ShowChatPrefixW)
                    message = $"[{ChatPrefixColor}]{ChatPrefix}[FFFFFF]: {message}";            PrintToChat(message);
            }        private void OnPlayerDisconnected(Player player)
            {
                if (!WatcherEnabled) return;
                var message = string.Format(Left, player.Name);            if (LogToConsole)
                    Log(message);            if (!LeaveEnabled) return;            if (HideList.Contains(player.Id.ToString())) return;            if (ShowChatPrefixW)
                    message = $"[{ChatPrefixColor}]{ChatPrefix}[FFFFFF]: {message}";            PrintToChat(message);
            }
           
            void BroadcastMessage()
            {
                string message;
                if (ShowRandom && Broadcasts.Count > 2)
                {
                    var randomMessage = random.Next(Broadcasts.Count);
                    while (randomMessage == previouslyBroadcastedMessage)
                        randomMessage = random.Next(Broadcasts.Count);                previouslyBroadcastedMessage = randomMessage;                message = Broadcasts[randomMessage];
                }
                else
                {
                    previouslyBroadcastedMessage++;
                    if (previouslyBroadcastedMessage >= Broadcasts.Count) previouslyBroadcastedMessage = 0;
                    message = Broadcasts[previouslyBroadcastedMessage];
                }
                if (ShowChatPrefixB)
                    message = $"[{ChatPrefixColor}]{ChatPrefix}[FFFFFF]: {message}";            PrintToChat(message);
            }        void ShowRules(Player player, string cmd, string[] args)
            {
                foreach (var rule in Rules)
                {
                    var message = rule;                if (ShowChatPrefixR)
                        message = $"[{ChatPrefixColor}]{ChatPrefix}[FFFFFF]: {message}";                PrintToChat(player, message);
                }
            }        [ChatCommand("version")]
            private void VersionCommand(Player player, string command, string[] args)
            {
                PrintToChat(player, "Oxide version: {0}, Reign of Kings version: {1} ", Core.OxideMod.Version.ToString(), GameInfo.VersionName);
            }        void Log(string msg) => Puts($"{Title} : {msg}");        void Warning(string msg) => PrintWarning($"{Title} : {msg}");        void LoadConfigData()
            {
                // Plugin settings
                ChatPrefix = GetConfigValue("Settings", "ChatPrefix", DefaultChatPrefix);
                ChatPrefixColor = GetConfigValue("Settings", "ChatPrefixColor", DefaultChatPrefixColor);            // Join/Leave watcher settings
                WatcherEnabled = GetConfigValue("ConnectionSettings", "Enabled", DefaultWatcherEnabled);
                JoinEnabled = GetConfigValue("ConnectionSettings", "ShowJoinMessages", DefaultJoinEnabled);
                LeaveEnabled = GetConfigValue("ConnectionSettings", "ShowLeaveMessages", DefaultLeaveEnabled);
                ShowChatPrefixW = GetConfigValue("ConnectionSettings", "ShowChatPrefix", DefaultShowChatPrefixW);
                LogToConsole = GetConfigValue("ConnectionSettings", "Log", DefaultLog);
                var tempHideList = GetConfigValue("ConnectionSettings", "ExcludePlayers", DefaultHideList);            // Broadcaster settings
                BroadcasterEnabled = GetConfigValue("BroadcasterSettings", "Enabled", DefaultBroadcasterEnabled);
                var tempBroadcasts = GetConfigValue("BroadcasterSettings", "Messages", DefaultBroadcasts);
                BroadcastInterval = GetConfigValue("BroadcasterSettings", "Interval", DefaultBroadcastInterval);
                ShowChatPrefixB = GetConfigValue("BroadcasterSettings", "ShowChatPrefix", DefaultShowChatPrefixB);
                ShowRandom = GetConfigValue("BroadcasterSettings", "ShowInRandomOrder", DefaultShowRandom);            // Rules settings
                RulesEnabled = GetConfigValue("RulesSettings", "Enabled", DefaultRulesEnabled);
                var tempRules = GetConfigValue("RulesSettings", "Rules", DefaultRules);
                ShowChatPrefixR = GetConfigValue("RulesSettings", "ShowChatPrefix", DefaultShowChatPrefixR);            // Custom commands
                ShowChatPrefixC = GetConfigValue("CustomCommands", "ShowChatPrefix", DefaultShowChatPrefixC);
                var tempCustomCommands = GetConfigValue("CustomCommands", "Commands", DefaultCustomCommands);
                // Plugin messages
                Joined = GetConfigValue("Messages", "PlayerJoined", DefaultJoined);
                Left = GetConfigValue("Messages", "PlayerLeft", DefaultLeft);            // Handle all config lists.
                HideList = new List<string>();
                if (tempHideList != null)
                    foreach (var str in tempHideList)
                        HideList.Add(str.ToString());            Broadcasts = new List<string>();
                if (tempBroadcasts != null)
                    foreach (var str in tempBroadcasts)
                        Broadcasts.Add(str.ToString());            Rules = new List<string>();
                if (tempRules != null)
                    foreach (var str in tempRules)
                        Rules.Add(str.ToString());            CustomCommands = new Dictionary<string, CustomCommand>();
                if (tempCustomCommands != null)
                {
                    foreach (var obj in tempCustomCommands)
                    {
                        var command = obj.Key;                    var content = obj.Value as List<object>;
                        if (content == null) continue;
                        var messages = content.Select(msg => msg.ToString()).ToList();
                        CustomCommands.Add(command.ToLower(), new CustomCommand(command, messages));
                    }
                }            foreach(var command in CustomCommands)
                    cmd.AddChatCommand(command.Key, this, "CustomChatCommand");            if (!configChanged) return;
                Warning("The configuration file was updated!");
                SaveConfig();
            }        private T GetConfigValue<T>(string category, string setting, T defaultValue)
            {
                var data = Config[category] as Dictionary<string, object>;
                object value;
                if (data == null)
                {
                    data = new Dictionary<string, object>();
                    Config[category] = data;
                    configChanged = true;
                }
                if (data.TryGetValue(setting, out value)) return (T)Convert.ChangeType(value, typeof(T));
                value = defaultValue;
                data[setting] = value;
                configChanged = true;
                return (T)Convert.ChangeType(value, typeof(T));
            }
        }
    }