Solved Placing a chest with specified items in it

  • 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!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

RetroGamerSP

Member
Jul 12, 2017
21
0
0
28
Essentially i want to make a skript that when an item is used it will summon a chest in a 10 block radius of the player with pre specified items in it, when the items are taken out i need the chest to dissapear, currently i cannot find a way of doing any of the above

could someone please help with this
 
This should work
code_language.skript:
function chestSummon(player: player, radius: integer):
    #here you get a random block
    set {_block} to random element out of the blocks in radius 10 around {_player}
    set {_block} to chest
    #Here is where you add the items this is just an example
    set slot 3 of {_block}'s inventory to diamond sword
    #Here is where you check if the chest has items
    while {_block} is a chest:
        if items in {_block}'s inventory isn't set:
            set {_block} to air
        wait 1 tick

on rightclick:
    chestSummon(player, 10)
Please mark as solved if this fixed ur problem
This is untested!
 
Last edited by a moderator:
This should work
code_language.skript:
on rightclick:
    chestSummon(player, 10)

function chestSummon(player: player, radius: integer):
    #here i get a random block
    loop blocks in radius {_radius} around {_player}:
        if {_blocks::%loop-block%} is not set:
            set {_blocks::%loop-block%} to true
    set {_block} to a random element out of {_blocks::*}
    set {_block} to chest
    #Here is where you add the items this is just an example
    set {_items} to a random integer between 4 and 7
    loop {_items} times:
        set {_slot} to a random integer between 0 and 26
        set {_item} to random item out of {items::*}
        #this is where you set the item
        set slot {_slot} of {_block}'s inventory to {_item}
    #Checking if there is items on the chest
    while {_block} is a chest:
        loop all items in {_block}'s inventory:
            add loop-item to {_chestitems::*}
        if size of {_chestitems::*} is 0:
            set {_block} to air
        wait 1 tick


on load:
    #here is where u add the items this is totally unnecesary if you dont want this
    add 1 fishing rod to {items::*}
    add 1 bow to {items::*}
Please mark as solved if this fixed ur problem
This is untested!
when using this i get this error
https://gyazo.com/eae8f83a9ffd655884125d6526edbabb
 
This should work
code_language.skript:
function chestSummon(player: player, radius: integer):
    #here i get a random block
    loop blocks in radius {_radius} around {_player}:
        if {_blocks::%loop-block%} is not set:
            set {_blocks::%loop-block%} to true
    set {_block} to a random element out of {_blocks::*}
    set {_block} to chest
    #Here is where you add the items this is just an example
    set slot 3 of {_block}'s inventory to diamond sword
    while {_block} is a chest:
        loop all items in {_block}'s inventory:
            add loop-item to {_chestitems::*}
        if size of {_chestitems::*} is 0:
            set {_block} to air
        wait 1 tick

on rightclick:
    chestSummon(player, 10)
Please mark as solved if this fixed ur problem
This is untested!
This wont work anyways unless I'm mistaken because you're not actually choosing a random block, you're going to always be setting {_block} to true because you're only adding true to the list.

You should be setting {_blocks::%loop-block%} to loop-block's location not true

Or as pikachu pointed out in a previous post you should do this instead of loops for a random block:
code_language.skript:
set {_block} to random element out of the blocks in radius whatever around {_player}
 
This wont work anyways unless I'm mistaken because you're not actually choosing a random block, you're going to always be setting {_block} to true because you're only adding true to the list.

You should be setting {_blocks::%loop-block%} to loop-block's location not true

Or as pikachu pointed out in a previous post you should do this instead of loops for a random block:
code_language.skript:
set {_block} to random element out of the blocks in radius whatever around {_player}
Ok, is edited now ty
[doublepost=1499824714,1499824671][/doublepost]P
nvm got it
Pls mark as solved
 
no i mean i got the version XD
oh ok xD test it check the code is edited
[doublepost=1499824902,1499824781][/doublepost]
This wont work anyways unless I'm mistaken because you're not actually choosing a random block, you're going to always be setting {_block} to true because you're only adding true to the list.

You should be setting {_blocks::%loop-block%} to loop-block's location not true

Or as pikachu pointed out in a previous post you should do this instead of loops for a random block:
code_language.skript:
set {_block} to random element out of the blocks in radius whatever around {_player}
the set to true is just to be sure that none of the blocks is repeated on the list variable
 
ok no errors this time but the chest isnt being placed at all
Test this
code_language.skript:
function chestSummon(player: player):
    #here you get a random block
    set {_block} to random element out of the blocks in radius 10 around {_player}
    broadcast "%{_block}%"
    set {_block} to chest
    #Here is where you add the items this is just an example
    set slot 3 of {_block}'s inventory to diamond sword
    #Here is where you check if the chest has items
    while {_block} is a chest:
        if items in {_block}'s inventory isn't set:
            set {_block} to air
        wait 1 tick
 
on rightclick:
    chestSummon(player)
And tell me what does the broadcast say
 
Test this
code_language.skript:
function chestSummon(player: player):
    #here you get a random block
    set {_block} to random element out of the blocks in radius 10 around {_player}
    broadcast "%{_block}%"
    set {_block} to chest
    #Here is where you add the items this is just an example
    set slot 3 of {_block}'s inventory to diamond sword
    #Here is where you check if the chest has items
    while {_block} is a chest:
        if items in {_block}'s inventory isn't set:
            set {_block} to air
        wait 1 tick
 
on rightclick:
    chestSummon(player)
And tell me what does the broadcast say
doesnt say anything
 
nvm it suddenyly started broadcasting the blocks in the area
This should work
code_language.skript:
function chestSummon(player: player):
    #here you get a random block
    set {_block} to random element out of the blocks in radius 10 around {_player}
    set block at {_block} to chest
    #Here is where you add the items this is just an example
    set slot 3 of {_block}'s inventory to diamond sword
    #Here is where you check if the chest has items
    while {_block} is a chest:
        if items in {_block}'s inventory isn't set:
            set {_block} to air
        wait 1 tick
 
on rightclick:
    chestSummon(player)
[doublepost=1499825302,1499825265][/doublepost]
line 5 needs to be
code_language.skript:
set the block at {_block}'s location to a chest
Yeah i forgot to change that part
 
Status
Not open for further replies.