Solved Toggleable json 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!

Wynnevir

Well-Known Member
Jul 9, 2017
1,015
62
48
30
Elsewhere
What I want:
I have a chat skript that I'd like augmented. What I want is for players to be able to use a command to hide everyone else's chat from them, save for if the message contains "@TheirName". This on it's own isn't hard, but I ran into issues as my chat is json. So if anyone knows how to make my skript chat-toggle-friendly, I'd greatly appreciate it! I'm too angry at it to work on it for a bit, lol.

The current chattoggle command:
code_language.skript:
command /chattoggle:
    trigger:
        if {hidechat::%player%} is true:
            set {hidechat::%player%} to false
            send "&e&l[&b&l✔&e&l] &r&7Player chat now visible."
        else:
            set {hidechat::%player%} to true
            send "&e&l[&b&l✔&e&l] &r&7Player chat hidden. You can still be mentioned wih ""@""."

My current chat code(without any of the measures I tried to get it to toggle):
code_language.skript:
on chat:
    set {_chatcooldown} to difference between {chatcooldown.last::%player%} and now
    if {_chatcooldown} is less than 30 seconds:
        if {chatmessage::%player%} is equal to "%message%":
            send "&e&l[&d&l✖&e&l] &r&7That's the same as your last message. Wait 30 seconds to chat the same thing."
            cancel event
            stop
    loop all players:
        remove loop-player from chat recipients   
    if player has permission "owner":
        json("@a","&b&o%player's display name% &7❖||cmd:/owner||ttp:&b&lOwner %new line%&b%player%|| &7%message%")
        stop
    else if player has permission "srguardian":
        json("@a","&b%player's display name% &7●||cmd:/action %player%||ttp:&bSrGuardian %new line%&b%player%|| &7%message%")
        stop
    else if player has permission "guardian":
        json("@a","&b%player's display name% ||cmd:/action %player%||ttp:&bGuardian %new line%&b%player%||&7● &7%message%")
        stop
    else if player has permission "ancient":
        json("@a","&d⚜&9%player's display name%&d⚜ ||cmd:/action %player%||ttp:&5Ancient %new line%&5%player%||&7● &7%message%")
        stop
    else if player has permission "youtuber":
        json("@a","&c[&f►&c]&3%player's display name% ||cmd:/action %player%||ttp:&cYoutuber %new line%&7%player%||&7● &7%message%")
        stop
    else if player has permission "wanderer":
        json("@a","&3%player's display name% ||cmd:/action %player%||ttp:&3Wanderer %new line%&3%player%||&7● &7%message%")
        stop
    else if player has permission "newcomer":
        json("@a","&7%player's display name% ||cmd:/action %player%||ttp:&7Newcomer %new line%&7%player%||&7● &7%message%")
        stop
    else if player has permission "dreamer":
        json("@a","&e☆&9%player's display name%&e☆ ||cmd:/action %player%||ttp: &9Dreamer %new line%&9%player%||&7● &7%message%")
        stop
    set {chatmessage::%player%} to the message
    set {chatcooldown.last::%player%} to now
When I'd like it by:
Whenever
 
i believe this will do what you want
code_language.skript:
on chat:
    set {_chatcooldown} to difference between {chatcooldown.last::%player%} and now
    if {_chatcooldown} is less than 30 seconds:
        if {chatmessage::%player%} is equal to "%message%":
            send "&e&l[&d&l✖&e&l] &r&7That's the same as your last message. Wait 30 seconds to chat the same thing."
            cancel event
            stop

    clear chat recipients
    loop all players: 
        set {_sendMessage} to false
        if {hidechat::%loop-player%} is not true:
            set {_sendMessage} to true
        else if "%message%" contains "@%loop-value%":
            set {_sendMessage} to true

        if {_sendMessage} is true:
            if player has permission "owner":
                json("%loop-value%","&b&o%player's display name% &7❖||cmd:/owner||ttp:&b&lOwner %new line%&b%player%|| &7%message%")
            else if player has permission "srguardian":
                json("%loop-value%","&b%player's display name% &7●||cmd:/action %player%||ttp:&bSrGuardian %new line%&b%player%|| &7%message%")
            else if player has permission "guardian":
                json("%loop-value%","&b%player's display name% ||cmd:/action %player%||ttp:&bGuardian %new line%&b%player%||&7● &7%message%")
            else if player has permission "ancient":
                json("%loop-value%","&d⚜&9%player's display name%&d⚜ ||cmd:/action %player%||ttp:&5Ancient %new line%&5%player%||&7● &7%message%")
            else if player has permission "youtuber":
                json("%loop-value%","&c[&f►&c]&3%player's display name% ||cmd:/action %player%||ttp:&cYoutuber %new line%&7%player%||&7● &7%message%")
            else if player has permission "wanderer":
                json("%loop-value%","&3%player's display name% ||cmd:/action %player%||ttp:&3Wanderer %new line%&3%player%||&7● &7%message%")
            else if player has permission "newcomer":
                json("%loop-value%","&7%player's display name% ||cmd:/action %player%||ttp:&7Newcomer %new line%&7%player%||&7● &7%message%")
            else if player has permission "dreamer":
                json("%loop-value%","&e☆&9%player's display name%&e☆ ||cmd:/action %player%||ttp: &9Dreamer %new line%&9%player%||&7● &7%message%")

    set {chatmessage::%player%} to the message
    set {chatcooldown.last::%player%} to now
you can clear recipients instead of looping and removing, and you dont need stop after else if statements, it only runs the else part if the previous if statement was false
 
i believe this will do what you want
code_language.skript:
on chat:
    set {_chatcooldown} to difference between {chatcooldown.last::%player%} and now
    if {_chatcooldown} is less than 30 seconds:
        if {chatmessage::%player%} is equal to "%message%":
            send "&e&l[&d&l✖&e&l] &r&7That's the same as your last message. Wait 30 seconds to chat the same thing."
            cancel event
            stop

    clear chat recipients
    loop all players:
        set {_sendMessage} to false
        if {hidechat::%loop-player%} is not true:
            set {_sendMessage} to true
        else if "%message%" contains "@%loop-value%":
            set {_sendMessage} to true

        if {_sendMessage} is true:
            if player has permission "owner":
                json("%loop-value%","&b&o%player's display name% &7❖||cmd:/owner||ttp:&b&lOwner %new line%&b%player%|| &7%message%")
            else if player has permission "srguardian":
                json("%loop-value%","&b%player's display name% &7●||cmd:/action %player%||ttp:&bSrGuardian %new line%&b%player%|| &7%message%")
            else if player has permission "guardian":
                json("%loop-value%","&b%player's display name% ||cmd:/action %player%||ttp:&bGuardian %new line%&b%player%||&7● &7%message%")
            else if player has permission "ancient":
                json("%loop-value%","&d⚜&9%player's display name%&d⚜ ||cmd:/action %player%||ttp:&5Ancient %new line%&5%player%||&7● &7%message%")
            else if player has permission "youtuber":
                json("%loop-value%","&c[&f►&c]&3%player's display name% ||cmd:/action %player%||ttp:&cYoutuber %new line%&7%player%||&7● &7%message%")
            else if player has permission "wanderer":
                json("%loop-value%","&3%player's display name% ||cmd:/action %player%||ttp:&3Wanderer %new line%&3%player%||&7● &7%message%")
            else if player has permission "newcomer":
                json("%loop-value%","&7%player's display name% ||cmd:/action %player%||ttp:&7Newcomer %new line%&7%player%||&7● &7%message%")
            else if player has permission "dreamer":
                json("%loop-value%","&e☆&9%player's display name%&e☆ ||cmd:/action %player%||ttp: &9Dreamer %new line%&9%player%||&7● &7%message%")

    set {chatmessage::%player%} to the message
    set {chatcooldown.last::%player%} to now
you can clear recipients instead of looping and removing, and you dont need stop after else if statements, it only runs the else part if the previous if statement was false

It doesn't work for normal chat, just the "@NAME" chat, which was one of the things really frustrating me before too x3 I did figure out why and how to fix that bit though. Just checking if a variable is not true apparently doesnt work if it's not set in the first place. so I just included these two lines and FINALLY it works!
code_language.skript:
    if {hidechat::%loop-player%} is not set:
        set {hidechat::%loop-player%} to false

I didn't know about just clearing the recipients so that's awesome to know. All I knew for sure was I couldn't just cancel it since DiscordSRV needs the event to pass. x3
Thank you so much!!! :emoji_grinning:<3