blumi

[Server Side c#] Chat messaging

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 by blumi

Share this post


Link to post
Share on other sites
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. ☺️

Share this post


Link to post
Share on other sites
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 by blumi
  • Like 1

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.