Chest Refill With Skript

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

CellFuzzy

Member
Sep 28, 2022
1
0
1
17
Hello,I am trying to learn more Skript by making a skywars-like gamemode and i tried making a command that refills the chests on executing but for some reason it executes without any errors, but the chests are still empty.I was wondering if you could help.Here is the Skript:


Code:
command /refill:
    trigger:
        set {arena.pos1} to the location at x = 104, y = 50, z = 70
        set {arena.pos2} to the location at x = -64, y = 17, z = -68
        loop blocks within {arena.pos1} to {arena.pos2}:
            If loop-block is glass:
                set loop-block to air
            If loop-block is chest:
                add 10 dirt to loop-block
                set {_chestnumber} to a random integer between 1 and 11
                send "&fINFO:&e A chest has been populated with set %{_chestnumber}%" to the console
                If {_chestnumber} is 1:
                    add 5 wood to loop-block
                    add 1 diamond pickaxe to loop-block
                    add 1 ender pearl to loop-block
                    add 23 xp bottle to loop-block
                    add 5 golden apple to loop-block
                    add wooden sword of sharpness 2 to loop-block
                    add 1 diamond sword to loop-block
                    add 1 diamond helmet of fire protection 1 to loop-block
                If {_chestnumber} is 2:
                    add 10 arrow to loop-block
                    add 1 iron sword to loop-block
                    add 1 ender pearl to loop-block
                    add 23 xp bottle to loop-block
                    add 1 golden apple to loop-block
                    add 1 diamond pickaxe to loop-block
                    add 1 iron axe to loop-block
                    add 1 ender pearl to loop-block
                    add 23 xp bottle to loop-block
                    add 5 golden apple to loop-block
                    add 1 wooden sword of sharpness 2 to loop-block
                    add 1 diamond chestplate of fire protection 1 to loop-block
                If {_chestnumber} is 3:
                    add 12 arrow to loop-block
                    add 1 slimeball of knockback 10 to loop-block
                    add 1 ender pearl to loop-block
                    add 23 xp bottle to loop-block
                    add 5 golden apple to loop-block
                    add 12 dirt to loop-block
                    add 1 diamond sword to loop-block
                    add diamond chestplate of fire protection 4 to loop-block
                    add 1 bow of flame 1 to loop-block
                    add 1 diamond sword to loop-block
                    add 1 golden boots of fire protection 4 to loop-block
                If {_chestnumber} is 4:
                    add 1 ender pearl to loop-block
                    add 23 xp bottle to loop-block
                    add 5 golden apple to loop-block
                    add 12 dirt to loop-block
                    add 1 ender pearl to loop-block
                    add 16 log to loop-block
                    add 23 xp bottle to loop-block
                    add 1 elytra to loop-block
                    add 5 golden apple to loop-block
                    add 12 dirt to loop-block
                    add 1 golden helmet of fire protection 4 to loop-block
                If {_chestnumber} is 5:
                    add 1 lava bucket to loop-block
                    add 8 cooked beef to loop-block
                    add 23 xp bottle to loop-block
                    add 12 dirt to loop-block
                    add 1 diamond helmet of fire protection to loop-block
                    add 1 golden sword of fire aspect 1 to loop-block
                    add 1 diamond leggings of fire protection 4 to loop-block
                If {_chestnumber} is 6:
                    add 5 golden apple to loop-block
                    add 12 dirt to loop-block
                    add 1 wooden sword of sharpness 2 to loop-block
                    add 12 wood to loop-block
                    add 10 arrow  to loop-block
                    add 1 ender pearl to loop-block
                    add 23 xp bottle to loop-block
                    add 5 golden apple to loop-block
                    add 12 dirt to loop-block
                    add 1 diamond helmet of fire protection 1 to loop-block
                If {_chestnumber} is 7:
                    add 1 diamond pickaxe to loop-block
                    add 1 iron axe to loop-block
                    add 8 log to loop-block
                    add 1 iron axe to loop-block
                    add 1 ender pearl to loop-block
                    add 1 elytra to loop-block
                    add 23 xp bottle to loop-block
                    add 5 golden apple to loop-block
                    add 1 wooden sword of sharpness 2 to loop-block
                    add 1 diamond sword to loop-block
                    add 12 arrow to loop-block
                    add 1 bow to loop-block
                If {_chestnumber} is 8:
                    add 1 wooden sword of sharpness 2 to loop-block
                    add 1 diamond sword of fire aspect 1 to loop-block
                    add 12 arrow to loop-block
                    add 10 arrow to loop-block
                    add 1 diamond boots of fire protection 4 to loop-block
                If {_chestnumber} is 9:
                    add 1 diamond helmet of fire protection 4 to loop-block
                    add 1 stone sword of fire aspect 1 to loop-block
                    add 1 bow of infinity to loop-block
                    add 1 golden boots of fire protection 4 to loop-block
                If {_chestnumber} is 10:
                    add 1 iron block to loop-block
                    add 1 stick to loop-block
                    add 1 bow of flame 1 to loop-block
                    add 1 arrow to loop-block
                    add 12 arrow to loop-block
                    add 1 elytra to loop-block
                    add 1 diamond sword to loop-block
                If {_chestnumber} is 11:
                    add 1 diamond sword of sharpness 1 to loop-block
                    add 1 leather chestplate of fire protection 4 to loop-block
                    add 8 log to loop-block
                    add 1 elytra to loop-block
[doublepost=1664990373,1664987357][/doublepost]I fixed it!:
Code:
command /refill:
    trigger:
        set {arena.pos1} to the location at x = 104, y = 50, z = 70
        set {arena.pos2} to the location at x = -64, y = 17, z = -68
        loop blocks within {arena.pos1} to {arena.pos2}:
            if loop-block is glass:
                set loop-block to air
            if loop-block is chest:
                clear loop-block's inventory
                add 10 dirt to loop-block
                set {_chestnumber} to a random integer between 1 and 11
                set {_chestloc} to location of loop-block
                send "&fINFO:&e A chest has been populated with set %{_chestnumber}% %{_chestloc}%" to the console
                if {_chestnumber} is 1:
                    add 5 wood to loop-block's inventory
                    add 1 diamond pickaxe to loop-block's inventory
                    add 1 ender pearl to loop-block's inventory
                    add 23 xp bottle to loop-block's inventory
                    add 5 golden apple to loop-block's inventory
                    add wooden sword of sharpness 2 to loop-block's inventory
                    add 1 diamond sword to loop-block's inventory
                    add 1 diamond helmet of fire protection 1 to loop-block's inventory
                if {_chestnumber} is 2:
                    add 10 arrow to loop-block's inventory
                    add 1 iron sword to loop-block's inventory
                    add 1 ender pearl to loop-block's inventory
                    add 23 xp bottle to loop-block's inventory
                    add 1 golden apple to loop-block's inventory
                    add 1 diamond pickaxe to loop-block's inventory
                    add 1 iron axe to loop-block's inventory
                    add 1 ender pearl to loop-block's inventory
                    add 23 xp bottle to loop-block's inventory
                    add 5 golden apple to loop-block's inventory
                    add 1 wooden sword of sharpness 2 to loop-block's inventory
                    add 1 diamond chestplate of fire protection 1 to loop-block's inventory
                if {_chestnumber} is 3:
                    add 12 arrow to loop-block's inventory
                    add 1 slimeball of knockback 10 to loop-block's inventory
                    add 1 ender pearl to loop-block's inventory
                    add 23 xp bottle to loop-block's inventory
                    add 5 golden apple to loop-block's inventory
                    add 12 dirt to loop-block's inventory
                    add 1 diamond sword to loop-block's inventory
                    add diamond chestplate of fire protection 4 to loop-block's inventory
                    add 1 bow of flame 1 to loop-block's inventory
                    add 1 diamond sword to loop-block's inventory
                    add 1 golden boots of fire protection 4 to loop-block's inventory
                if {_chestnumber} is 4:
                    add 1 ender pearl to loop-block's inventory
                    add 23 xp bottle to loop-block's inventory
                    add 5 golden apple to loop-block's inventory
                    add 12 dirt to loop-block's inventory
                    add 1 ender pearl to loop-block's inventory
                    add 16 log to loop-block's inventory
                    add 23 xp bottle to loop-block's inventory
                    add 1 elytra to loop-block's inventory
                    add 5 golden apple to loop-block's inventory
                    add 12 dirt to loop-block's inventory
                    add 1 golden helmet of fire protection 4 to loop-block
                if {_chestnumber} is 5:
                    add 1 lava bucket to loop-block's inventory
                    add 8 cooked beef to loop-block's inventory
                    add 23 xp bottle to loop-block's inventory
                    add 12 dirt to loop-block's inventory
                    add 1 diamond helmet of fire protection to loop-block's inventory
                    add 1 golden sword of fire aspect 1 to loop-block's inventory
                    add 1 diamond leggings of fire protection 4 to loop-block's inventory
                if {_chestnumber} is 6:
                    add 5 golden apple to loop-block's inventory
                    add 12 dirt to loop-block's inventory
                    add 1 wooden sword of sharpness 2 to loop-block's inventory
                    add 12 wood to loop-block's inventory
                    add 10 arrow  to loop-block's inventory
                    add 1 ender pearl to loop-block's inventory
                    add 23 xp bottle to loop-block's inventory
                    add 5 golden apple to loop-block's inventory
                    add 12 dirt to loop-block's inventory
                    add 1 diamond helmet of fire protection 1 to loop-block's inventory
                if {_chestnumber} is 7:
                    add 1 diamond pickaxe to loop-block's inventory
                    add 1 iron axe to loop-block's inventory
                    add 8 log to loop-block's inventory
                    add 1 iron axe to loop-block's inventory
                    add 1 ender pearl to loop-block's inventory
                    add 1 elytra to loop-block's inventory
                    add 23 xp bottle to loop-block's inventory
                    add 5 golden apple to loop-block's inventory
                    add 1 wooden sword of sharpness 2 to loop-block's inventory
                    add 1 diamond sword to loop-block's inventory
                    add 12 arrow to loop-block's inventory
                    add 1 bow to loop-block's inventory
                if {_chestnumber} is 8:
                    add 1 wooden sword of sharpness 2 to loop-block's inventory
                    add 1 diamond sword of fire aspect 1 to loop-block's inventory
                    add 12 arrow to loop-block's inventory
                    add 10 arrow to loop-block's inventory
                    add 1 diamond boots of fire protection 4 to loop-block's inventory
                if {_chestnumber} is 9:
                    add 1 diamond helmet of fire protection 4 to loop-block's inventory
                    add 1 stone sword of fire aspect 1 to loop-block's inventory
                    add 1 bow of infinity to loop-block's inventory
                    add 1 golden boots of fire protection 4 to loop-block's inventory
                if {_chestnumber} is 10:
                    add 1 iron block to loop-block's inventory
                    add 1 stick to loop-block's inventory
                    add 1 bow of flame 1 to loop-block's inventory
                    add 1 arrow to loop-block's inventory
                    add 12 arrow to loop-block's inventory
                    add 1 elytra to loop-block's inventory
                    add 1 diamond sword to loop-block's inventory
                if {_chestnumber} is 11:
                    add 1 diamond sword of sharpness 1 to loop-block's inventory
                    add 1 leather chestplate of fire protection 4 to loop-block's inventory
                    add 8 log to loop-block's inventory
                    add 1 elytra to loop-block's inventory
 
Thats what i got
i just copy pasted it
Sorry if its kinda hard to understand

Code:
on rightclick on any chest or barrel:
    chest_open(event-block, player)

on block break:
    event is not cancelled
    event-block is any chest or barrel
    chest_open(event-block, player)

on block place:
    add block at event-block to {bluept::skywars::chests::*}
   

function chest_open(block: block, p:player):
    "%{_p}'s world%" is "skywars"
    set {_b} to block at {_block}
    loop {bluept::skywars::chests::*}:
        {_b} is loop-value
        stop
    add {_b} to {bluept::skywars::chests::*}
    set {_block}'s inventory to air
    chest_loot({_block}, {_p})

function chest_loot(block:block, p:player=""):
    loop 54 times:
        set {_loot} to getloot()

        if {_loot} is bow or crossbow:
            set {_addarrows} to true

        set {_tag} to tag "getcolorcodeitem" of {_loot}'s nbt
        if {_tag} is set:
            set {_amount} to {_loot}'s item amount
            set {_loot} to loot_getcolorcodeitem({_tag}, getrankcolor({_p}, true))
            set {_loot} to "%{_amount}% %{_loot}%" parsed as item

        set slot loop-number -1 of {_block}'s inventory to {_loot}

    if {_addarrows} is true:
        set {_item} to arrow
        set {_item}'s item amount to (random integer between 2 and 32)
        add {_item} to {_block}'s inventory

function ria(i:item, min:integer=1, max:integer=64) :: item:
    set {_a} to random integer between {_min} and {_max}
    set {_i} to "%{_a}% %{_i}%" parsed as item
    return {_i}

function loot_randenchantment(i:item, type:text, min:integer=1, max:integer=2) :: item:
    loop random integer between {_min} and {_max} times:
        random number between 0 and 100 is more than 80
        # Weapon
        if {_type} is "weapon":
            set {_e} to random integer between 1 and 4
            if {_e} is 1:
                set {_a} to random integer between 1 and 3
                enchant {_i} with unbreaking 1 if {_a} is 1
                enchant {_i} with unbreaking 2 if {_a} is 2
                enchant {_i} with unbreaking 3 if {_a} is 3
            if {_e} is 2:
                set {_a} to random integer between 1 and 3
                enchant {_i} with sharpness 1 if {_a} is 1
                enchant {_i} with sharpness 2 if {_a} is 2
                enchant {_i} with sharpness 3 if {_a} is 3
            if {_e} is 3:
                enchant {_i} with knockback 1
            if {_e} is 4:
                random integer between 1 and 4 is 4
                enchant {_i} with fire aspect 1

        # Armor
        else if {_type} is "armor":
            set {_e} to random integer between 1 and 3
            if {_e} is 1:
                set {_a} to random integer between 1 and 3
                enchant {_i} with unbreaking 1 if {_a} is 1
                enchant {_i} with unbreaking 2 if {_a} is 2
                enchant {_i} with unbreaking 3 if {_a} is 3
            if {_e} is 2:
                set {_a} to random integer between 1 and 4
                enchant {_i} with protection 1 if {_a} is 1
                enchant {_i} with protection 2 if {_a} is 2
                enchant {_i} with protection 3 if {_a} is 3
                enchant {_i} with protection 4 if {_a} is 4
            if {_e} is 3:
                set {_a} to random integer between 1 and 2
                enchant {_i} with thorns 1 if {_a} is 1
                enchant {_i} with thorns 2 if {_a} is 2

        # Tool
        else if {_type} is "tool":
            set {_e} to random integer between 1 and 2
            if {_e} is 1:
                set {_a} to random integer between 1 and 3
                enchant {_i} with unbreaking 1 if {_a} is 1
                enchant {_i} with unbreaking 2 if {_a} is 2
                enchant {_i} with unbreaking 3 if {_a} is 3
            if {_e} is 2:
                set {_a} to random integer between 1 and 4
                enchant {_i} with efficiency 1 if {_a} is 1
                enchant {_i} with efficiency 2 if {_a} is 2
                enchant {_i} with efficiency 4 if {_a} is 3
                enchant {_i} with efficiency 5 if {_a} is 4

    if random integer between 1 and 8 is 1:
        enchant {_i} with curse of vanishing

    return {_i}

function loot_getcolorcodeitem(item:text, c:text) :: item:
    set {_i} to "black" if {_c} is "0"
    set {_i} to "blue" if {_c} is "1"
    set {_i} to "green" if {_c} is "2"
    set {_i} to "cyan" if {_c} is "3"
    set {_i} to "red" if {_c} is "4"
    set {_i} to "purple" if {_c} is "5"
    set {_i} to "orange" if {_c} is "6"
    set {_i} to "light gray" if {_c} is "7"
    set {_i} to "gray" if {_c} is "8"
    set {_i} to "blue" if {_c} is "9"
    set {_i} to "lime" if {_c} is "a"
    set {_i} to "light blue" if {_c} is "b"
    set {_i} to "red" if {_c} is "c"
    set {_i} to "magenta" if {_c} is "d"
    set {_i} to "yellow" if {_c} is "e"
    set {_i} to "white" if {_c} is "f"
    set {_i} to "%{_i}% %{_item}%" parsed as item
    return {_i}
and
Code:
# Loot
function getloot(type:text="mcc") :: item:
    if {_type} is "default":
        add ria(golden carrot, 3, 7) to {_l::*}
        add ria(golden carrot, 2, 7) to {_l::*}
        add ria(apple, 1, 5) to {_l::*}
        add 5 cooked beef to {_l::*}
        add loot_randenchantment(diamond axe, "tool", 1, 1) to {_l::*}
        add loot_randenchantment(netherite axe, "tool", 1, 1) to {_l::*}
        # add loot_randenchantment(diamond pickaxe, "tool", 1, 1) to {_l::*}
        # add 3 sponge to {_l::*}
        # add flint to {_l::*}
        add ria(iron ingot, 1, 8) to {_l::*}
        add ria(gold ingot, 1, 7) to {_l::*}
        add ria(gold ingot, 1, 7) to {_l::*}
        add ria(cobweb, 1, 9) to {_l::*}
        add ria(diamond, 1, 5) to {_l::*}
        add ria(diamond, 1, 5) to {_l::*}
        add netherite ingot to {_l::*}  if random integer between 1 and 3 is 1
        add 10 lapis lazuli to {_l::*}
        add 16 experience bottle to {_l::*}
        add "totem of undying" parsed as item to {_l::*} if random integer between 1 and 5 is 1
        add golden apple to {_l::*}
        add golden apple to {_l::*} if random integer between 1 and 2 is 1
        add splash potion of strong healing to {_l::*}
        add ender pearl to {_l::*}
        add crossbow with nbt "{Damage:%326 - random number between 10 and 64%}" to {_l::*}
        add flint and steel to {_l::*}

    set {_chance} to 70
    set {_chance} to 80 if {_type} is "default"
    if random number between 0 and 100 is less than {_chance}:
        return random element of {_l::*}
    else:
        return air
 
Status
Not open for further replies.