1. 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!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Snippet] Argument alias

Discussion in 'Snippets' started by EWS, Apr 15, 2018.

  1. EWS

    EWS Active Member

    Jan 26, 2017
    Likes Received:
    What does it do?
    It creates easy aliases for your commands. For example, if you need to create a weather script and want to match many words to one type of weather, this function will return:
    - the word to send to the player, for example, if you type sun it'll send sunny.
    - the weather type, in this case, clear.

    Code (Skript):
    2. function alias(t: text, a: text) :: objects:
    3.    set {_t::*} to split {_t} at "|"
    4.    if {_t::*} is not set:
    5.        set {_t::*} to {_t}
    6.    loop {_t::*}:
    7.        set {_s::*} to split loop-value at ","
    8.        loop {_s::*}:
    9.            loop-value-2 = {_a}
    10.            return {_s::1} and {_s::2}
    11.            stop loop
    12.    return false
    The usage is pretty simple:
    Code (Skript):
    2. set {_aliases::*} alias("[type you want to parse],[what to send],[word to match],[word to match]|[another type to be parsed],[what to send],[word to match],[word to match], "word to check""
    4. # {_aliases::1} = object you want to parse
    5. # {_aliases::2} = text you want to send to the player
    You can keep going forever with the 'words to match'. Just add other commas..
    [ ] are not needed.

    If you didn't get it, here it is line by line:
    Code (Skript):
    2. alias("
    3. [type to be parsed] - e.g. "creative"
    4. [word to send] - e.g. "fly 'n' duplication mode"
    5. [word to match] - e.g. "1"
    6. [word to match] - e.g. "fly plus hacks"
    7. | - another word to match
    8. [type to be parsed] - e.g. "survival"
    9. [word to send] - e.g. "just die mode"
    10. [word to match] - e.g. "0"
    11. [word to match] - e.g. "not creative"
    12. ")

    Code (Skript):
    2. command /weather [<text>]:
    3.    aliases: clima, tempo, time
    4.    permission: e.weather
    5.    permission message: {@P}
    6.    trigger:
    7.        set {_weather::*} to alias("sunny,ensolarado,clear,limpo,claro,clear|rain,chuvoso,chuva,rainy|thunder,tespestade,storm,tempest,raios", "%arg 1%")
    8.        if {_weather::*} is false: # False means that it didn't match anything.
    9.            send "&3ⒸⓂⒹ &7That weather &cdoes not exist&7."
    10.        else:
    11.            set weather to {_weather::1} parsed as weather # Parses the first returned value
    12.            send "&3ⒸⓂⒹ &7The weather has been changed to &a%{_weather::2}%&7." # Sends the second value
    As you can see, instead of a huge code, I just had the work to write down the aliases basically.

    Hope you enjoy!​

Share This Page