Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

GUI Manager

Tuke-Nuke edited this page Apr 28, 2017 · 5 revisions

GUI Manager 2

About:

GUI Manager is a simple API that allows you to easily make guis using the best performance possible. This is a second version, where brings more improvements that came from the first version, also with more new features and optimizations.

Syntaxes:

Meeting the syntaxes.

Create/Edit a gui

#Expression to create a virtual inventory
#They all do the same thing, the many syntaxes is just to fit all usages of syntax.
virtual %inventorytype% [inventory] [with size %-number%] [(named|with (name|title)) %-string%]
virtual %inventorytype% [inventory] [with %-number% row[s]] [(named|with (name|title)) %-string%]
virtual %inventorytype% [inventory] [(named|with (name|title)) %-string%] with size %-number%
virtual %inventorytype% [inventory] [(named|with (name|title)) %-string%] with %-number% row[s]

#Effects
create [a] [new] gui [[with id] %-string%] with %inventory% [and shape %-strings%]
(change|edit) %guiinventory%
Make GUI

(make|format) next gui [slot] (with|to) %itemstack%
(make|format) gui [slot] %strings/numbers% (with|to) %itemstack%
Close GUI

#This is an effect that will execute some code when a gui is closed.
run (when|while) clos(e|ing) [gui]
Change GUI Properties

#Change properties of a gui, like name and size of a inventory or reorder the items in a gui.
change gui inventory to name %string% and size %number%
change gui shape [of (items|actions)] to %strings%
change gui properties of inventory to name %string% [with %-number% row[s]] and shape [of (items|actions)] to %strings%
GUI Expressions

#General expressions
last[ly] [created] gui #Returns the last created GUI, only works per event (like a local variable)
gui [with id] %string% #Returns a gui from a given string id.

#GUI expressions (see about them later)
# Returns the clicked slot number
gui-slot 

# Returns the raw clicked slot number in both inventories.
# Numbers from 0 to <size of top inventory> means it is from the top inventory
# Numbers from <size of top inventory + 1> to higher means the slot from player's inventory.
# Not used in any expressions so far, but just an option.
gui-raw-slot 

# The hotbar slot number if the click type is 'number key'
gui-hotbar-slot

# The gui inventory involved in that action
gui-inventory

# The inventory actions, see values below.
gui-inventory-action

# The click type, see values below.
gui-click-(type|action)

# The item in cursor and the item in clicked slot, these expressions can be added/removed/setted/cleared.
gui-cursor
gui-[(clicked|current)-]item

# The slot type of slot. Not useful, just an extra value.
gui-slot-type

# The player that clicked in slot
gui-player

# A list of all players that have this gui currently open.
gui-players

# The name of inventory, basically is 'name of event-inventory'
gui-inventory-name

# The slot string ID, see more about it below
gui-slot-id

# The gui object itself, where you can change options about it.
gui
Types

gui inventory: Represents a gui inventory, this type is only used to edit an alreaddy created gui.

click (type|action): It represents a click type in a inventory click event. Starting from 1.7.4-beta/1.7.5, it uses Bensku's values too for compatibility.
Values: left [mouse button], (shift left|left mouse button with shift), right [mouse button], (shift right|right mouse button with shift), middle [mouse button], number key, double click [using mouse], drop [key], (control drop|drop key with control)

inventory action: It represents a action in a inventory click event. Starting from 1.7.4-beta/1.7.5, it uses Bensku's values too for compatibility.
Values: nothing, pickup all, pickup some, pickup half, pickup one [item], place all, place some, place one, swap with cursor, drop all [from] cursor, drop one [from] cursor, drop all [from] slot, drop one [from] slot, (move to other inventory|instant move), hotbar move and readd, (hotbar swap|swap with hotbar), clone stack, collect to cursor, unknown

slot type: It represents a type of clicked slot in a inventory click event.
Values: armor, container, crafting, fuel, outside, quickbar, result

In case you have Bensku, you need to check the values for click action and inventory action in his documentation. TuSKe only uses the same values in case you are running an old fork version.

How to make a gui

First off, this new gui system use a different format to make guis (instead of openning the inventory + formatting the slot), now you need to create a gui:

#syntax: create [a] [new] gui [[with id] %-string%] with %inventory% [and shape %-strings%]
create a gui with virtual chest with 6 rows named "&4Select the server"

Then, now comes one of new things: effects inside effects. Basically it is effects that can run codes in it, (MundoSk has some effects that uses that and they are called Scopes, for example). Using this idea, you need to use the Make GUI effect inside of it:

create a gui with virtual chest with 6 rows named "&4Select the server":
    #Syntaxes:
    # (make|format) next gui [slot] (with|to) %itemstack%
    # (make|format) gui [slot] %strings/numbers% (with|to) %itemstack%
    make next gui with diamond sword named "&4PvP server" # It will format the next free slot that is not formatted yet.
    make next gui with grass named "&aSkyBlock"

So far, it will do nothing more than just set a unstealable item (like the to do nothing from previous version). Now, instead of executing functions/commands, you can use skript code directly in it (effects inside effects inside effects? What effectception is this?). To do it, just indent the code below the effect make gui, and then it will run when the player clicks on it.

create a gui with virtual chest with 6 rows named "&4Select the server":
    make next gui with diamond sword named "&4PvP server":
        send "You will be teleported to the Pvp server"
        execute player command "/server pvp"
    make next gui with grass named "&aSkyBlock":
        send "You will be teleported to the Skyblock server"
        execute player command "/server skyblock"

Now, you only need to open a gui to player, you can use last[ly] [created] gui expression + Skript effect open inventory:

open last gui to player

And that's done, the most basic gui is that. Your code should be like:

command /servers:
    trigger:
        create a gui with virtual chest with 6 rows named "&4Select the server":
            make next gui with diamond sword named "&4PvP server":
                send "You will be teleported to the Pvp server"
                execute player command "/server pvp"
            make next gui with grass named "&aSkyBlock":
                send "You will be teleported to the Skyblock server"
                execute player command "/server skyblock"
        open last gui to player

You also have an effect to run a code when a gui closes.

create new gui with virtual chest named "Backpack":
    run when close the gui: #This code below will be executed before cleaning a gui
        set {Variable::%gui-player%::*} to all items of gui-inventory

Inventory click's event values

Now, you can use any event values even if it is not the proper event, in case you do have an addon that supports it.

create a gui with virtual chest with 6 rows named "&4Select the server":
    make next gui with diamond sword named "&4PvP server":
        send "%clicked item%" #Umbaska

But, to not let you depend them, TuSKe has it owns expressions that covers it (see the GUI Expressions above). So:

create a gui with virtual chest with 6 rows:
    make next gui with glass:
        if gui-click-action is left mouse buttom or right mouse buttom:
            set gui-clicked-item to gui-cursor-item
            set gui-cursor-item to air
            #Only these two expressions can be changed.

Global GUIs.

Now you can create global GUIs with given string ID.

on skript load:
    create a gui with id "HUB" with virtual chest with 6 rows named "&4Select the server":
        make next gui with diamond sword named "&4PvP server":
            send "You will be teleported to the Pvp server"
            execute player command "/server pvp"
        make next gui with grass named "&aSkyBlock":
            send "You will be teleported to the Skyblock server"
            execute player command "/server skyblock"

command /servers:
    trigger:
        open gui "HUB" to player

Note: All GUIs (global GUIs or local GUIs) shares the same inventory. Which means that if you change a item for one player, it will change for the others players too.

The best usage of Global GUIs are for static guis (like a server selector or gui to show values from a faction), where it doesn't have values that changes per player. But you also can create global GUIs for players, so you don't need to create them everytime, but **don't forget to remove unused guis, like when a player quits or when it is not used anymore:

on quit:
    delete gui "PlayerStats.%player%"
    #It will close the GUI if open for some player and removes it in case it is a global GUI.

Editing a GUI

In case you want to edit a gui, like reformat a slot or change a gui properties (see about it below). You can just use the effect to edit instead of create.

command /edit:
    trigger:
        edit gui "HUB":
            #It will automatically change in case it is open for some player
            make gui 0 with diamond sword named "The PvP server is down for maintence." 

String based slot

To make your guis looks simple and easy to change, now you can create GUIs using shapes. Shapes are the same concept from shaped recipes: A single char to represent a slot in a inventory. With this, is more helpfull to make custom dinamic guis

#syntax: create [a] [new] gui [[with id] %string%] with %inventory% [and shape %strings%]
add "xxxxxxxxx" to {_shape::*}
add "x--------x" to {_shape::*}
add "xxxxxxxxx" to {_shape::*}
create a gui with virtual chest and shape {_shape::*}

Imagine that the strings above are a representation of a inventory. Each slots that has char in common will be the same, so when they will be formated or a player clicks on it, it will have same item and do same action.

add "xxxxxxxxx" to {_shape::*}
add "x--------x" to {_shape::*}
add "xxxxxxxxx" to {_shape::*}
create a gui with virtual chest and shape {_shape::*}:
    make gui slot "x" with iron ingot
    make gui slot "-" with diamond

See some examples below of how it is useful.

Change GUI properties.

This effects will help you how to change the gui inventory smoothly. You need to use them in (edit|change) %gui inventory% (It doesn't has necessity to change when creating).

#Syntaxes:
change gui inventory to name %string% and size %number%
change gui shape [of (items|actions)] to %strings%
change gui properties of inventory to name %string% [with %-number% row[s]] and shape [of (items|actions)] to %strings%

The first one is to only edit the name and size (in case it is a chest type) of a gui. Nothing much to say. The second is more complex: It is used to change the positions of items, actions or both in a gui. For example, let's use this gui:

create new gui with id "Example" with virtual hopper and shape "ABCDE": #You can set the shape in a single line
    loop 9 times:
        make next gui with a random item of all items
open last gui to player

When using change gui shape of items <...>, you need tu use a shape where it will get a item from slot X and put at slot Y. So using the shape EABCD, you will note that the E was changed to the first slot and the other one were moved on slot to the right. So:

edit last gui:
    loop 10 times:
        wait 1 second
        change gui shape of items to "EABCD"

And it will make a effect as the items is moved to the right slot.

When using change gui shape of actions <...> it will only change the actions of it, so:

  • If we have a gui with two slots using shape AB and we change the shape of actions to BA, it will execute in slot 0 where it was executing in slot 1 previously.

When using change gui shape to <...> it will change both together: items and actions

For the last syntax, it basically will change both syntaxes above together.

Things you need to know:

  • You can't use event values inside the code to run when the player clicks on it.
    • To avoid that, you need to set a variable them use the variable:
      command /example <text>:
          trigger:
              set {_arg} to arg
              create new gui with virtual chest:
                  make gui slot 0 with diamond:
                      send "%{_arg}%"
    • Variables inside the code will work as "local slot variable". What does it mean? It will keep the same variable everytime the player clicks on it:
      create gui with virtual chest:
          make gui slot 0 with diamond:
              add 1 to {_count}
              send "%{_count}%"
              #It will increase everytime a player clicks on it
    • The variables is not shared between slots, unless it was formatted with same String id.
      command /example2:
          trigger:
              set {_var} to 1
              create new gui with virtual chest:
                  loop integers from 0 to 35:
                      make gui slot loop-integer with diamond:
                          add 1 to {_var}
                          send "%{_var}%"
                          #All slots will start with '1', but they will be increased individually per slot.

Code examples:

Tomorrow I will add them I said tomorrow only 😠.
Clone this wiki locally