Solved First letter in message

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

Scholler

Active Member
Aug 6, 2018
130
9
0
24
Hello, I want to get the first letter of the message.
My code now looks like this:
code_language.skript:
on chat:
    if message starts with "!":
        if player has permission "yellowchat":
            set {msg} to message
            replace all "!" with "" in {msg}
            cancel event
            loop all players:
                send "&f<%player%> &e%{msg}%" to loop-player

And it's not working when I start the message with !
I added a line so I can test when the message is not starts with !, and it always activates. Well, if you don't understand:
code_language.skript:
on chat:
    if message starts with "!":
        if player has permission "yellowchat":
            set {msg} to message
            replace all "!" with "" in {msg}
            cancel event
            loop all players:
                send "&f<%player%> &e%{msg}%" to loop-player
    else:
        send "test"
And it always sends me that test.
[doublepost=1538229006,1538228721][/doublepost]Oh wait! When the ! is the end of the message, it's working.
So when I say !asd it's not working, but it's working with asd!
weird
[doublepost=1538229093][/doublepost]Oh... Using "ends with" it's.. working..
So this code is working now:
code_language.skript:
on chat:
    if message ends with "!":
        if player has permission "yellowchat":
            set {msg} to message
            replace all "!" with "" in {msg}
            cancel event
            loop all players:
                send "&f<%player%> &e%{msg}%" to loop-player
    else:
        send "test"

But.. Why is the "starts with" not working?
 
Hello, I want to get the first letter of the message.
My code now looks like this:
code_language.skript:
on chat:
    if message starts with "!":
        if player has permission "yellowchat":
            set {msg} to message
            replace all "!" with "" in {msg}
            cancel event
            loop all players:
                send "&f<%player%> &e%{msg}%" to loop-player

And it's not working when I start the message with !
I added a line so I can test when the message is not starts with !, and it always activates. Well, if you don't understand:
code_language.skript:
on chat:
    if message starts with "!":
        if player has permission "yellowchat":
            set {msg} to message
            replace all "!" with "" in {msg}
            cancel event
            loop all players:
                send "&f<%player%> &e%{msg}%" to loop-player
    else:
        send "test"
And it always sends me that test.
[doublepost=1538229006,1538228721][/doublepost]Oh wait! When the ! is the end of the message, it's working.
So when I say !asd it's not working, but it's working with asd!
weird
[doublepost=1538229093][/doublepost]Oh... Using "ends with" it's.. working..
So this code is working now:
code_language.skript:
on chat:
    if message ends with "!":
        if player has permission "yellowchat":
            set {msg} to message
            replace all "!" with "" in {msg}
            cancel event
            loop all players:
                send "&f<%player%> &e%{msg}%" to loop-player
    else:
        send "test"

But.. Why is the "starts with" not working?
Not about the problem, but still: you change the message in an on chat event by just using set message to "" and using temporary variable {_test}, not {test} (temporary variables won't be saved and will be removed after the trigger ends)
 
Not about the problem, but still: you change the message in an on chat event by just using set message to "" and using temporary variable {_test}, not {test} (temporary variables won't be saved and will be removed after the trigger ends)
I know but I need the variables in another event.
 
I know but I need the variables in another event.
Okay but I still recommend changing the chat message with set message and if you want change the chat format as well if you want a custom chat instead of sending a message to every player, because some plugins / scripts don't want the chat to be cancelled, since they think it's cancelled when it's actually not.
 
Status
Not open for further replies.