LoopChests Skript

Discussion in 'Skript' started by Stoian, Jan 9, 2020.

  1. Hello. I want to make a LoopChests plugin and I don't know how to do it actually... Every 3 hours, to spawn in the world how many chests I set with the command, at that location. And in that chests to be items that I have in inventory and set them with a command. Please don't hate, I'm at the beginning and I really need it.
     
  2. you will need skript-json addon so you can store inventories in one variable

    I have this code snippet from somewhere, I think skript discord, it is not made by me, but you should find it very useful for what you are making:

    Code (Text):

    function jsonSerializeInventoryContents(inventory: inventory) :: String:
        set {_size} to {_inventory}'s amount of rows * 9
        set {_c} to 0
        loop {_size} times:
            add slot {_c} of {_inventory} to {_items::*}
            add 1 to {_c}
        if "%{_inventory}%" is not "inventory of %{_none}%":
            loop 5 times:
                set {_i} to slot {_c} of {_inventory}
                if "%{_i}%" is "%{_none}%":
                    add air to {_items::*}
                else:
                    add slot {_c} of {_inventory} to {_items::*}
                add 1 to {_c}
                delete {_i}
        return {_items::*}'s serialized json form

    function jsonSetSerializedInventoryContents(inventory: inventory, json: string, includeArmor: boolean):
        map json {_json} to {_items::*}
        set {_c} to 1
        loop ({_inventory}'s amount of rows * 9) times:
            set slot {_c}-1 of {_inventory} to {_items::%{_c}%}
            add 1 to {_c}
        if "%{_inventory}%" is not "inventory of %{_none}%":
            if {_includeArmor} is true:
                loop 5 times:
                    set slot {_c}-1 of {_inventory} to {_items::%{_c}%}
                    add 1 to {_c}
     
  3. Thanks, the code works. But I don't know how to use command on skript-json...How to set chests and other things?
     
  4. Thanks, the code works. But I don't know how to use command on skript-json...How to set chests and other things?
     
  5. try
    jsonSetSerializedInventoryContents((inventory of block at {_chestlocation}), {_json})