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; }
Don't send message if it contains defined string
Discussion in 'Rust Development' started by as esu grejtis, Mar 8, 2017.
-
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 -
Yep, it replies, but message still shows up in chat.
-
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)
-
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.
-
So if I'm using BetterChat I need to do what? lol
-
Wulf Community Admin
-
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. -
Wulf Community Admin
-
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; } } }
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? -
Wulf Community Admin