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!

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

Skript Using Metadata Tags In GUI's

Discussion in 'Tutorials' started by ZsCortzones, Mar 17, 2021.

  1. ZsCortzones

    ZsCortzones Member

    Joined:
    Feb 18, 2021
    Messages:
    19
    Likes Received:
    0
    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 (Text):
    1. command /opengui:
    2.     trigger:
    3.         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 (Text):
    1. command /opengui:
    2.     trigger:
    3.         set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
    4.         set slot 0 of metadata tag "YourGuiName" of player to (your item name) named "Your Name Here"
    5.  
    6. #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 (Text):
    1. command /opengui:
    2.     trigger:
    3.         set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
    4.         loop numbers between 0 and 44:
    5.             set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "
    6.  
    7. #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 (Text):
    1. command /opengui:
    2.     trigger:
    3.         set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
    4.         loop numbers between 0 and 44:
    5.             set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "
    6.         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 (Text):
    1. command /opengui:
    2.     trigger:
    3.         set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
    4.         loop numbers between 0 and 44:
    5.             set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "
    6.         open (metadata tag "YourGuiName" of player) to player
    7.  
    8.  
    9. on inventory click:
    10.     event-inventory = (metadata tag "YourGuiName" of player):
    11.         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 (Text):
    1. command /opengui:
    2.     trigger:
    3.         set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
    4.         loop numbers between 0 and 44:
    5.             set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "
    6.         open (metadata tag "YourGuiName" of player) to player
    7.  
    8.  
    9. on inventory click:
    10.     event-inventory = (metadata tag "YourGuiName" of player):
    11.         cancel event
    12.         index of event-slot = 22:
    13.             (your event here)
    14.             close inventory of player
    15.  
    16. #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 (Text):
    1.  
    2. command /opengui:
    3.     trigger:
    4.         set metadata tag "YourGuiName" of player to chest inventory with 5 rows named "YourGuiName"
    5.         loop numbers between 0 and 44:
    6.             set slot loop-number of metadata tag "YourGuiName" of player to white stained glass pane named " "
    7.         set slot 22 of metadata tag "YourGuiName" of player to diamond block named "&3&lInfo" and lore "&bClick for info in chat!"
    8.         open (metadata tag "YourGuiName" of player) to player
    9.  
    10.  
    11. on inventory click:
    12.     event-inventory = (metadata tag "YourGuiName" of player):
    13.         cancel event
    14.         index of event-slot = 22:
    15.             send "&3Tutorial made by &7- &bZsCortzones"
    16.             send "&3Tutorial On &7- &bMetadata Tags in GUIs"
    17.             close inventory of player
    5)
    Customize your Skript!
     
    #1 ZsCortzones, Mar 17, 2021
    Last edited: Mar 17, 2021
  2. Runakai

    Moderator Supporter

    Joined:
    Apr 27, 2018
    Messages:
    494
    Likes Received:
    31
    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
     
    • Agree Agree x 1
  3. FrostPVP™️

    FrostPVP™️ Active Member

    Joined:
    Feb 12, 2021
    Messages:
    62
    Likes Received:
    3
    OOF
     
  4. ZsCortzones

    ZsCortzones Member

    Joined:
    Feb 18, 2021
    Messages:
    19
    Likes Received:
    0
    Well excuse me for explaining what I know and trying to help others to the best of my ability
     
  5. FrostPVP™️

    FrostPVP™️ Active Member

    Joined:
    Feb 12, 2021
    Messages:
    62
    Likes Received:
    3
    its okay :emoji_slight_smile:
     
  6. Runakai

    Moderator Supporter

    Joined:
    Apr 27, 2018
    Messages:
    494
    Likes Received:
    31
    Please make sure the things you know are actually true first
     
  7. FrostPVP™️

    FrostPVP™️ Active Member

    Joined:
    Feb 12, 2021
    Messages:
    62
    Likes Received:
    3
    well since I'm a noob at skipt i thought it was good XD
     
  8. ZsCortzones

    ZsCortzones Member

    Joined:
    Feb 18, 2021
    Messages:
    19
    Likes Received:
    0
    Glad it helped you
     
  9. couger44

    Supporter

    Joined:
    Feb 19, 2017
    Messages:
    714
    Likes Received:
    31
    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.
    --- Double Post Merged, Mar 24, 2021, Original Post Date: Mar 22, 2021 ---
    "doesn't". I just realized a misspelling.
     
    • Ducky Ducky x 1

Share This Page

Loading...