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

I need help in making a random block generator

Discussion in 'Skript' started by Astral, May 31, 2020.

Thread Status:
Not open for further replies.
  1. Astral

    Astral Member

    Joined:
    May 31, 2020
    Messages:
    2
    Likes Received:
    0
    Hello i'm wondering how to make that when u right click a cd for example stal u get a random item except for bedrock. Can anyone help me?
     
  2. Nikd0

    Nikd0 Active Member

    Joined:
    May 30, 2020
    Messages:
    202
    Likes Received:
    19
    Do you mean something like this?
    Code (Text):
    1. on right click on polished granite:
    2.     loop all items:
    3.         add loop-item to {_loop::*}
    4.     remove bedrock from {_loop::*}
    5.     give player a random item out of {_loop::*}
    Do not mind the polished granite, used just for testing :emoji_grinning:
    --- Double Post Merged, May 31, 2020, Original Post Date: May 31, 2020 ---
    Okay... there may be a problem, it takes a bit of time to loop all items. You can do this:
    Code (Text):
    1. on load:
    2.     loop all items:
    3.         add loop-item to {allitems::*}
    4.     remove bedrock from {allitems::*}
    5. on right click on polished granite:
    6.     give player a random item out of {allitems::*}
     
  3. WeeHee

    WeeHee Active Member

    Joined:
    Mar 4, 2017
    Messages:
    108
    Likes Received:
    20
    After reloading your skript 2 times, you now have a list with 2x all items.

    This code works instantly after reload and I would recommend using it instead.
    Code (Text):
    1.  
    2. on rightclick on stone:
    3.     set {_items::*} to all items
    4.     remove bedrock from {_items::*}
    5.     give player a random item out of {_items::*}
    6.  
     
    • Like Like x 1
  4. Nikd0

    Nikd0 Active Member

    Joined:
    May 30, 2020
    Messages:
    202
    Likes Received:
    19
    Yes, but when I tested it, it took about 1 second to loop all items and give it to player. If he doesn't mind, you can sure use it.
    In my last code I forgot to add
    Code (Text):
    1. if {allitems::*} is not set:
    2.     loop all items:
    3.         #...
     
    • Like Like x 1
  5. WeeHee

    WeeHee Active Member

    Joined:
    Mar 4, 2017
    Messages:
    108
    Likes Received:
    20
    In my code I don't loop all items. It's instant and reliable.
     
    • Like Like x 1
  6. Nikd0

    Nikd0 Active Member

    Joined:
    May 30, 2020
    Messages:
    202
    Likes Received:
    19
    Oh, sorry. I can't read :emoji_neutral_face:
     
  7. Astral

    Astral Member

    Joined:
    May 31, 2020
    Messages:
    2
    Likes Received:
    0
    Hey man thanks for helping me do this, I surely dont mind about the 1 second
    --- Double Post Merged, Jun 1, 2020, Original Post Date: Jun 1, 2020 ---
    Thank you aswell
     
  8. Nikd0

    Nikd0 Active Member

    Joined:
    May 30, 2020
    Messages:
    202
    Likes Received:
    19
    Please mark the thread as solved.
     
Thread Status:
Not open for further replies.

Share This Page

Loading...