blumi Posted February 3, 2019 Share Posted February 3, 2019 Hello to all! I have a question about chat messaging. I read the OnChatMessage documentation. There was an example for filtering bad words. The [DisableDefaultChat] attribute was used to disable the default chat behavior, but it was written that this attribute was not yet implemented. What can I use instead of this attribute for the same behavior? Thank you in advance Link to comment Share on other sites More sharing options...
GangstaSunny Posted February 4, 2019 Share Posted February 4, 2019 NAPI.Data.SetEntityData(player, "muted", 1); public void OnChatMessage(Client player, string message) { if(NAPI.Data.GetEntityData(player, "muted")) { NAPI.Chat.SendChatMessageToPlayer(player, "You're muted"); return; } NAPI.Chat.SendChatMessageToAll(player.Name + ": " + message); } I assume u want to mute the player. Link to comment Share on other sites More sharing options...
blumi Posted February 4, 2019 Author Share Posted February 4, 2019 1 час назад, GangstaSunny сказал: NAPI.Data.SetEntityData(player, "muted", 1); public void OnChatMessage(Client player, string message) { if(NAPI.Data.GetEntityData(player, "muted")) { NAPI.Chat.SendChatMessageToPlayer(player, "You're muted"); return; } NAPI.Chat.SendChatMessageToAll(player.Name + ": " + message); } I assume u want to mute the player. Hey. Thank you for your reply. I meant remove player message and display this message with custom text formating. Link to comment Share on other sites More sharing options...
GangstaSunny Posted February 4, 2019 Share Posted February 4, 2019 So if someone sends "word" you want to edit the text and output "wo*d" instead (for example), right? https://wiki.gtanet.work/index.php?title=OnChatMessage&mobileaction=toggle_view_desktop the example on the bottom of the page is not working? or do I still don't get what you want. kind regards Link to comment Share on other sites More sharing options...
blumi Posted February 4, 2019 Author Share Posted February 4, 2019 57 минут назад, GangstaSunny сказал: So if someone sends "word" you want to edit the text and output "wo*d" instead (for example), right? https://wiki.gtanet.work/index.php?title=OnChatMessage&mobileaction=toggle_view_desktop the example on the bottom of the page is not working? or do I still don't get what you want. kind regards Yes, I mean it. In this example, the [Disable Default Chat] attribute does not work. Will the [return] keyword cancel the player message? Link to comment Share on other sites More sharing options...
blumi Posted February 5, 2019 Author Share Posted February 5, 2019 10 часов назад, GangstaSunny сказал: So if someone sends "word" you want to edit the text and output "wo*d" instead (for example), right? https://wiki.gtanet.work/index.php?title=OnChatMessage&mobileaction=toggle_view_desktop the example on the bottom of the page is not working? or do I still don't get what you want. kind regards I tried to make a chat like in your example. I wrote a small function for displaying a player's messages in the chat in any format and did not display messages that were written from the game chat. Here is my code: [ServerEvent(Event.ChatMessage)] public void OnChatMessage(Client player, string message) { string playerName = player.Name.Replace("_", " "); TimeSpan time = NAPI.World.GetTime(); NAPI.Chat.SendChatMessageToAll($"[{time.Hours}:{time.Minutes}:{time.Seconds}]~b~{playerName}: ~w~{message}"); return; } When I compiled the project and tried to write something in the chat, I saw 2 messages in the chat. The first message was my message, which I wrote using the code, and the second message was the message that the player wrote from the game chat. Here is picture: Chat messages Link to comment Share on other sites More sharing options...
Sleepy Posted February 5, 2019 Share Posted February 5, 2019 (edited) sorry. del. Edited February 5, 2019 by Sleepy fix. sorry. Link to comment Share on other sites More sharing options...
blumi Posted February 5, 2019 Author Share Posted February 5, 2019 (edited) 10 минут назад, Sleepy сказал: [ServerEvent(Event.ChatMessage)] public void OnChatMessage(Client player, string message) { string playerName = player.Name.Replace("_", " "); TimeSpan time = NAPI.World.GetTime(); NAPI.Chat.SendChatMessageToAll($"[{time.Hours}:{time.Minutes}:{time.Seconds}]~b~{playerName}: ~w~{message}"); return; } I beg your pardon. Such issue. Why use return in a method of type "void"? We use "return" to stop the execution of the method. I used return at the end of the method because I thought it would not execute the default chat logic. Edited February 5, 2019 by blumi Link to comment Share on other sites More sharing options...
Sleepy Posted February 5, 2019 Share Posted February 5, 2019 1 минуту назад, blumi сказал: We use refund to stop the execution of the method. I used return at the end of the method because I thought it would not execute the default chat logic. I understood. ☺️ Link to comment Share on other sites More sharing options...
blumi Posted February 5, 2019 Author Share Posted February 5, 2019 (edited) 7 часов назад, Sleepy сказал: I understood. ☺️ If you interested of this problem I found Server-Side command: NAPI.Server.SetGlobalServerChat(false) I can't verify it now, but I will write here when I check this command. Yes it works. This team solved my problem. Edited February 5, 2019 by blumi 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now