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

Not open for further replies.
1. ### RetroGamerSP Member

Joined:
Jul 12, 2017
Messages:
21
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.
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
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

#1
2. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,183
234
works for me. what skript & mc version you using?

#2
3. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,183
234
its meant to spawn in a radius of the player not just at their feet

skript 2.2

#3
4. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,183
234
for me the chest is spawning in a random location not at my feet. idk why its not working for you

#4

Joined:
Sep 7, 2017
Messages:
2,183
234
hmmm

#5
6. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,183
234
You can try broadcasting variables to see what exactly isn't working

#6
7. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,183
234
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.

#7
8. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,183
234
shouldnt you be calling addBlocks(player, 10) which then calls chestSummon on its own

#8
9. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,183
234
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?

#9

Joined:
Sep 7, 2017
Messages:
2,183
234
#10
11. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,183
234
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)

#11

Joined:
Sep 7, 2017
Messages:
2,183
234

Joined:
Sep 7, 2017
Messages:
2,183
234
#13
14. ### ShaneBee Supporter +Addon Developer

Joined:
Sep 7, 2017
Messages:
2,183
234
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

#14
Not open for further replies.