Clear the chat only for players who don't have permission

  • 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.

KroterPvP

Active Member
Apr 10, 2017
178
7
18
22
Hello, I want to create a clearchat skript, but it should only clear the chat for players who haven't the permission "clearchat.prevent". The chat won't be cleared for the players with this permission.

I don't know what I'm doing wrong, but it clears the chat to all players. Also, I don't know why, but players with permission recive the clearchat message twice.

Code:
code_language.skript:
command /clearchat:
    aliases: /cc, clearc, /cchat
    trigger:
        player has permission "clearchat.use":
            loop all players:
                if loop-player has permission "clearchat.prevent":
                    add loop-player to {looped-players-with-permission}
                set {looped-players} to loop-player
                remove {looped-players-with-permission} from {looped-players}
                loop 200 times:
                    send "" to {looped-players}
                send "               &7The chat was cleared by &a%player%&7." to all players
        else if player doesn't have permission "clearchat.prevent":
            send "&cYou don't have permission to do this!"
 
You need to be using list variables - {variable::*}. Here's your code cleaned up:
code_language.skript:
command /clearchat:
    aliases: /cc, clearc, /cchat
    trigger:
        player has permission "clearchat.use":
            loop all players:
                if loop-player does not have permission "clearchat.prevent":
                    add loop-player to {players::*}
            loop 200 times:
                send "" to {players::*}
            send "               &7The chat was cleared by &a%player%&7." to all players #if you want this only sent to the players who's chat was cleared then send the message to {players::*}
        else if player doesn't have permission "clearchat.use":
            send "&cYou don't have permission to do this!"
 
You need to be using list variables - {variable::*}. Here's your code cleaned up:
code_language.skript:
command /clearchat:
    aliases: /cc, clearc, /cchat
    trigger:
        player has permission "clearchat.use":
            loop all players:
                if loop-player does not have permission "clearchat.prevent":
                    add loop-player to {players::*}
            loop 200 times:
                send "" to {players::*}
            send "               &7The chat was cleared by &a%player%&7." to all players #if you want this only sent to the players who's chat was cleared then send the message to {players::*}
        else if player doesn't have permission "clearchat.use":
            send "&cYou don't have permission to do this!"
Thanks, it actually works well!


Code:
code_language.skript:
command /clearchat:
    aliases: /cc, clearc, /cchat
    trigger:
        player has permission "clearchat.use":
            loop all players:
                if loop-player doesn't have permission "clearchat.prevent":
                    add loop-player to {players::*}
                if loop-player has permission "clearchat.prevent":
                    add loop-player to {players-with-permission::*}
                loop 200 times:
                    send "" to {players::*}
                send "               &7The chat was cleared by &a%player%&7." to {players::*}
                send "&a%player% &7has cleared the chat." to {players-with-permission::*}
        else if player doesn't have permission "clearchat.use":
            send "&cYou don't have permission to do this!"
I don't know why, but this message is sent twice:
code_language.skript:
send "&a%player% &7has cleared the chat." to {players-with-permission::*}
 
Your indentation is slightly off:
code_language.skript:
command /clearchat:
    aliases: /cc, clearc, /cchat
    trigger:
        player has permission "clearchat.use":
            loop all players:
                if loop-player doesn't have permission "clearchat.prevent":
                    add loop-player to {players::*}
                if loop-player has permission "clearchat.prevent":
                    add loop-player to {players-with-permission::*}
            loop 200 times:
                send "" to {players::*}
            send "               &7The chat was cleared by &a%player%&7." to {players::*}
            send "&a%player% &7has cleared the chat." to {players-with-permission::*}
        else if player doesn't have permission "clearchat.use":
            send "&cYou don't have permission to do this!"
[doublepost=1498151962,1498151815][/doublepost]You should probably also change the lists to local variables so that they're deleted after the event or else it will save the players you add to this lists every time. ex) {_players::*}
 
Now the messages are sent 2 times, and I don't know why...
code_language.skript:
            send "               &7The chat was cleared by &a%player%&7." to {players::*}
            send "&a%player% &7has cleared the chat." to {players-with-permission::*}
[doublepost=1498152249,1498152101][/doublepost]I've fixed it making it wait to send the messages 0.5 seconds
code_language.skript:
command /clearchat:
    aliases: /cc, clearc, /cchat
    trigger:
        player has permission "clearchat.use":
            loop all players:
                if loop-player doesn't have permission "clearchat.prevent":
                    add loop-player to {_players::*}
                if loop-player has permission "clearchat.prevent":
                    add loop-player to {_players-with-permission::*}
            loop 200 times:
                send "" to {_players::*}
            wait 0.5 seconds
            send "               &7The chat was cleared by &a%player%&7." to {_players::*}
            send "&a%player% &7has cleared the chat." to {_players-with-permission::*}
        else if player doesn't have permission "clearchat.use":
            send "&cYou don't have permission to do this!"
 
Status
Not open for further replies.