1. Hello. So I was trying to make an auto reply plugin. Basicly if message contains defined string it shouldn't send it, but how do that? Im including my code below and part who doesnt work is return false;(it shouldn't send the message).

    Code:
            private object OnUserChat(IPlayer player, string message)
            {
                if (message.Contains("admin"))
                {
                    player.Reply("BannedWord", this, player.Id);
                    return false;
                }
                return null;
            }
     
  2. I think you want to try OnPlayerChat(ConsoleSystem.Arg arg)

    Edit: Well, unless you're going for a Covalence plugin... (not enough coffee) So your reply to player works, but it doesn't cancel the original chat message?
     
    Last edited by a moderator: Mar 8, 2017
  3. Yep, it replies, but message still shows up in chat.
     
  4. Do you have any other plugins installed that affect/modify chat? That procedure works from what I can see. (I literally copy/pasted into one of my own plugins and it runs just fine)
     
  5. Wulf

    Wulf Community Admin

    Returning anything other than null would cancel the message in your own plugin, but not for any other plugins that are sending their own message replacement in that same hook. So if you have another plugin installed that is handling the chat already, you'd need to make them work together.
     
  6. So if I'm using BetterChat I need to do what? lol
     
  7. Wulf

    Wulf Community Admin

    You'd either not use it, or you'd need to tie into the plugin's methods to send the chat or disable it from sending.
     
  8. As per Wulf's reply: Better Chat | Page 218 | Oxide

    I've posted an example change to BetterChat you can implement in yours, and then structure your own OnBetterChat hook to return true to drop the message.
     
  9. Wulf

    Wulf Community Admin

    I don't think that change is necessary, as BetterChat already stops handling if you return true or false in OnBetterChat to allow your plugin to handle it instead. This won't fix other plugins that also do the same though.
     
  10. I suppose that's true:
    Code:
    using Oxide.Core;
    using Oxide.Core.Plugins;
    using Oxide.Core.Libraries.Covalence;namespace Oxide.Plugins
    {
        [Info("Sample Plugin", "", "1.0")]
        class SamplePlugin : RustPlugin
        {
            [PluginReference] Plugin BetterChat;        [HookMethod("OnBetterChat")]
            private object SampleOnBetterChat(IPlayer player, string message)
            {
                if(message.Contains("$"))
                {
                    // Stop OnBetterChat from executing, and make it so the next OnUserChat hook is called.
                    return false;
                }            return null;
            }        object OnUserChat(IPlayer player, string message)
            {
                if(message.Contains("$"))
                {
                    rust.RunServerCommand("say", "Someone had a $ in their message (via OnUserChat)!");
                    return false;
                }
              
                return null;
            }
        }
    }
    
    It "looks" worse imo in terms of the implementation, but it doesn't require any plugin edits so it's a lot simpler and doesn't require whatever chat handling hook is used to add more code if they follow the basic additional Interface.CallHook implementation. (and yes, looking past the fact any other hooks registered would execute first and whatnot)

    Design wise, do you think it's more dev friendly for hooks to just allow fall-through like BetterChat is doing for hook executions, or just support their additional hooks having the control I proposed?
     
  11. Wulf

    Wulf Community Admin

    There are a lot of things that could be improved with how hooks work.