Jump to content

Avoiding code's execution inside 'onPlayerChat'


'LinKin

Recommended Posts

Hello,

I've some script that mutes a player in main chat or globally; So inside of those, in order to prevent a player talking in the chatbox, I use cancelEvent() inside onPlayerChat.

I want to make another script that does something each time any message is output in the chatBox (by using onChatMessage)

But I've one issue, this event will be triggered even if a muted player tries to chat, how could I prevent this without touching the other scripts that mute the player?

I tried using wasEventCancelled() inside onChatMessage but it won't work.

Thanks for your time.

Link to comment

I'd use setPlayerMuted and isPlayerMuted instead, either way I don't see why wasEventCancelled would return false since the event itself is being cancelled.

Although, "cancelEvent does not have an effect on all events, see the individual event's pages for information on what happens when the event is canceled. cancelEvent does not stop further event handlers from being called, as the order of event handlers being called is undefined in many cases. Instead, you can see if the currently active event has been cancelled using wasEventCancelled.".

So basically, you could do it way easier by using the functions I stated above and therefore avoid having further issues.

Link to comment
  • Moderators

What about making them cooperate?

1 script checks if the other is running. (the one who doesn't mute, checks the one who mutes)

If it is running, you start using export functions or a custom event.

If not running, use the normal event.

Link to comment

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.
×
×
  • Create New...