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.

Solved Making skript choose a random block on the players y-co-ordinate that is air & in a radius of 10

Discussion in 'Skript' started by RetroGamerSP, Jul 19, 2017.

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

    RetroGamerSP Member

    Joined:
    Jul 12, 2017
    Messages:
    21
    Likes Received:
    0
    i have been trying to get this skript code working as intented for a while now

    it is meant to replace a random block in a radius of 10 of the player with a chest but only on the same y-level of the player, so if it fails to choose an air block on the same y-level as the player it should try again, but i cannot get this to work

    Code (Skript):
    1.  
    2. function chestSummon(block: location):
    3.     set block at {_block} to chest
    4.     #Here is where you add the items this is just an example
    5.     add 1 diamond sword to block at {_block}'s inventory
    6.     #Here is where you check if the chest has items
    7.     wait 1 tick
    8.     while block at {_block} is a chest:
    9.         if items in block at {_block}'s inventory isn't set:
    10.             set block at {_block} to air
    11.         wait 1 tick
    12.  
    13. function addBlocks(player: player, radius: integer):
    14.     #here you get a random block
    15.     loop blocks in radius {_radius} around {_player}:
    16.         loop-block is air
    17.         set {_1} to "%loop-block's y-coordinate%"
    18.         set {_loc1::*} to {_1} split at "."
    19.         set {_2} to "%{_player}'s y-coordinate%"
    20.         set {_loc2::*} to {_2} split at "."
    21.         {_loc1::1} = {_loc2::1}
    22.         add loop-block to {_blocks::*}
    23.     if {_blocks::*} is set:
    24.         set {_block} to a random block out of {_blocks::*}
    25.         chestSummon({_block}'s location)
    26.     else:
    27.         wait 1 tick
    28.         addBlocks({_player}, {_radius})
    29.  
    the 1st part works as intended the chest spawns with the test item in it, but the second part will only spawn the chest at the players feet and will also not detect if it is air so if your standing on a slab it replaces the slab, could i get some help fixing this please
     
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    works for me. what skript & mc version you using?
     
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    its meant to spawn in a radius of the player not just at their feet

    skript 2.2
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    for me the chest is spawning in a random location not at my feet. idk why its not working for you
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    hmmm
     
  6. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    You can try broadcasting variables to see what exactly isn't working
     
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    could it be how i am calling the function?
    Code (Skript):
    1.  
    2. on rightclick:
    3.     if player is holding torch named "&r&lSimple Flare &6(Right-Click)" with lore "&7Right-click to summon a Simple Drop Package":
    4.         chestSummon(player)
    5.         remove 1 torch named "&r&lSimple Flare &6(Right-Click)" with lore "&7Right-click to summon a Simple Drop Package" from players
    6.  
     
  8. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    shouldnt you be calling addBlocks(player, 10) which then calls chestSummon on its own
     
  9. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    another question i know how to detect if a player is in a certain region how can i also detect if a player IS NOT in a certain region?
     
  10. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
  11. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    thank you, how would i also play a sound a the chests location? so its easy to find it if in a crowded area (such as a house in a warzone)
     
  12. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
  13. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
  14. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    with skyrayfall you can:
    Code (Skript):
    1. on store:
    2.     cancel event
    however im not sure how you could do this for a specific chest becuase theres no event-block or anything to get the location of the chest
    --- Double Post Merged, Jul 19, 2017, Original Post Date: Jul 19, 2017 ---
    i guess the next best thing would to make a region around the chest and check if the player is in the region
     
Thread Status:
Not open for further replies.

Share This Page

Loading...