Solved Moving items from players inventories to chest problem

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

lohmann99

New Member
Oct 21, 2020
6
0
1
32
I Have a problem that i find very weird.

Code:
command /item_test:
    trigger:
        # Locate chest
        loop all blocks in radius 2 around player:
            if loop-block is chest:
                set {_chest} to loop-block
        
        if {_chest} is set:
            loop all items in player's inventory:
                add loop-item to {_itemlist::*}
                
            loop {_itemlist::*}:
                add loop-value to {_chest}
        else:
            message "Something went wrong, there is no chest"

in my test world i have 3 chests set up 2 double chest, and 1 single chest. They are spread about as to not interfere with the search. The skript works.... but only on one of the chests... And if i try to message the contetns of the {_itemlist::*} i just get back <none> even when the items apear in the chest as planned.
(Just to clarify, i know im copying the items at this point, its just for proof of concept)

Im stumped.
 
Can you clarify by what you mean with "only on one of the chests"? You're setting {_chest} to the last looped chest, so it's only ever going to be the chest furthest away from you. When looping the blocks, add message "%loop-block%" to see what Skript is looping through. Potentially, there could be an aliases issues where loop-block is double chest not chest which fails the if.

As for messaging {_itemlist::*} not working, that's a weird one. It might because that Skript can't serialise the item into a string so just sends <none>. What version of MC and Skript are you using?
 
Yeah thats a clarification error on my part.. the chest are far apart and i run up to each chest and test. It's suposed to just work on one chest at a time, but it only works on of of the 3 chest when i test... a double chest.

When i run it near that chest it copies yet if i run to the other chest it won't. and i dont get the else statement, so it locates the chest.

i'm running minecraft 1.16.3 on a paper-206 server and skript 2.5 with Skellet
 
Try this:
Code:
command /item_test:
    trigger:
        loop all blocks in radius 2 around player:
            if loop-block is chest:
                loop all items in player's inventory:
                    if loop-block have enough space for 1 of stone:
                        add loop-item to loop-block's inventory
                        remove loop-item from player's inventory  
        if player doesn't have enough space for 2277 of stone:
            send "Chests near are full"
            stop              
        send "Added items to chests"

or this one if you want it to add it to a list and then add it to the chest

Code:
command /item_test2:
    trigger:
        loop all items in player's inventory:
            add loop-item to {_items::*}
           
        loop all blocks in radius 2 around player:
            if loop-block is chest:
                loop {_items::*}:
                    if loop-block have enough space for 1 of stone:
                        send "%loop-value-2%" #send item
                        add loop-value-2 to loop-block's inventory
                        remove loop-value-2 from {_items::*}
                        remove loop-value-2 from player's inventory
        if player doesn't have enough space for 2277 of stone:
            send "Chests near are full"
            stop                  
       

        send "Added items to chests"
 
  • Like
Reactions: lohmann99
Try this:
Code:
command /item_test:
    trigger:
        loop all blocks in radius 2 around player:
            if loop-block is chest:
                loop all items in player's inventory:
                    if loop-block have enough space for 1 of stone:
                        add loop-item to loop-block's inventory
                        remove loop-item from player's inventory 
        if player doesn't have enough space for 2277 of stone:
            send "Chests near are full"
            stop             
        send "Added items to chests"

or this one if you want it to add it to a list and then add it to the chest

Code:
command /item_test2:
    trigger:
        loop all items in player's inventory:
            add loop-item to {_items::*}
          
        loop all blocks in radius 2 around player:
            if loop-block is chest:
                loop {_items::*}:
                    if loop-block have enough space for 1 of stone:
                        send "%loop-value-2%" #send item
                        add loop-value-2 to loop-block's inventory
                        remove loop-value-2 from {_items::*}
                        remove loop-value-2 from player's inventory
        if player doesn't have enough space for 2277 of stone:
            send "Chests near are full"
            stop                 
      

        send "Added items to chests"

This works like a charm! but i'm still utterly confused as to why my skrpit would work on one chest but not the others...

Thanks!
 
Status
Not open for further replies.