Solved Stop certain players from receiving chat.

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

sandor_1234

Active Member
Jan 26, 2017
165
5
0
21
I am searching for a way to stop certain players from receiving the chat.
Is there a thing in skript to do this:
https://bukkit.org/threads/disabling-chat-for-a-player.81999/

I know i could do it with something like this:
code_language.skript:
on chat:
    cancel event
    loop all players:
        if {chat::%loop-player%} is "On":
            send "%message%" to loop-player
But by doing it that way a lot off plugins will stop working and the chat messages don't get logged to the console anymore.
 
So, at the moment, your code does this:

code_language.skript:
on chat:
    cancel chat message
    loop all online players:
        if online player has chat enabled:
            send message to player

What if I told you we reverse the logic, while still having the same effect?

code_language.skript:
on chat:
    loop all players:
        if looped player has chat disabled:
            nullify the message

Now, the above was all sudo-code meant to be used to explain things more effectively; here's the above code in Skript-syntax:

code_language.skript:
on chat:
    loop all players:
        if {chat::%loop-player%} is "Off":
            remove loop-player from chat recipients

You can also use this, which is the same thing, but is a lot more compact:
code_language.skript:
on chat:
    loop all players where [{chat::%player input%} is "Off"]:
        remove loop-player from chat recipients

Note: the chat recipients expression is from RandomSK, but it was merged into Skellett
the chat recipients expression is vanilla Skript :emoji_thumbsup:
 
Last edited by a moderator:
So, at the moment, your code does this:

code_language.skript:
on chat:
    cancel chat message
    loop all online players:
        if online player has chat enabled:
            send message to player

What if I told you we reverse the logic, while still having the same effect?

code_language.skript:
on chat:
    loop all players:
        if looped player has chat disabled:
            nullify the message

Now, the above was all sudo-code meant to be used to explain things more effectively; here's the above code in Skript-syntax:

code_language.skript:
on chat:
    loop all players:
        if {chat::%loop-player%} is "Off":
            remove loop-player from chat recipients

You can also use this, which is the same thing, but is a lot more compact:
code_language.skript:
on chat:
    loop all players where [{chat::%player input%} is "Off"]:
        remove loop-player from chat recipients

Note: the chat recipients expression is from RandomSK, but it was merged into Skellett
code_language.skript:
set chat recipients to all players where [{chat::%player input%} is "On"]
and chat recipients is vanilla
 
Status
Not open for further replies.