1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Chest Refill With Skript

Discussion in 'Skript' started by CellFuzzy, Oct 5, 2022.

  1. CellFuzzy

    CellFuzzy Member

    Joined:
    Sep 28, 2022
    Messages:
    1
    Likes Received:
    0
    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 (Text):
    1. command /refill:
    2.     trigger:
    3.         set {arena.pos1} to the location at x = 104, y = 50, z = 70
    4.         set {arena.pos2} to the location at x = -64, y = 17, z = -68
    5.         loop blocks within {arena.pos1} to {arena.pos2}:
    6.             If loop-block is glass:
    7.                 set loop-block to air
    8.             If loop-block is chest:
    9.                 add 10 dirt to loop-block
    10.                 set {_chestnumber} to a random integer between 1 and 11
    11.                 send "&fINFO:&e A chest has been populated with set %{_chestnumber}%" to the console
    12.                 If {_chestnumber} is 1:
    13.                     add 5 wood to loop-block
    14.                     add 1 diamond pickaxe to loop-block
    15.                     add 1 ender pearl to loop-block
    16.                     add 23 xp bottle to loop-block
    17.                     add 5 golden apple to loop-block
    18.                     add wooden sword of sharpness 2 to loop-block
    19.                     add 1 diamond sword to loop-block
    20.                     add 1 diamond helmet of fire protection 1 to loop-block
    21.                 If {_chestnumber} is 2:
    22.                     add 10 arrow to loop-block
    23.                     add 1 iron sword to loop-block
    24.                     add 1 ender pearl to loop-block
    25.                     add 23 xp bottle to loop-block
    26.                     add 1 golden apple to loop-block
    27.                     add 1 diamond pickaxe to loop-block
    28.                     add 1 iron axe to loop-block
    29.                     add 1 ender pearl to loop-block
    30.                     add 23 xp bottle to loop-block
    31.                     add 5 golden apple to loop-block
    32.                     add 1 wooden sword of sharpness 2 to loop-block
    33.                     add 1 diamond chestplate of fire protection 1 to loop-block
    34.                 If {_chestnumber} is 3:
    35.                     add 12 arrow to loop-block
    36.                     add 1 slimeball of knockback 10 to loop-block
    37.                     add 1 ender pearl to loop-block
    38.                     add 23 xp bottle to loop-block
    39.                     add 5 golden apple to loop-block
    40.                     add 12 dirt to loop-block
    41.                     add 1 diamond sword to loop-block
    42.                     add diamond chestplate of fire protection 4 to loop-block
    43.                     add 1 bow of flame 1 to loop-block
    44.                     add 1 diamond sword to loop-block
    45.                     add 1 golden boots of fire protection 4 to loop-block
    46.                 If {_chestnumber} is 4:
    47.                     add 1 ender pearl to loop-block
    48.                     add 23 xp bottle to loop-block
    49.                     add 5 golden apple to loop-block
    50.                     add 12 dirt to loop-block
    51.                     add 1 ender pearl to loop-block
    52.                     add 16 log to loop-block
    53.                     add 23 xp bottle to loop-block
    54.                     add 1 elytra to loop-block
    55.                     add 5 golden apple to loop-block
    56.                     add 12 dirt to loop-block
    57.                     add 1 golden helmet of fire protection 4 to loop-block
    58.                 If {_chestnumber} is 5:
    59.                     add 1 lava bucket to loop-block
    60.                     add 8 cooked beef to loop-block
    61.                     add 23 xp bottle to loop-block
    62.                     add 12 dirt to loop-block
    63.                     add 1 diamond helmet of fire protection to loop-block
    64.                     add 1 golden sword of fire aspect 1 to loop-block
    65.                     add 1 diamond leggings of fire protection 4 to loop-block
    66.                 If {_chestnumber} is 6:
    67.                     add 5 golden apple to loop-block
    68.                     add 12 dirt to loop-block
    69.                     add 1 wooden sword of sharpness 2 to loop-block
    70.                     add 12 wood to loop-block
    71.                     add 10 arrow  to loop-block
    72.                     add 1 ender pearl to loop-block
    73.                     add 23 xp bottle to loop-block
    74.                     add 5 golden apple to loop-block
    75.                     add 12 dirt to loop-block
    76.                     add 1 diamond helmet of fire protection 1 to loop-block
    77.                 If {_chestnumber} is 7:
    78.                     add 1 diamond pickaxe to loop-block
    79.                     add 1 iron axe to loop-block
    80.                     add 8 log to loop-block
    81.                     add 1 iron axe to loop-block
    82.                     add 1 ender pearl to loop-block
    83.                     add 1 elytra to loop-block
    84.                     add 23 xp bottle to loop-block
    85.                     add 5 golden apple to loop-block
    86.                     add 1 wooden sword of sharpness 2 to loop-block
    87.                     add 1 diamond sword to loop-block
    88.                     add 12 arrow to loop-block
    89.                     add 1 bow to loop-block
    90.                 If {_chestnumber} is 8:
    91.                     add 1 wooden sword of sharpness 2 to loop-block
    92.                     add 1 diamond sword of fire aspect 1 to loop-block
    93.                     add 12 arrow to loop-block
    94.                     add 10 arrow to loop-block
    95.                     add 1 diamond boots of fire protection 4 to loop-block
    96.                 If {_chestnumber} is 9:
    97.                     add 1 diamond helmet of fire protection 4 to loop-block
    98.                     add 1 stone sword of fire aspect 1 to loop-block
    99.                     add 1 bow of infinity to loop-block
    100.                     add 1 golden boots of fire protection 4 to loop-block
    101.                 If {_chestnumber} is 10:
    102.                     add 1 iron block to loop-block
    103.                     add 1 stick to loop-block
    104.                     add 1 bow of flame 1 to loop-block
    105.                     add 1 arrow to loop-block
    106.                     add 12 arrow to loop-block
    107.                     add 1 elytra to loop-block
    108.                     add 1 diamond sword to loop-block
    109.                 If {_chestnumber} is 11:
    110.                     add 1 diamond sword of sharpness 1 to loop-block
    111.                     add 1 leather chestplate of fire protection 4 to loop-block
    112.                     add 8 log to loop-block
    113.                     add 1 elytra to loop-block
    --- Double Post Merged, Oct 5, 2022, Original Post Date: Oct 5, 2022 ---
    I fixed it!:
    Code (Text):
    1. command /refill:
    2.     trigger:
    3.         set {arena.pos1} to the location at x = 104, y = 50, z = 70
    4.         set {arena.pos2} to the location at x = -64, y = 17, z = -68
    5.         loop blocks within {arena.pos1} to {arena.pos2}:
    6.             if loop-block is glass:
    7.                 set loop-block to air
    8.             if loop-block is chest:
    9.                 clear loop-block's inventory
    10.                 add 10 dirt to loop-block
    11.                 set {_chestnumber} to a random integer between 1 and 11
    12.                 set {_chestloc} to location of loop-block
    13.                 send "&fINFO:&e A chest has been populated with set %{_chestnumber}% %{_chestloc}%" to the console
    14.                 if {_chestnumber} is 1:
    15.                     add 5 wood to loop-block's inventory
    16.                     add 1 diamond pickaxe to loop-block's inventory
    17.                     add 1 ender pearl to loop-block's inventory
    18.                     add 23 xp bottle to loop-block's inventory
    19.                     add 5 golden apple to loop-block's inventory
    20.                     add wooden sword of sharpness 2 to loop-block's inventory
    21.                     add 1 diamond sword to loop-block's inventory
    22.                     add 1 diamond helmet of fire protection 1 to loop-block's inventory
    23.                 if {_chestnumber} is 2:
    24.                     add 10 arrow to loop-block's inventory
    25.                     add 1 iron sword to loop-block's inventory
    26.                     add 1 ender pearl to loop-block's inventory
    27.                     add 23 xp bottle to loop-block's inventory
    28.                     add 1 golden apple to loop-block's inventory
    29.                     add 1 diamond pickaxe to loop-block's inventory
    30.                     add 1 iron axe to loop-block's inventory
    31.                     add 1 ender pearl to loop-block's inventory
    32.                     add 23 xp bottle to loop-block's inventory
    33.                     add 5 golden apple to loop-block's inventory
    34.                     add 1 wooden sword of sharpness 2 to loop-block's inventory
    35.                     add 1 diamond chestplate of fire protection 1 to loop-block's inventory
    36.                 if {_chestnumber} is 3:
    37.                     add 12 arrow to loop-block's inventory
    38.                     add 1 slimeball of knockback 10 to loop-block's inventory
    39.                     add 1 ender pearl to loop-block's inventory
    40.                     add 23 xp bottle to loop-block's inventory
    41.                     add 5 golden apple to loop-block's inventory
    42.                     add 12 dirt to loop-block's inventory
    43.                     add 1 diamond sword to loop-block's inventory
    44.                     add diamond chestplate of fire protection 4 to loop-block's inventory
    45.                     add 1 bow of flame 1 to loop-block's inventory
    46.                     add 1 diamond sword to loop-block's inventory
    47.                     add 1 golden boots of fire protection 4 to loop-block's inventory
    48.                 if {_chestnumber} is 4:
    49.                     add 1 ender pearl to loop-block's inventory
    50.                     add 23 xp bottle to loop-block's inventory
    51.                     add 5 golden apple to loop-block's inventory
    52.                     add 12 dirt to loop-block's inventory
    53.                     add 1 ender pearl to loop-block's inventory
    54.                     add 16 log to loop-block's inventory
    55.                     add 23 xp bottle to loop-block's inventory
    56.                     add 1 elytra to loop-block's inventory
    57.                     add 5 golden apple to loop-block's inventory
    58.                     add 12 dirt to loop-block's inventory
    59.                     add 1 golden helmet of fire protection 4 to loop-block
    60.                 if {_chestnumber} is 5:
    61.                     add 1 lava bucket to loop-block's inventory
    62.                     add 8 cooked beef to loop-block's inventory
    63.                     add 23 xp bottle to loop-block's inventory
    64.                     add 12 dirt to loop-block's inventory
    65.                     add 1 diamond helmet of fire protection to loop-block's inventory
    66.                     add 1 golden sword of fire aspect 1 to loop-block's inventory
    67.                     add 1 diamond leggings of fire protection 4 to loop-block's inventory
    68.                 if {_chestnumber} is 6:
    69.                     add 5 golden apple to loop-block's inventory
    70.                     add 12 dirt to loop-block's inventory
    71.                     add 1 wooden sword of sharpness 2 to loop-block's inventory
    72.                     add 12 wood to loop-block's inventory
    73.                     add 10 arrow  to loop-block's inventory
    74.                     add 1 ender pearl to loop-block's inventory
    75.                     add 23 xp bottle to loop-block's inventory
    76.                     add 5 golden apple to loop-block's inventory
    77.                     add 12 dirt to loop-block's inventory
    78.                     add 1 diamond helmet of fire protection 1 to loop-block's inventory
    79.                 if {_chestnumber} is 7:
    80.                     add 1 diamond pickaxe to loop-block's inventory
    81.                     add 1 iron axe to loop-block's inventory
    82.                     add 8 log to loop-block's inventory
    83.                     add 1 iron axe to loop-block's inventory
    84.                     add 1 ender pearl to loop-block's inventory
    85.                     add 1 elytra to loop-block's inventory
    86.                     add 23 xp bottle to loop-block's inventory
    87.                     add 5 golden apple to loop-block's inventory
    88.                     add 1 wooden sword of sharpness 2 to loop-block's inventory
    89.                     add 1 diamond sword to loop-block's inventory
    90.                     add 12 arrow to loop-block's inventory
    91.                     add 1 bow to loop-block's inventory
    92.                 if {_chestnumber} is 8:
    93.                     add 1 wooden sword of sharpness 2 to loop-block's inventory
    94.                     add 1 diamond sword of fire aspect 1 to loop-block's inventory
    95.                     add 12 arrow to loop-block's inventory
    96.                     add 10 arrow to loop-block's inventory
    97.                     add 1 diamond boots of fire protection 4 to loop-block's inventory
    98.                 if {_chestnumber} is 9:
    99.                     add 1 diamond helmet of fire protection 4 to loop-block's inventory
    100.                     add 1 stone sword of fire aspect 1 to loop-block's inventory
    101.                     add 1 bow of infinity to loop-block's inventory
    102.                     add 1 golden boots of fire protection 4 to loop-block's inventory
    103.                 if {_chestnumber} is 10:
    104.                     add 1 iron block to loop-block's inventory
    105.                     add 1 stick to loop-block's inventory
    106.                     add 1 bow of flame 1 to loop-block's inventory
    107.                     add 1 arrow to loop-block's inventory
    108.                     add 12 arrow to loop-block's inventory
    109.                     add 1 elytra to loop-block's inventory
    110.                     add 1 diamond sword to loop-block's inventory
    111.                 if {_chestnumber} is 11:
    112.                     add 1 diamond sword of sharpness 1 to loop-block's inventory
    113.                     add 1 leather chestplate of fire protection 4 to loop-block's inventory
    114.                     add 8 log to loop-block's inventory
    115.                     add 1 elytra to loop-block's inventory
    116.                    
     
  2. Pierrelasse

    Pierrelasse Active Member

    Joined:
    Apr 20, 2022
    Messages:
    111
    Likes Received:
    3
    Thats what i got
    i just copy pasted it
    Sorry if its kinda hard to understand

    Code (Text):
    1.  
    2. on rightclick on any chest or barrel:
    3.     chest_open(event-block, player)
    4.  
    5. on block break:
    6.     event is not cancelled
    7.     event-block is any chest or barrel
    8.     chest_open(event-block, player)
    9.  
    10. on block place:
    11.     add block at event-block to {bluept::skywars::chests::*}
    12.    
    13.  
    14. function chest_open(block: block, p:player):
    15.     "%{_p}'s world%" is "skywars"
    16.     set {_b} to block at {_block}
    17.     loop {bluept::skywars::chests::*}:
    18.         {_b} is loop-value
    19.         stop
    20.     add {_b} to {bluept::skywars::chests::*}
    21.     set {_block}'s inventory to air
    22.     chest_loot({_block}, {_p})
    23.  
    24. function chest_loot(block:block, p:player=""):
    25.     loop 54 times:
    26.         set {_loot} to getloot()
    27.  
    28.         if {_loot} is bow or crossbow:
    29.             set {_addarrows} to true
    30.  
    31.         set {_tag} to tag "getcolorcodeitem" of {_loot}'s nbt
    32.         if {_tag} is set:
    33.             set {_amount} to {_loot}'s item amount
    34.             set {_loot} to loot_getcolorcodeitem({_tag}, getrankcolor({_p}, true))
    35.             set {_loot} to "%{_amount}% %{_loot}%" parsed as item
    36.  
    37.         set slot loop-number -1 of {_block}'s inventory to {_loot}
    38.  
    39.     if {_addarrows} is true:
    40.         set {_item} to arrow
    41.         set {_item}'s item amount to (random integer between 2 and 32)
    42.         add {_item} to {_block}'s inventory
    43.  
    44. function ria(i:item, min:integer=1, max:integer=64) :: item:
    45.     set {_a} to random integer between {_min} and {_max}
    46.     set {_i} to "%{_a}% %{_i}%" parsed as item
    47.     return {_i}
    48.  
    49. function loot_randenchantment(i:item, type:text, min:integer=1, max:integer=2) :: item:
    50.     loop random integer between {_min} and {_max} times:
    51.         random number between 0 and 100 is more than 80
    52.         # Weapon
    53.         if {_type} is "weapon":
    54.             set {_e} to random integer between 1 and 4
    55.             if {_e} is 1:
    56.                 set {_a} to random integer between 1 and 3
    57.                 enchant {_i} with unbreaking 1 if {_a} is 1
    58.                 enchant {_i} with unbreaking 2 if {_a} is 2
    59.                 enchant {_i} with unbreaking 3 if {_a} is 3
    60.             if {_e} is 2:
    61.                 set {_a} to random integer between 1 and 3
    62.                 enchant {_i} with sharpness 1 if {_a} is 1
    63.                 enchant {_i} with sharpness 2 if {_a} is 2
    64.                 enchant {_i} with sharpness 3 if {_a} is 3
    65.             if {_e} is 3:
    66.                 enchant {_i} with knockback 1
    67.             if {_e} is 4:
    68.                 random integer between 1 and 4 is 4
    69.                 enchant {_i} with fire aspect 1
    70.  
    71.         # Armor
    72.         else if {_type} is "armor":
    73.             set {_e} to random integer between 1 and 3
    74.             if {_e} is 1:
    75.                 set {_a} to random integer between 1 and 3
    76.                 enchant {_i} with unbreaking 1 if {_a} is 1
    77.                 enchant {_i} with unbreaking 2 if {_a} is 2
    78.                 enchant {_i} with unbreaking 3 if {_a} is 3
    79.             if {_e} is 2:
    80.                 set {_a} to random integer between 1 and 4
    81.                 enchant {_i} with protection 1 if {_a} is 1
    82.                 enchant {_i} with protection 2 if {_a} is 2
    83.                 enchant {_i} with protection 3 if {_a} is 3
    84.                 enchant {_i} with protection 4 if {_a} is 4
    85.             if {_e} is 3:
    86.                 set {_a} to random integer between 1 and 2
    87.                 enchant {_i} with thorns 1 if {_a} is 1
    88.                 enchant {_i} with thorns 2 if {_a} is 2
    89.  
    90.         # Tool
    91.         else if {_type} is "tool":
    92.             set {_e} to random integer between 1 and 2
    93.             if {_e} is 1:
    94.                 set {_a} to random integer between 1 and 3
    95.                 enchant {_i} with unbreaking 1 if {_a} is 1
    96.                 enchant {_i} with unbreaking 2 if {_a} is 2
    97.                 enchant {_i} with unbreaking 3 if {_a} is 3
    98.             if {_e} is 2:
    99.                 set {_a} to random integer between 1 and 4
    100.                 enchant {_i} with efficiency 1 if {_a} is 1
    101.                 enchant {_i} with efficiency 2 if {_a} is 2
    102.                 enchant {_i} with efficiency 4 if {_a} is 3
    103.                 enchant {_i} with efficiency 5 if {_a} is 4
    104.  
    105.     if random integer between 1 and 8 is 1:
    106.         enchant {_i} with curse of vanishing
    107.  
    108.     return {_i}
    109.  
    110. function loot_getcolorcodeitem(item:text, c:text) :: item:
    111.     set {_i} to "black" if {_c} is "0"
    112.     set {_i} to "blue" if {_c} is "1"
    113.     set {_i} to "green" if {_c} is "2"
    114.     set {_i} to "cyan" if {_c} is "3"
    115.     set {_i} to "red" if {_c} is "4"
    116.     set {_i} to "purple" if {_c} is "5"
    117.     set {_i} to "orange" if {_c} is "6"
    118.     set {_i} to "light gray" if {_c} is "7"
    119.     set {_i} to "gray" if {_c} is "8"
    120.     set {_i} to "blue" if {_c} is "9"
    121.     set {_i} to "lime" if {_c} is "a"
    122.     set {_i} to "light blue" if {_c} is "b"
    123.     set {_i} to "red" if {_c} is "c"
    124.     set {_i} to "magenta" if {_c} is "d"
    125.     set {_i} to "yellow" if {_c} is "e"
    126.     set {_i} to "white" if {_c} is "f"
    127.     set {_i} to "%{_i}% %{_item}%" parsed as item
    128.     return {_i}
    129.  
    and
    Code (Text):
    1.  
    2. # Loot
    3. function getloot(type:text="mcc") :: item:
    4.     if {_type} is "default":
    5.         add ria(golden carrot, 3, 7) to {_l::*}
    6.         add ria(golden carrot, 2, 7) to {_l::*}
    7.         add ria(apple, 1, 5) to {_l::*}
    8.         add 5 cooked beef to {_l::*}
    9.         add loot_randenchantment(diamond axe, "tool", 1, 1) to {_l::*}
    10.         add loot_randenchantment(netherite axe, "tool", 1, 1) to {_l::*}
    11.         # add loot_randenchantment(diamond pickaxe, "tool", 1, 1) to {_l::*}
    12.         # add 3 sponge to {_l::*}
    13.         # add flint to {_l::*}
    14.         add ria(iron ingot, 1, 8) to {_l::*}
    15.         add ria(gold ingot, 1, 7) to {_l::*}
    16.         add ria(gold ingot, 1, 7) to {_l::*}
    17.         add ria(cobweb, 1, 9) to {_l::*}
    18.         add ria(diamond, 1, 5) to {_l::*}
    19.         add ria(diamond, 1, 5) to {_l::*}
    20.         add netherite ingot to {_l::*}  if random integer between 1 and 3 is 1
    21.         add 10 lapis lazuli to {_l::*}
    22.         add 16 experience bottle to {_l::*}
    23.         add "totem of undying" parsed as item to {_l::*} if random integer between 1 and 5 is 1
    24.         add golden apple to {_l::*}
    25.         add golden apple to {_l::*} if random integer between 1 and 2 is 1
    26.         add splash potion of strong healing to {_l::*}
    27.         add ender pearl to {_l::*}
    28.         add crossbow with nbt "{Damage:%326 - random number between 10 and 64%}" to {_l::*}
    29.         add flint and steel to {_l::*}
    30.  
    31.     set {_chance} to 70
    32.     set {_chance} to 80 if {_type} is "default"
    33.     if random number between 0 and 100 is less than {_chance}:
    34.         return random element of {_l::*}
    35.     else:
    36.         return air
    37.  
     

Share This Page

Loading...