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 Vanilla GUIs

Discussion in 'Tutorials' started by Runakai1, Mar 20, 2019.

  1. Runakai1

    Runakai1 Well-Known Member

    Apr 27, 2018
    Likes Received:
    Skript GUIs are a secure and great way to create and manage GUIs. SkQuery GUIs are not recommended as they tend to have bugs. Switching from SkQuery to Vanilla may seem a bit confusing at first but it's easier once you get them. This tutorial exists to help you getting into vanilla GUIs.

    Some things you have to consider before starting:
    On 1.14 you have to replace the "name of event-inventory" effect with
    Code (Text):
    1. event.getView().getTitle()
    if you want to use Skript-Mirror.

    LINK: https://skripttools.net/dl/skript-mirror+2.0.0-SNAPSHOT.jar

    Otherwise you can use Sk-NbeeT or SkQuery to get the Inventory Name

    You don't have to do this if you're below 1.14 Minecraft.

    Using at least Skript 2.2 is necessary for Vanilla GUIs to work. If you are on 1.8 Minecraft, use dev36

    LINK: https://github.com/SkriptLang/Skript/releases/download/dev36/Skript.jar

    • - event-item
    • - event-slot
    • - event-inventory
    • - event-click type
    • - index of event-slot
    • - event-inventory
    event-item returns the item-type. Let's say you click on a diamond sword named "&cCookieslicer".
    Code (Text):
    1. event-item
    will return
    Code (Text):
    1. diamond sword

    event-slot does not return the clicked slot as you may have thought. It returns the actual Item you click on including lore, name, nbt, enchantments and whatever.

    event-inventory returns the inventory you click in. This expression is very handy since you can get the name of the event-inventory, making distinguishes between different inventory easier. Note that the native player's inventory also has a name. We will get to that later on how to prevent the
    Code (Text):
    1. inventory click event
    to be triggered when clicking the native inventory.

    To get the slot the player clicked in as a number you have to use
    Code (Text):
    1. index of event-slot is 1,2,3,4, etc...

    event-click type. This one is pretty interesting and gives a bunch of new possibilities! You can detect how the player clicks on the item.

    The click types:
    left mouse button, left mouse button with shift, right mouse button, right mouse button with shift, window border using right mouse button, window border using left mouse button, middle mouse button, number key, double click using mouse, drop key, drop key with control, creative action, unknown

    Let's start with something simple. Bob wants to open a simple chest gui with 3 rows. The GUI should have the name "&bCookieGod". He wants the first slot to be a stone named "&cTest". There are 2 ways to create vanilla gui inventories.

    Possibility 1:
    Code (Text):
    1. command /bob:
    2.     trigger:
    3.         open chest inventory with 3 rows named "&bCookieGod" to player
    4.         set slot 1 of player's current inventory to stone named "&cHello"
    Possibility 2:
    Code (Text):
    1. command /bob:
    2.     trigger:
    3.         set {_inventory} to chest inventory with 3 rows named "&bCookieGod"
    4.         set slot 1 of {_inventory} to stone named "&cTest"
    5.         open {_inventory} to player
    Bob clicks on the stone but he is able to pick it up. Bob is sad. Bob didn't want that. Bob knows how to fix that. Bob is using the inventory click event!

    Bob doesn't want his players to be able to steal his worthy stone. What does Bob do now? He uses the inventory click event and cancels it!

    Code (Text):
    1. command /bob:
    2.     trigger:
    3.         open chest inventory with 3 rows named "&bCookieGod" to player
    4.         set slot 1 of player's current inventory to stone named "&cHello"
    5. on inventory click:
    6.     if name of event-inventory is "&bCookieGod":
    7.         if event-slot is stone named "&cTest":
    8.             cancel event
    9.             send "You are not allowed to steal my stone!"
    The Inventory click event gets triggered every time you click in an inventory. Let's get through it detailled:
    Someone clicks in the inventory. It checks if the name of the Inventory is "&bCookieGod". If that is true it checks if the event-slot is a stone named "&cTest". If that is true as well, the inventory click gets cancelled. It doesn't let the player pick up, move, etc. the item and then sends a message. You can add as many effects as possible since it's simple skript knowledge.

    Here is an example with many conditions. Once you understand this, you got the way of vanilla guis

    Code (Text):
    1. command testgui:
    2.     trigger:
    3.         open chest inventory with 3 rows named "Test" to player
    4.         loop 27 times:
    5.             set slot (loop-number -1) of player' current inventory to stone named "This is a Stone" with lore "Stonelore" and "Stonelore2"
    7. on inventory click:
    8.     event-inventory != player's inventory:
    9.         name of player' current inventory = "Test":
    10.             event-slot = stone:
    11.                 index of event-slot = 0:
    12.                     name of event-slot = "This is a Stone":
    13.                         event-click type = left mouse button:
    14.                             cancel event #this effect makes the item unstealable
    15.                             send "hi" to player
    16.                             remove 4 from player's balance
    17.                             set {team::%player%} to true
    18.                             kick the player
    19.                             #do stuff
    the only new thing in here is event-inventory != player's inventory. This basically checks if the GUI you click in is the inventory you just opened. Make sure to include this condition all the time if you don't want the player's inventory to be involved in all of this. Otherwise you might have difficulties figuring out why your code get's executed in the player's inventory as well

    This one is for all of you who want to save an inventory within the servers memory. They get deleted after restarting the server. Since you actually need to know skript well to even know metadata exists, I will not include any information regarding the following code. If wished, comment on this thread and I will edit it. Thanks for Blue for this piece of code!

    Code (Text):
    1. command /gamble:
    2.   trigger:
    3.     loop 50 times:
    5.       set {_c} to random element out of ("&4", "&c", "&6", "&e", "&a", "&2", "&3", "&9", "&1", "&5", and "&d")
    6.       set {_} to chest inventory with 1 row named "%{_c}%&lGamble"
    7.       set {_w} to red wool, orange wool, yellow wool, light green wool, green wool, blue wool, purple wool or magenta wool
    8.       set slots (integers from 0 to 8) of {_} to {_w}      
    9.       set slot 4 of {_} to random element out of all items
    11.       set metadata "gamble-inv" of player to {_}
    12.       open (metadata "gamble-inv" of player) to player
    13.       play sound "block.note_block.pling" for player
    14.       wait 2 ticks
    15.     close player's inventory view
    16.     set {_item} to "%type of slot 4 of (metadata ""gamble-inv"" of player)%"
    17.     send "&6You got: &e&l%subtext of {_item} from indices 1 and 1 in upper case%&e&l%subtext of {_item} from indices 2 and length of {_item} in lower case%"
    18.     give (slot 4 of (metadata "gamble-inv" of player)) to player
    20. on inventory click:
    21.   cancel event if event-inventory is metadata "gamble-inv" of player
    #1 Runakai1, Mar 20, 2019
    Last edited: Oct 19, 2019 at 4:54 PM