Refill chest, barel, shulker

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

Spygain

Member
Dec 17, 2019
3
1
3
26
Minecraft version: 1.19.4
Skript version: 2..7.3

Addons used: None

Skript type : Skript refill chest

Skript description :

I recently took over my server and I needed to take a skript in hand, it's a chest refill skript, as the name suggests ^^.

However, the things I'd like to see have evolved: from now on, I'd like the skript to have a "rarity" function depending on the list, which is why I've created several lists, and if possible, I'd like the number of items in each list to be random, instead of having 1 dimaond, 2 iron ingot, I'd just like the number to be random.

And I'd also like it to be able to refill chests, barrels and shulkers.

And if there's a way to optimize the skript, I'm not against it.

Code:
# Ajout de listes d'objets avec pourcentage de chance
on load:
    delete {random.item.list1::*}
    delete {random.item.list2::*}
    delete {random.item.list3::*}
    delete {random.item.list4::*}
    delete {random.item.list5::*}
    delete {random.item.list6::*}
    delete {random.item.list7::*}
  
    add 1 diamond to {random.item.list1::*}
    add 2 iron ingot to {random.item.list1::*}
  
    add 2 leather to {random.item.list2::*}
    add 2 tnt to {random.item.list2::*}
  
    add 3 gold ingot to {random.item.list3::*}
    add 1 apple to {random.item.list3::*}
  
    add 2 bread to {random.item.list4::*}
    add 1 fishing rod to {random.item.list4::*}
  
    add 3 diamond sword to {random.item.list5::*}
    add 2 bow to {random.item.list5::*}
  
    add 3 iron sword to {random.item.list6::*}
    add 2 iron pickaxe to {random.item.list6::*}
  
    add 1 diamond block to {random.item.list7::*}
    add 2 emerald to {random.item.list7::*}

command /chest [<text>]:
    permission: chest.use
    trigger:
        if arg 1 is not set:
            message "&7&m&l---------------------------"
            message "&8[&a&lChest&8] &b➡ Commandes  :"
            message "&c● &e/chest add &7> Ajouter un coffre"
            message "&c● &e/chest remove &7> Supprimer un coffre"
            message "&c● &e/chest clear &7> Supprimer tous les coffres"
            message "&c● &e/chest refill &7> Refill les coffres"
            message "&cPour ajouter/supprimer un coffre, il faut le regarder et faire la commande"
            message "&7&m&l---------------------------"
        else:
            if arg 1 is not "add" or "remove" or "refill" or "clear":
                make player execute command "/chest"
            else:
                if arg 1 is "clear":
                    clear {Chest.location::*}
                    message "&8[&a&lChest&8] &a➡ &eVous avez supprimé tous les coffres de la liste"
                if arg 1 is "add":
                    if targeted block is a chest:
                        loop {Chest.location::*}:
                            if loop-value is location of targeted block:
                                message "&8[&a&lChest&8] &c➡ Le coffre est déjà dans la liste"
                                stop
                        add location of targeted block to {Chest.location::*}
                        message "&8[&a&lChest&8] &a➡ &eVous avez bien ajouté ce coffre, il y a maintenant &a%size of {Chest.location::*}% &ecoffres"
                    else:
                        message "&8[&a&lChest&8] &c➡ Vous devez cibler un coffre"
                if arg 1 is "remove":
                    if targeted block is a chest:
                        loop {Chest.location::*}:
                            if loop-value is location of targeted block:
                                message "&8[&a&lChest&8] &a➡ &eVous avez bien supprimé ce coffre, il y a maintenant &a%size of {Chest.location::*}% &ecoffres"
                                remove location of targeted block from {Chest.location::*}
                                stop
                        message "&8[&a&lChest&8] &c➡ Le coffre n'est pas dans la liste"
                    else:
                        message "&8[&a&lChest&8] &c➡ Vous devez cibler un coffre"
                if arg 1 is "refill":
                    loop {Chest.location::*}:
                        set {_slot::*} to ""
                        loop 27 times:
                            add loop-number to {_number::*}
                        clear inventory of block at loop-value
                        set {_nbr} to a random number between 3 and 6
                        loop {_nbr} times:
                            set {_rand} to a random integer between 1 and 100
                            set {_chosenList::*} to a random element out of {random.item.list1::*}, {random.item.list2::*}, {random.item.list3::*}, {random.item.list4::*}, {random.item.list5::*}, {random.item.list6::*}, {random.item.list7::*}
                            set {_item} to a random element out of {_chosenList::*}
                            set {_slot} to a random element out of {_number::*}
                            add {_item} to slot ({_slot} - 1) of block at loop-value-1
                        message "&8[&a&lChest&8] &a➡ &eLes &a%size of {Chest.location::*}% &e coffres ont été refill"

I hope my request is clear enough
 
  • Haha
Reactions: Shroob