Skript Using Metadata Tags In GUI's

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

ZsCortzones

Member
Feb 18, 2021
32
1
8
26
Hello everyone, I recently learned how to use metadata tags inside of GUI's, and I felt like sharing it in this simple little guide. This guide is intended to be easy to use, but may have some complicated functions in it.

SkQuery may be required

1)

For the first step of this tutorial, you need to open up your writing tool of choice. This can be using Microsoft Word, Notepad, or any other interface that will allow you to type your code.

2)

For the second step of this tutorial, we will be setting up a basic gui that will open when the player runs a command. Normally we would just use "set (variable) to chest inventory," but since we are using metadata tags, we will use a code like this:
Code:
command /opengui:
    trigger:
        set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"

What we can now do is fill in the slots of the GUI with items of our choice by using lines such as this:
Code:
command /opengui:
    trigger:
        set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
        set slot 0 of metadata tag "YourGuiName" of player to (your item name) named "Your Name Here"

#note that the first slot of the GUI is "slot 0" as opposed to "slot 1"

Now, if we want to set all of the items in the GUI to the same item, we can do a line of code like this, which will set a selection of our GUI to an item of our choice. For this example I will be using white glass panes, as they make a nice background for a GUI.
Code:
command /opengui:
    trigger:
        set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
        loop numbers between 0 and 44:
            set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "

#note that if you name the glass "" it will appear as "White Stained Glass Pane." To avoid this, put a space in between the quotes like this: " "

3)
For the third step, we will be putting in the line of code to open the GUI to the player that runs the command. To do this we will put the metadata tag in parentheses like this:
Code:
command /opengui:
    trigger:
        set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
        loop numbers between 0 and 44:
            set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "
        open (metadata tag "YourGuiName" of player) to player

By doing this, when the command is run by the player, it will properly fill in the items and open the GUI to the player. Our only problem now is that the players will be able to take the items out of the GUI, which you will probably not want.

4)
For the fourth step, we will be making it so that the players are unable to take any items from the chests. This is where the metadata tags become most helpful. If we were to be using code without metadata tags, the skript will often times interfere with the player inventory and cause issues. By using our metadata tags, we avoid this issue.
Code:
command /opengui:
    trigger:
        set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
        loop numbers between 0 and 44:
            set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "
        open (metadata tag "YourGuiName" of player) to player


on inventory click:
    event-inventory = (metadata tag "YourGuiName" of player):
        cancel event

This piece of the Skript will make it so that when a player tries to pick up any item in the GUI, it will be immediately put back down. If we want to have other items do things when clicked, we will use slot events like this:

Code:
command /opengui:
    trigger:
        set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
        loop numbers between 0 and 44:
            set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "
        open (metadata tag "YourGuiName" of player) to player


on inventory click:
    event-inventory = (metadata tag "YourGuiName" of player):
        cancel event
        index of event-slot = 22:
            (your event here)
            close inventory of player

#slot 22 is the direct center of this specific GUI

To make slot 22 stand out more, we can set it to an item such as a diamond block with the name "Info." For this example I will make the block give you some basic information.

Code:
command /opengui:
    trigger:
        set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
        loop numbers between 0 and 44:
            set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "
        set slot 22 of metadata tag "YourGuiName" of player to diamond block named "&3&lInfo" and lore "&bClick for info in chat!"
        open (metadata tag "YourGuiName" of player) to player


on inventory click:
    event-inventory = (metadata tag "YourGuiName" of player):
        cancel event
        index of event-slot = 22:
            send "&3Tutorial made by &7- &bZsCortzones"
            send "&3Tutorial On &7- &bMetadata Tags in GUIs"
            close inventory of player

5)
Customize your Skript!
 
Last edited:
Not entirely sure what's the point of this. Also you don't need skquery. And all in all, this contains false information and misunderstood syntaxes
 
Not entirely sure what's the point of this. Also you don't need skquery. And all in all, this contains false information and misunderstood syntaxes
Well excuse me for explaining what I know and trying to help others to the best of my ability
 
Well... there's already a vanilla inventory tutorial where the use of MetaData is explained. It's not so difficult to learn. Just have to search.

As Runakai said, before writing a tutorial, make sure you know what you are teaching.

This does'nt mean that you can't rewrite a tutorial to help those who are joining the "community", just make sure you know what you are reporting to avoid new members getting confused.

Anyways, I hope this doesn't put you off or anything like that. It's just a tip.
[doublepost=1616575693,1616373029][/doublepost]"doesn't". I just realized a misspelling.
 
Hello everyone, I recently learned how to use metadata tags inside of GUI's, and I felt like sharing it in this simple little guide. This guide is intended to be easy to use, but may have some complicated functions in it.

SkQuery may be required

1)

For the first step of this tutorial, you need to open up your writing tool of choice. This can be using Microsoft Word, Notepad, or any other interface that will allow you to type your code.

2)

For the second step of this tutorial, we will be setting up a basic gui that will open when the player runs a command. Normally we would just use "set (variable) to chest inventory," but since we are using metadata tags, we will use a code like this:
Code:
command /opengui:
    trigger:
        set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"

What we can now do is fill in the slots of the GUI with items of our choice by using lines such as this:
Code:
command /opengui:
    trigger:
        set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
        set slot 0 of metadata tag "YourGuiName" of player to (your item name) named "Your Name Here"

#note that the first slot of the GUI is "slot 0" as opposed to "slot 1"

Now, if we want to set all of the items in the GUI to the same item, we can do a line of code like this, which will set a selection of our GUI to an item of our choice. For this example I will be using white glass panes, as they make a nice background for a GUI.
Code:
command /opengui:
    trigger:
        set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
        loop numbers between 0 and 44:
            set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "

#note that if you name the glass "" it will appear as "White Stained Glass Pane." To avoid this, put a space in between the quotes like this: " "

3)
For the third step, we will be putting in the line of code to open the GUI to the player that runs the command. To do this we will put the metadata tag in parentheses like this:
Code:
command /opengui:
    trigger:
        set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
        loop numbers between 0 and 44:
            set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "
        open (metadata tag "YourGuiName" of player) to player

By doing this, when the command is run by the player, it will properly fill in the items and open the GUI to the player. Our only problem now is that the players will be able to take the items out of the GUI, which you will probably not want.

4)
For the fourth step, we will be making it so that the players are unable to take any items from the chests. This is where the meta tags analyzer become most helpful. If we were to be using code without metadata tags, the skript will often times interfere with the player inventory and cause issues. By using our metadata tags, we avoid this issue.
Code:
command /opengui:
    trigger:
        set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
        loop numbers between 0 and 44:
            set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "
        open (metadata tag "YourGuiName" of player) to player


on inventory click:
    event-inventory = (metadata tag "YourGuiName" of player):
        cancel event

This piece of the Skript will make it so that when a player tries to pick up any item in the GUI, it will be immediately put back down. If we want to have other items do things when clicked, we will use slot events like this:

Code:
command /opengui:
    trigger:
        set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
        loop numbers between 0 and 44:
            set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "
        open (metadata tag "YourGuiName" of player) to player


on inventory click:
    event-inventory = (metadata tag "YourGuiName" of player):
        cancel event
        index of event-slot = 22:
            (your event here)
            close inventory of player

#slot 22 is the direct center of this specific GUI

To make slot 22 stand out more, we can set it to an item such as a diamond block with the name "Info." For this example I will make the block give you some basic information.

Code:
command /opengui:
    trigger:
        set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
        loop numbers between 0 and 44:
            set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "
        set slot 22 of metadata tag "YourGuiName" of player to diamond block named "&3&lInfo" and lore "&bClick for info in chat!"
        open (metadata tag "YourGuiName" of player) to player


on inventory click:
    event-inventory = (metadata tag "YourGuiName" of player):
        cancel event
        index of event-slot = 22:
            send "&3Tutorial made by &7- &bZsCortzones"
            send "&3Tutorial On &7- &bMetadata Tags in GUIs"
            close inventory of player

5)
Customize your Skript!
This guide is very helpful for meta tags. thanks for sharing with us. And don't worry about some complicated or issues.
 
Last edited: