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.

Shane's Expressions (Rainbow Text/words)(String of random Char)

Discussion in 'Snippets' started by ShaneBee, Aug 22, 2018.

  1. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    227
    So I made an expression for rainbow text/words (Uses Skript-Mirror) and also did the same thing in a function (for those that dont want to use Skript-Mirror.
    Just added an expression to create a string of random characters

    Expression:
    Code (Skript):
    1. #!EXPRESSION -- Rainbow Words / Letters in text
    2. expression rainbow [(1¦word[s]|2¦letter[s])] %string%:
    3.     get:
    4.         if parse mark is 1 or 0:
    5.             set {_col::*} to "&4" and "&c" and "&6" and "&e" and "&2" and "&a" and "&b" and "&9" and "&d" and "&5"
    6.             set {_newcol::*} to {_col::*}
    7.             set {_text::*} to expression-1 split at " "
    8.             loop {_text::*}:
    9.                 if loop-value is not " ":
    10.                     if {_newcol::*} is not set:
    11.                         set {_newcol::*} to {_col::*}
    12.                     set {_col} to first element of {_newcol::*}
    13.                     set {_newword::%loop-index%} to "%{_col}%%loop-value%"
    14.                     remove {_col} from {_newcol::*}
    15.                 else:
    16.                     set {_newword::%loop-index%} to loop-value
    17.             set {_newword} to join {_newword::*} with " "
    18.             return {_newword}
    19.         else if parse mark is 2:
    20.             set {_col::*} to "&4" and "&c" and "&6" and "&e" and "&2" and "&a" and "&b" and "&9" and "&d" and "&5"
    21.             set {_newcol::*} to {_col::*}
    22.             set {_text::*} to expression-1 split at ""
    23.             loop {_text::*}:
    24.                 if loop-value is not " ":
    25.                     if {_newcol::*} is not set:
    26.                         set {_newcol::*} to {_col::*}
    27.                     set {_col} to first element of {_newcol::*}
    28.                     set {_newword::%loop-index%} to "%{_col}%%loop-value%"
    29.                     remove {_col} from {_newcol::*}
    30.                 else:
    31.                     set {_newword::%loop-index%} to loop-value
    32.             set {_newword} to join {_newword::*} with ""
    33.             return {_newword}
    Code (Skript):
    1. #! Function for individually colored letters
    2. function rainbowLetters(t: text) :: text:
    3.     set {_col::*} to "&4" and "&c" and "&6" and "&e" and "&2" and "&a" and "&b" and "&9" and "&d" and "&5"
    4.     set {_newcol::*} to {_col::*}
    5.     set {_text::*} to {_t} split at ""
    6.     loop {_text::*}:
    7.         if loop-value is not " ":
    8.             if {_newcol::*} is not set:
    9.                 set {_newcol::*} to {_col::*}
    10.             set {_col} to first element of {_newcol::*}
    11.             set {_newword::%loop-index%} to "%{_col}%%loop-value%"
    12.             remove {_col} from {_newcol::*}
    13.         else:
    14.             set {_newword::%loop-index%} to loop-value
    15.     set {_newword} to join {_newword::*} with ""
    16.     return {_newword}
    17.  
    18. #! Function for colored words
    19. function rainbowWord(t: text) :: text:
    20.     set {_col::*} to "&4" and "&c" and "&6" and "&e" and "&2" and "&a" and "&b" and "&9" and "&d" and "&5"
    21.     set {_newcol::*} to {_col::*}
    22.     set {_text::*} to {_t} split at " "
    23.     loop {_text::*}:
    24.         if loop-value is not " ":
    25.             if {_newcol::*} is not set:
    26.                 set {_newcol::*} to {_col::*}
    27.             set {_col} to first element of {_newcol::*}
    28.             set {_newword::%loop-index%} to "%{_col}%%loop-value%"
    29.             remove {_col} from {_newcol::*}
    30.         else:
    31.             set {_newword::%loop-index%} to loop-value
    32.     set {_newword} to join {_newword::*} with " "
    33.     return {_newword}
    --- Double Post Merged, Aug 23, 2018, Original Post Date: Aug 22, 2018 ---
    Thanks to @KingAlterIV for changing one line in this.... which speeds up the expression/function quiet a bit. Based on my testing it's about 8 times faster.

    Code (Skript):
    1. #! SYNTAX
    2. random string of %integer% [capital[ized]] character[s]
    3.  
    4. #! EXPRESSION - Random string of letters
    5. expression random string of %integer% [(1¦capital[ized])] character[s]:
    6.     get:
    7.         set {_let} to "abcdefghijklmnopqrstuvwxyz"
    8.         set {_letters::*} to {_let} split at ""
    9.         loop expression-1 times:
    10.             add random element of {_letters::*} to {_newstring::*}
    11.         set {_newstring} to join {_newstring::*} by ""
    12.         if parse mark is 0:
    13.             return {_newstring}
    14.         if parse mark is 1:
    15.             return capitalized {_newstring}
    16.  
    17. #! EXAMPLE
    18. command /random <integer> [<text>]:
    19.     trigger:
    20.         if arg-2 is not set:
    21.             send "&aTEST: %random string of arg-1 characters%"
    22.         else:
    23.             if arg-2 is "cap":
    24.                 send "&aTEST: %random string of arg-1 capital characters%"
    Edited ... thanks to a suggestion by donut!
     
    #1 ShaneBee, Aug 23, 2018
    Last edited: Nov 10, 2018
    • Like Like x 2
  2. Donut

    Donut Well-Known Member

    Joined:
    Mar 27, 2017
    Messages:
    1,340
    Likes Received:
    176
    Medals:
    heres my go at it
    Code (Skript):
    1. on script load:
    2.     set {rainbow::*} to "&4" and "&c" and "&6" and "&e" and "&2" and "&a" and "&b" and "&9" and "&d" and "&5"
    3.  
    4. function rainbowLetters(t: text) :: text:
    5.     loop {_t} split at "":
    6.         if loop-value is not " ":
    7.             set {_i} to {_i} + 1 if {_i} < 10 else 1
    8.         set {_new} to join {_new} and {rainbow::%{_i}%} and loop-value
    9.     return {_new}
    10.  
    11. function rainbowWord(t: text) :: text:
    12.     loop {_t} split at " ":
    13.         set {_i} to {_i} + 1 if {_i} < 10 else 1
    14.         set {_new} to join {_new} and {rainbow::%{_i}%} and loop-value and " "
    15.     return {_new}
     
    • Like Like x 1
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    227
    Showoff :emoji_wink: jk
    --- Double Post Merged, Aug 30, 2018, Original Post Date: Aug 24, 2018 ---
    I added an expression to create a string of random characters (All capital or not)
     
  4. jaylawl

    jaylawl Active Member

    Joined:
    Jan 29, 2017
    Messages:
    173
    Likes Received:
    31
    any reason in particular you're doing this
    Code (Skript):
    1. add "a" and "b" and "c" and "d" and "e" and "f" and "g" and "h" and "i" and "j" and "k" and "l" and "m"
    instead of this:
    Code (Skript):
    1. add "a", "b",  "c", "d", "e", "f", "g", "h", "i", "j", "k", "l" and "m"
    ? :emoji_astonished:
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    227
    Well thats embarrassing :emoji_wink:
    For some dumb reason I thought you had to use the AND.... I will make the change
    Also if you are wondering why i broke it up into 2 lines, it was strictly just to make it so my skript file wasn't 4 feet wide on my screen :emoji_wink:
     
  6. jaylawl

    jaylawl Active Member

    Joined:
    Jan 29, 2017
    Messages:
    173
    Likes Received:
    31
    I know the feeling :emoji_sweat_smile: really hate long lines of code
     
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    227
    Okay, it has been updated... Thank you for pointing that out. :emoji_slight_smile: I appreciate the help
     
  8. jaylawl

    jaylawl Active Member

    Joined:
    Jan 29, 2017
    Messages:
    173
    Likes Received:
    31
    hey you're welcome. we're in this together... this mission to shorten lines of code x)
     
  9. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    227
    Haha totally. Another pair of eyes always helps
     
  10. Donut

    Donut Well-Known Member

    Joined:
    Mar 27, 2017
    Messages:
    1,340
    Likes Received:
    176
    Medals:
    btw you can do
    Code (Skript):
    1. set {_letters::*} to "abcdefghijklmnopqrstuvwxyz" split at ""
    also im sorry i dont mean to rain on your parade but i cant help myself to point out alternatives:
    Code (Skript):
    1. import:
    2.     org.apache.commons.lang3.RandomStringUtils
    3.  
    4. expression random string of %integer% [(1¦capital[ized])] character[s]:
    5.     get:
    6.         return RandomStringUtils.randomAlphabetic(expr-1) in lower case if parse mark is 0 else capitalized RandomStringUtils.randomAlphabetic(expr-1)
     
    • Like Like x 1
  11. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    227
    Hahah no need to apologize
    "set {_letters::*} to "abcdefghijklmnopqrstuvwxyz" split at """ <---WELL FRIGGEN HELL that just makes it like 1,000,000 cleaner. Thanks
    Part #2... OOF... ok So clearly you're a lot better at Java/Skript mirror than I am :emoji_wink:
     
  12. Snow-Pyon

    Snow-Pyon Well-Known Member

    Joined:
    Jan 25, 2017
    Messages:
    1,236
    Likes Received:
    176
    Medals:
    I'll also get in:
    Code (Skript):
    1. on script load:
    2.  
    3.   set {colors::*} to split "0123456789abcdef" by ""
    4.  
    5. function rainbowLetters(input: texts) :: texts:
    6.   loop {_input::*}:
    7.     set {_input} to split loop-value by ""
    8.     set {_color} to random element out of
    9.     loop {_input} split by "":
    10.       set {_color} to random element out of ({colors::*} where [input isn't {_color}]
    11.       set {_output} to join {_output}, "<%{_color}%>" and loop-value by ""
    12.     add {_output} to {_final::*}
    13.   return {_final::*}
    14.  
    It can be a lot shorter if I were to use addons such as MundoSK, skQuery or skript-mirror (I can make it a single line with skript-mirror lol) but decided to make it pure vanilla.
     
    • Like Like x 1
    • Winner Winner x 1
  13. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    227
    I like your use of "set {colors::*} to split "0123456789abcdef" by """ for the colors, very smart!

    [​IMG]
     
  14. Donut

    Donut Well-Known Member

    Joined:
    Mar 27, 2017
    Messages:
    1,340
    Likes Received:
    176
    Medals:
    thats random colors @Snow-Pyon not (cycling through) ROYGBIV
     
  15. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    227
    It could easily be re-written to just use the colors I chose to use
     
  16. Donut

    Donut Well-Known Member

    Joined:
    Mar 27, 2017
    Messages:
    1,340
    Likes Received:
    176
    Medals:
    it chooses a random color out of the colors, its doesnt cycle like mine and yours
     
  17. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    227
    RIGHT... gotcha
     

Share This Page

Loading...