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 Feb 23, 2017 · 5 revisions

About:

GUI Manager is a system to help you to make your GUIs easily, making automatically to handle any possible way the player has to get the item out.

Syntax:

Open inventory

``` #Effect open (virtual %inventory type% inventory [with size %integer%] [(named|with (name|title)) %string%]) to %players%

#Only the expression between parentheses is from TuSKe, which returns a blank inventory. #The rest is just the effect from vanilla Skript.

</p></details>
<details><summary>Create a GUI</summary>
<p>

#Effects (format|create|make) [a] gui slot %integers% of %players% with %item stack% [to [do] nothing]

(format|create|make) [a] gui slot %integers% of %players% with %item stack% to close [(using|with) %click action% [(button|click|action)]]

(format|create|make) [a] gui slot %integers% of %players% with %item stack% to [close then] (run|exe[cute]) %sender% command %string% [with permission %string%] [(using|with) %click action% [(button|click|action)]] [(using|with) cursor [item] %item stack%]

(format|create|make) [a] gui slot %integers% of %players% with %item stack% to [close then] (run|exe[cute]) function %function% [(using|with) %click action% [(button|click|action)]] [(using|with) cursor [item] %item stack%]

(format|create|make) [a] gui slot %integers% of %players% with %item stack% to (run|exe[cute]) [gui [click]] event

<p></details>
<details><summary>Remove a GUI</summary>
<p>

#Effects (unformat|remove) [the] gui slot %integers% of %players%

(unformat|remove) [all] [the] gui slots of %players%

<p></details>
<details><summary>Conditions</summary>
<p>

%player% has [a] gui %player% does(n't| not) have [a] gui

slot %number% of %player% is [a] gui slot %number% of %player% is(n't| not) [a] gui

<p></details>

**What the effects do**:

There is 4 types of actions: `do nothing` (aka as `unbreakable` from SkQuery), `run command`, `run function` and `run event`.

The first 3 types have an option to close the GUI when you click on it, just include the `to close`. And it also has an option to only do the action with certain click type, just include the `using %clicktype%`.
Possible click types:
<details><summary>Mirreski's fork (Skript v2.2-8b)</summary>
<p>

left right shift left shift right double click middle number key drop control drop

</p></details>
<details><summary>Bensku's fork (Most used one for 1.9+, also the type is called `click action` in this fork)</summary>
<p>

left mouse button right mouse button left mouse button with shift right mouse button with shift double click using mouse middle mouse button number key drop key drop key with control

</p></details>

The `run command` and `run function` have a possibility to only do the action if the the player clicks on it using a specific item in his cursor.
Just include the `(using|with) cursor [item] %itemstack%`.

`Run command` allows you to run a command when a player clicks on it, you can choose between `console` and `player` for the `sender`, you also have `with permission %string%` and it will make the player execute the command with given permission (the permission is gone after the command).

`Run function` allows you to run a function when a player clicks on it, the format is just the same as calling a simple function in Skript `<function's name>(<given paremeter's if any>)`.

The last one, `Run event`, is just in case you want to execute more codes and still want your gui be safe against stole items. This one doesn't have any detaills and it will run an event **only when click on gui slots that uses this effect**:
<details><summary>Event</summary>
<p>

[on] gui (action|click)

#Values: player : the player who clicked on item.

event-inventory : The inventory (can only be the top inventory until this moment)

event-number : The slot number

event-item : the item in cursor of the player #Note: it isn't the item in the slot, is the cursor. If you want the item in slot, use the two values above: 'slot event-number of event-inventory'

event-type : the click type (left, right ...) #In case you have Bensku's fork, is prefered that you use 'event-string', which returns the same thing but in string form.

</p></details>

**Basic structure**:

To make a gui, you just need two simple steps:
* Use any effect that opens an inventory.
* Use any of effects above to create a gui.

That's a basic example of what your code will need to be.

**Examples**:

<details><summary>Testing all effects</summary>
<p>

command /gui: trigger: if sender is console: broadcast "This was executed by console!" stop if player has permission "": send "Player executed this command with permission """"" wait a tick if player doesn't have permission "*": send "Player doesn't have that permission anymore." else: send "Well, player still has this permission, but maybe is he an op?" else: send "Player execute this command without permission"

command /guiExample: trigger: open virtual chest inventory to player format gui slot 0 of player with stone named "It won't do anything" format gui slot 1 of player with stone named "It will just close" to close format gui slot 2 of player with stone named "It will just close but only with pressing a number key" to close using number key format gui slot 3 of player with stone named "It will make the player execute a command, but he might not have permission" to run player command "/gui" format gui slot 4 of player with stone named "It will make the player execute a command with """" permission" to run player command "/gui" with permission "" format gui slot 5 of player with stone named "It will make the console execute a command" to run console command "/gui" format gui slot 6 of player with stone named "It will run the function doSomething()" to run function doSomething() format gui slot 7 of player with stone named "It will close and then run the function doSomething()" to close then run function doSomething() format gui slot 8 of player with stone named "It will run doSomething() if you click on it with a stone" to run function doSomething() with cursor stone format gui slot 9 of player with stone named "It will run the gui event" to run gui event

function doSomething(i: int = 0): #TuSKe will run this function even if it was loaded after the command above. Need 1.7.2+ for it. broadcast "And it did"

on gui click: send "It was executed in a separated event"

</p></details>
<details><summary>Multi-action example</summary>
<p>

function changeName(p: Player, clicktype: String): set {_number} to name of slot 4 of {_p}'s current inventory parsed as number #Requires SkQuery or Bensku's fork if {_clicktype} is "left": remove 1 from {_number} else if {_clicktype} is "shift left": remove 100 from {_number} else if {_clicktype} is "right": add 1 to {_number} else if {_clicktype} is "shift right": add 100 to {_number} set name of slot 4 of {_p}'s current inventory to "%{_number}%"

command /multiactionExample: trigger: open virtual dispenser inventory named "Multi-action example" to player set {_item} to diamond named "1" set line 1 of lore of {_item} to "&7Left click: remove 1" set line 2 of lore of {_item} to "&7Shift left click: remove 100" set line 3 of lore of {_item} to "&7Right click: add 1" set line 4 of lore of {_item} to "&7Shift right click: add 100" format gui slot 4 of player with {_item} to run function changeName(player, "left") with "left" click format gui slot 4 of player with {_item} to run function changeName(player, "shift left") with "shift left" click format gui slot 4 of player with {_item} to run function changeName(player, "right") with "right" click format gui slot 4 of player with {_item} to run function changeName(player, "shift right") with "shift right" click

<p></details>
<details><summary>Multi-pages gui</summary>
<p>

function openMenu(p: Player, type: String): if {_type} is "page 1": open virtual chest inventory with size 1 named "Page 1" to {_p} make a gui slot 0 of {_p} with stone named "Go to page 2" to run function openMeny({_p}, "page 2") else if {_type} is "page 2": open virtual chest inventory with size 1 named "Page 2" to {_p} make a gui slot 0 of {_p} with stone named "Go to page 3" to run function openMeny({_p}, "page 3") #And so on until ends of page... else if {_type} is "page 3": open virtual chest inventory with size 1 named "Page 3" to {_p} make a gui slot 0 of {_p} with stone named "Go back to page 1" to run function openMeny({_p}, "page 1")

</p></details>

**Things you should know**:

  * If you want to only change the item after already formatted a slot, you don't need to format it again, just use any expression to change the slot of a inventory, like `set slot 0 of player's current inventory to {_newItem}`.
  * If you format the inventory with an `air` item, it will make a locked slot. The player can't place any items in that slot.
  * You can format the same slot with more than one action, like to run a command when using the left click and a function when using the right click.
  * In `gui click` event, you will need to check `the name of event-inventory is the gui name that you want`, since more scripts can have this event.
  * If you use `uncancel event` in `gui click` event, it will allow the player to remove the item and it will lock the slot after that (because of reason above), so you can just use `unformat the gui event-number of player` if you don't want it to be locked.
  * Starting from `1.7.2`, you can use functions that isn't loaded yet or is below the code, TuSKe will get that function when the gui is opened, but if it couldn't find any function, it won't do anything obviously.
  
Thank's for all, if you found something wrong or have a suggestion/example to give, just contact me somewhere else and I will be glad.
Clone this wiki locally