-
Notifications
You must be signed in to change notification settings - Fork 17
Global GUIs
A global GUI is one that persists through the life of the server. That is, it is only lost once the server restarts.
A global GUI is identified by a unique identifier (text) that can be specified during the creation of a GUI. Consider the example below of a small server-wide GUI game:
on script load:
set {-gui_boss_damage} to 0
create a gui with id "game-boss fight" with a virtual dispenser inventory named "Boss Fight: Zombie":
make gui slot 4 with a zombie head named "<red>Total Damage: 0":
add a random integer between 1 and 5 to {-gui_boss_damage}
set the name of the gui clicked item to "<red>Total Damage: %{-gui_boss_damage}%"The with id "boss fight" is the crucial part here.
Any text is fine, just be sure to keep it unique.
If we want to make this game available, we need to expose it for users.
The gui with id expression can be used to obtain any GUI by its ID:
[the] gui[s] [with [the] id[entifier][s]] %strings%We can create a simple command that displays the boss fight GUI to the player:
command /bossfight:
trigger:
open the gui with the id "game-boss fight" for the playerIt is also possible to obtain and modify the ID of a GUI, using the id of gui expression:
[the] [gui] id[entifier][s] of %guis%
%guis%'[s] [gui] id[entifier][s]All existing global GUIs can be obtained through the all global guis expression:
[all [[of] the]|the] global guisFor example, we could use this expression to dynamically create a GUI to display the available GUI games:
command /games:
trigger:
create a gui with a virtual hopper inventory named "GUI Games":
loop all global guis:
if the id of the loop-gui starts with "game":
set {_id} to the id of the loop-gui
set {_name} to the last (length of {_id} - 5) characters of {_id} # remove "game-"
set {_name} to {_name} in proper case
make the next gui slot with a diamond sword named "<red>%{_name}%":
open the gui with the id {_id} for the player
open the last created gui for the player