Solved Random slot number

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

    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.

oeoxdd

Member
Mar 29, 2022
2
1
3
So, im trying to make a command that opens up for you a chest and i want it to choose a random slot and put in dirt in there, But it no work

script:
Code:
command /dirtchest:
    trigger:
        set {_slot} to a random integer between 0 and 25
        set {_dirt} to a random integer between 1 and 3
        set metadata tag "DIRTchest" of player to chest inventory with 3 rows named "&dDirt Chest"
        set slot {_slot} of metadata tag "DIRTchest" of player to {_dirt} dirt
        open (metadata tag "DIRTchest" of player) to player
edit: when i do the command it shows me only a empty chest with 3 rows named Dirt Chest in pink which is good but i dont see any dirt
 
So, im trying to make a command that opens up for you a chest and i want it to choose a random slot and put in dirt in there, But it no work

script:
Code:
command /dirtchest:
    trigger:
        set {_slot} to a random integer between 0 and 25
        set {_dirt} to a random integer between 1 and 3
        set metadata tag "DIRTchest" of player to chest inventory with 3 rows named "&dDirt Chest"
        set slot {_slot} of metadata tag "DIRTchest" of player to {_dirt} dirt
        open (metadata tag "DIRTchest" of player) to player
edit: when i do the command it shows me only a empty chest with 3 rows named Dirt Chest in pink which is good but i dont see any dirt
This is a vanilla gui from the tutorial on this page you just need skript to work
Code:
function gui(s: string, r: number, p: player):
    open chest inventory with {_r} rows named "%{_s}%" to {_p}
    
command /dirtchest:
    trigger:
        set {slot.%player%} to a random integer between 0 and 25
        gui("&dDirt Chest", 3, player)
        set slot {slot.%player%} of player's current inventory to dirt

on inventory click:
    #check if the clicked inventory is the one we just created
    if name of event-inventory is "&dDirt Chest":
        #cancel the clicking. This makes the Item unstealable
        cancel event
        if index of event-slot is {slot.%player%}:
            close the player's inventory #optional
            delete {slot.%player%}
            #code
 
thanks ill try it soon!

edit: i tried it and i removed alittle code because i wanted it to be stealable but the problem was only the amount of dirt, but still thanks!
 
Last edited:
  • Like
Reactions: Mich
Status
Not open for further replies.