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!

  2. LOOKING FOR A VERSION OF SKRIPT??:

    You can always check our our Wiki for downloads and any other information about Skript!

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

Solved Running multiple loops at the same time

Discussion in 'Skript' started by Fiopon, Apr 6, 2019.

Tags:
Thread Status:
Not open for further replies.
  1. F

    Fiopon Member

    Joined:
    Dec 26, 2018
    Messages:
    6
    Likes Received:
    0
    I'm making a skript that creates a gui-based slots machine. I want to be able to run the spinning animation of the 3 "reels" I have at the same time, how can I do this? Here's my code so far:

    (Code for win conditions and stuff not implemented yet)

    Code (Text):
    1. command /playslots:
    2.     permission: slots.play
    3.     permission message: {@noperm}
    4.     trigger:
    5.         if player's balance < 2000:
    6.             message "{@intro}Insufficient funds! You need %2000-player's balance% more."
    7.             stop
    8.         set {_reelitems::*} to yaml list "Reel.Items" from file "plugins/Skript/SaveFiles/Slots/Reel.yml"
    9.         set {_reelmax} to yaml value "Reel.Max" from file "plugins/Skript/SaveFiles/Slots/Reel.yml"
    10.         set {_reel1} to random integer between 1 and {_reelmax}
    11.         set {_reel2} to random integer between 1 and {_reelmax}
    12.         set {_reel3} to random integer between 1 and {_reelmax}
    13.         set {_reel1speed} to random integer between 1 and 4
    14.         set {_reel2speed} to random integer between 1 and 4
    15.         set {_reel3speed} to random integer between 1 and 4
    16.         set {_defaultwin} to random integer between 2 and 8
    17.         if player hasn't enough space for 1 stone sword:
    18.             message "{@intro}Cannot play with a full inventory!"
    19.             stop
    20.         remove 2000 from player's balance
    21.         set {slotsclosed.%player%} to false
    22.         set {slotsfinished.%player%} to false
    23.         open chest with 3 rows named "&3&lSlots Machine" to player
    24.         wait 1 tick
    25. #Blank Spaces
    26.         set slot 0 of player's current inventory to white stained glass pane named "&r"
    27.         set slot 1 of player's current inventory to white stained glass pane named "&r"
    28.         set slot 3 of player's current inventory to white stained glass pane named "&r"
    29.         set slot 5 of player's current inventory to white stained glass pane named "&r"
    30.         set slot 7 of player's current inventory to white stained glass pane named "&r"
    31.         set slot 8 of player's current inventory to white stained glass pane named "&r"
    32.         set slot 9 of player's current inventory to lime stained glass pane named "&r"
    33.         set slot 10 of player's current inventory to lime stained glass pane named "&r"
    34.         set slot 12 of player's current inventory to lime stained glass pane named "&r"
    35.         set slot 14 of player's current inventory to lime stained glass pane named "&r"
    36.         set slot 16 of player's current inventory to lime stained glass pane named "&r"
    37.         set slot 17 of player's current inventory to lime stained glass pane named "&r"
    38.         set slot 18 of player's current inventory to white stained glass pane named "&r"
    39.         set slot 19 of player's current inventory to white stained glass pane named "&r"
    40.         set slot 21 of player's current inventory to white stained glass pane named "&r"
    41.         set slot 23 of player's current inventory to white stained glass pane named "&r"
    42.         set slot 25 of player's current inventory to white stained glass pane named "&r"
    43.         set slot 26 of player's current inventory to white stained glass pane named "&r"
    44. #Setup Reels
    45.         loop 20 times:
    46.             loop {_reel1speed} times:
    47.                 wait 2 ticks
    48.                 set {_reel1} to {_reel1}-1
    49.                 if {_reel1} < 1:
    50.                     set {_reel1} to {_reelmax}
    51.                 if {_reel1} > {_reelmax}:
    52.                     set {_reel1} to 1
    53.                 set {_reel1.1} to {_reel1}-1
    54.                 set {_reel1.2} to {_reel1}+1
    55.                 if {_reel1.1} < 1:
    56.                     set {_reel1.1} to {_reelmax}
    57.                 if {_reel1.2} > {_reelmax}:
    58.                     set {_reel1.2} to 1
    59.                 if {slotsclosed.%player%} is false:
    60.                     set slot 2 of player's current inventory to {_reelitems::%{_reel1.1}%} parsed as item
    61.                     set slot 11 of player's current inventory to {_reelitems::%{_reel1}%} parsed as item
    62.                     set slot 20 of player's current inventory to {_reelitems::%{_reel1.2}%} parsed as item
    63.             loop {_reel2speed} times:
    64.                 wait 2 ticks
    65.                 set {_reel2} to {_reel2}-1
    66.                 if {_reel2} < 1:
    67.                     set {_reel2} to {_reelmax}
    68.                 if {_reel2} > {_reelmax}:
    69.                     set {_reel2} to 1
    70.                 set {_reel2.1} to {_reel2}-1
    71.                 set {_reel2.2} to {_reel2}+1
    72.                 if {_reel2.1} < 1:
    73.                     set {_reel2.1} to {_reelmax}
    74.                 if {_reel2.2} > {_reelmax}:
    75.                     set {_reel2.2} to 1
    76.                 if {slotsclosed.%player%} is false:
    77.                     set slot 4 of player's current inventory to {_reelitems::%{_reel2.1}%} parsed as item
    78.                     set slot 13 of player's current inventory to {_reelitems::%{_reel2}%} parsed as item
    79.                     set slot 22 of player's current inventory to {_reelitems::%{_reel2.2}%} parsed as item
    80.             loop {_reel3speed} times:
    81.                 wait 2 ticks
    82.                 set {_reel3} to {_reel3}-1
    83.                 if {_reel3} < 1:
    84.                     set {_reel3} to {_reelmax}
    85.                 if {_reel3} > {_reelmax}:
    86.                     set {_reel3} to 1
    87.                 set {_reel3.1} to {_reel3}-1
    88.                 set {_reel3.2} to {_reel3}+1
    89.                 if {_reel3.1} < 1:
    90.                     set {_reel3.1} to {_reelmax}
    91.                 if {_reel3.2} > {_reelmax}:
    92.                     set {_reel3.2} to 1
    93.                 if {slotsclosed.%player%} is false:
    94.                     set slot 6 of player's current inventory to {_reelitems::%{_reel3.1}%} parsed as item
    95.                     set slot 15 of player's current inventory to {_reelitems::%{_reel3}%} parsed as item
    96.                     set slot 24 of player's current inventory to {_reelitems::%{_reel3.2}%} parsed as item
    97.             if {slotsclosed.%player%} is true:
    98.                 add 2000 to player's balance
    99.                 set {slotsclosed.%player%} to false
    100.                 stop
    101.         set {slotsfinished.%player%} to true
    102.  
    103. on inventory close:
    104.     if name of player's current inventory is "&3&lSlots Machine":
    105.         if {slotsfinished.%player%} is true:
    106.             set {slotsfinished.%player%} to false
    107.             stop
    108.         message "{@intro}Please don't close your inventory while playing slots! You have been refunded."
    109.         set {slotsclosed.%player%} to true
    110.  
    111. on inventory click:
    112.     if name of player's current inventory is "&3&lSlots Machine":
    113.         cancel event
    Edit:
    A compromise that worked for me was nesting the loops in each other and speeding them up to the point where one might not notice they're not going at EXACTLY the same time.
     
    #1 Fiopon, Apr 6, 2019
    Last edited: Apr 7, 2019
Thread Status:
Not open for further replies.
Loading...