Is it possible to modify chat messages before they are sent (C#)?
Thank you,
Maniah
Solved Modify chat messages [C#]
Discussion in 'Rust Development' started by Maniah, Jun 16, 2015.
-
Wulf Community Admin
http://docs.oxidemod.org/rust/#onplayerchat
If you'd like a working example, take a look at any plugin that adds titles, changes the chat, etc. -
I tried that before asking the question. But I can't find any C# examples. All the mods using this seem to be writtein in LUA.
-
Code:bool OnPlayerChat(ConsoleSystem.Arg arg) { BasePlayer player = PlayerFromArg; string message = MessageFromArg; string userId = UserIdFromPlayer; WriteInChat(DisplayNameFromPlayer, message, userId); blockMessage; }
Last edited by a moderator: Jun 16, 2015 -
Ended up with:
Code:[HookMethod("OnPlayerChat")] object OnPlayerChat(ConsoleSystem.Arg arg) { string playerChat = arg.GetString(0, "text"); BasePlayer player = arg.connection.player as BasePlayer; string result = ""; string playerColor = "#cccccc"; string factionColor = allianceColor; if (player != null && playerChat != null) { result = string.Format("<color={0}>{1}</color>: {2}", playerColor, player.displayName, playerChat); PrintToChat(result); return "handled"; } } }
-
Also I don't see the reason for
string factionColor = allianceColor;
The rest seems fine -
You do not need to use the HookMethod attribute in plugins
Some redundancy here and there but should work, only part I'm not sure of is the arg.GetString part for when the user sends a message which has quotes in it, not sure if it will still see everything as a single argument or if it starts a second one, so that's something you'll need to test.