gui

Functions:

create_inventory_ctr

gui.create_inventory_ctr(gui_id: string): invCtr

Name
Type
Description

gui_id

string

Unique identifier for GUI container. The inventory identifier is also based on this.

Creates a container containing inventory for different players. Returns an object invCtr .

Each player can only have one inventory in a container. In other words, the container is actually an inventory that distinguishes different players.

create_scoreboard_ctr

gui.create_scoreboard_ctr(gui_id: string): sbCtr

Name
Type
Description

gui_id

string

Unique identifier for GUI container.

Creates a container containing scoreboard for different players. Returns an object sbCtr .

Methods:

🗳️ invCtr

:create_inventory

invCtr:create_inventory(player_name: string, title: string, size: number[, storable: boolean])

Name
Type
Description

player_name

string

The player name to which this inventory belongs

title

string

Inventory title

size

number

Inventory size. It can only be a multiple of 9 and between 9 and 54.

storable

boolean

Optional. Can the inventory store items that players put in. Defaults to false.

Creates an inventory instance for a specific player, and if the player already has an instance, do nothing.

:open

invCtr:open(player_name: string)

Name
Type
Description

player_name

string

The player who is about to open this inventory

Opens inventory for a specific player.

:close

invCtr:close(player_name: string)

Name
Type
Description

player_name

string

The player who is about to close this inventory

Closes inventory for a specific player.

:set_item

invCtr:set_item(player_name: string, slot: number, item: item, on_click: function)

Name
Type
Description

player_name

string

The player name to which this inventory belongs

slot

number

Slot number, starting from 1.

item

item

Item object

on_click

function

Click callback with player_name and click_type as the argument.

Sets the item for a specific slot in the inventory and bind it to click callback.

:remove_item

invCtr:remove_item(player_name: string, slot: number)

Name
Type
Description

player_name

string

The player name to which this inventory belongs

slot

number

Slot number, starting from 1.

Removes the item for a specific slot in the inventory.

:set_slot_interact

invCtr:set_slot_interact(player_name: string, slot: number, can_put: boolean, can_take: boolean)

Name
Type
Description

player_name

string

The player name to which this inventory belongs

slot

number

Slot number, starting from 1.

can_put

boolean

Can items be placed in the slot

can_take

boolean

Can items be taken out of the slot

Sets the interactivity of inventory specific slots.

:on_open

invCtr:on_open(player_name: string, callback: function)

Name
Type
Description

player_name

string

The player name to which this inventory belongs

callback

function

Callback when opening menu with player_name as the argument.

Sets the callback function when inventory is opened.

:on_close

invCtr:on_close(player_name: string, callback: function)

Name
Type
Description

player_name

string

The player name to which this inventory belongs

callback

function

Callback when closing menu with player_name as the argument.

Sets the callback function when inventory is closed.

:animate

invCtr:animate(player_name: string, duration: number, interval: number, animation_fn: function)

Name
Type
Description

player_name

string

The player name to which this inventory belongs

duration

number

Total animation duration in tick

interval

number

Animation interval in tick

animation_fn

function

Animation callback with container, player_name and tick as the argument.

Sets animation callback for inventory.

:remove_inventory

invCtr:remove_inventory(player_name: string)

Name
Type
Description

player_name

string

The player name to which this inventory belongs

Removes specific player's inventory. This is used to clean up resources, usually called when the player leaves.

🗳️ sbCtr

:create_scoreboard

sbCtr:create_scoreboard(player_name: string, title: string)

Name
Type
Description

player_name

string

The player name to which this scoreboard belongs

title

string

Scoreboard title

Creates an scoreboard instance for a specific player, and if the player already has an instance, do nothing.

:show

sbCtr:show(player_name: string)

Name
Type
Description

player_name

string

The player who is about to show this scoreboard

Shows scoreboard for a specific player.

:hide

sbCtr:hide(player_name: string)

Name
Type
Description

player_name

string

The player who is about to hide this scoreboard

Hides scoreboard for a specific player.

:set_title

sbCtr:set_title(player_name: string, title: string)

Name
Type
Description

player_name

string

The player name to which this scoreboard belongs

title

string

Scoreboard title

Sets the new title of the scoreboard.

:set_line

sbCtr:set_line(player_name: string, line: number, text: string)

Name
Type
Description

player_name

string

The player name to which this scoreboard belongs

line

number

Line number (1-15)

text

string

Line content

Sets the line content of the scoreboard.

:set_lines

sbCtr:set_lines(player_name: string, line: number, text: string)

Name
Type
Description

player_name

string

The player name to which this scoreboard belongs

lines

table

Lines table

Sets multi line content of the scoreboard.

:clear_line

sbCtr:clear_line(player_name: string, line: number)

Name
Type
Description

player_name

string

The player name to which this scoreboard belongs

line

number

Line number (1-15)

Clears the line content of the scoreboard.

:clear_all_lines

sbCtr:clear_all_lines(player_name: string)

Name
Type
Description

player_name

string

The player name to which this scoreboard belongs

Clears all lines of the scoreboard.

:on_show

sbCtr:on_show(player_name: string, callback: function)

Name
Type
Description

player_name

string

The player name to which this scoreboard belongs

callback

function

Callback when showing scoreboard with player_name as the argument.

Sets the callback function when scoreboard is showed.

:on_hide

sbCtr:on_hide(player_name: string, callback: function)

Name
Type
Description

player_name

string

The player name to which this scoreboard belongs

callback

function

Callback when hiding scoreboard with player_name as the argument.

Sets the callback function when scoreboard is hided.

:animate

sbCtr:animate(player_name: string, duration: number, interval: number, animation_fn: function)

Name
Type
Description

player_name

string

The player name to which this scoreboard belongs

duration

number

Total animation duration in tick

interval

number

Animation interval in tick

animation_fn

function

Animation callback with container, player_name and tick as the argument.

Sets animation callback for scoreboard.

:remove_scoreboard

sbCtr:remove_scoreboard(player_name: string)

Name
Type
Description

player_name

string

The player name to which this scoreboard belongs

Removes specific player's scoreboard. This is used to clean up resources, usually called when the player leaves.

Example:

-- Create three inventory containers
local container1 = gui.create_container("test_gui1")
local container2 = gui.create_container("test_gui2")
local container3 = gui.create_container("test_gui3")

-- Wool colors
local wool_colors = {
    "WHITE_WOOL", "ORANGE_WOOL", "MAGENTA_WOOL", "LIGHT_BLUE_WOOL",
    "YELLOW_WOOL", "LIME_WOOL", "PINK_WOOL", "GRAY_WOOL",
    "LIGHT_GRAY_WOOL", "CYAN_WOOL", "PURPLE_WOOL", "BLUE_WOOL",
    "BROWN_WOOL", "GREEN_WOOL", "RED_WOOL", "BLACK_WOOL"
}

-- Colored wool wave animation, each slot has a phase difference, changing from left to right.
-- This is just a example. You can implement more complex animations if you like.
local function wool_wave_animation(container, player_name)
    local slots = {4, 5, 6, 7}
    local wave_length = #slots
    local color_count = #wool_colors

    container:animate(player_name, 200, 2, function(self, player, tick)
        for i, slot in ipairs(slots) do
            local color_index = ((tick - (i - 1) * 2) % color_count) + 1
            local wool_name = wool_colors[color_index]
            local item = items.create_custom(
                wool_name,
                "§fColored Wool",
                { "§7Slot: " .. slot, "§7Tick: " .. tick }
            )
            container:set_item(player, slot, item)
        end
    end)
end

events.player:set("PlayerJoinEvent", function(e)
    local player_name = e.player:get_name()

    container1:create_inventory(player_name, "§aTest Menu 1", 9, true) -- Create a 9-slot inventory, set as storable
    container2:create_inventory(player_name, "§bTest Menu 2", 9)       -- Create a 9-slot inventory, non-storable by default
    container3:create_inventory(player_name, "§cTest Menu 3", 9)

    -- Menu 1 content
    container1:set_item(player_name, 1, items.create_custom("DIAMOND", "§bTest Diamond", { "§7Click me" }), function(player, click_type)
        print("Player " .. player .. " clicked slot 1 in menu 1, click type: " .. click_type)
    end)
    -- Go to page 2
    container1:set_item(player_name, 9, items.create_custom("PAPER", "§eNext Page", { "§7Click to switch to Menu 2" }), function(player, click_type)
        print("Player " .. player .. " clicked the page switch button in menu 1, switching to menu 2")
        container2:open(player)
    end)
    -- Animation
    container1:set_item(player_name, 8, items.create_custom("CLOCK", "§dAnimation Test", { "§7Click to start animation" }), function(player, click_type)
        print("Player " .. player .. " clicked the animation test button, starting animation")
        wool_wave_animation(container1, player_name)
    end)
    -- Set interactivity: slot 2 and 3 can put in or take out items
    container1:set_slot_interact(player_name, 2, true, true)
    container1:set_slot_interact(player_name, 3, true, true)

    -- Menu 2 content
    container2:set_item(player_name, 1, items.create_custom("EMERALD", "§aMenu 2 Item", { "§7This is page 2" }), function(player, click_type)
        print("Player " .. player .. " clicked slot 1 in menu 2, click type: " .. click_type)
    end)
    container2:set_slot_interact(player_name, 2, true, true)
    container2:set_slot_interact(player_name, 3, true, true)

    -- Go to page 3
    container2:set_item(player_name, 9, items.create_custom("PAPER", "§eNext Page", { "§7Click to switch to Menu 3" }), function(player, click_type)
        print("Player " .. player .. " clicked the page switch button in menu 2, switching to menu 3")
        container3:open(player)
    end)
    -- Return to page 1
    container2:set_item(player_name, 8, items.create_custom("ARROW", "§eBack", { "§7Click to return to Menu 1" }), function(player, click_type)
        print("Player " .. player .. " clicked the back button in menu 2, returning to menu 1")
        container1:open(player)
    end)

    -- Menu 3 content
    container3:set_item(player_name, 1, items.create_custom("GOLD_INGOT", "§6Menu 3 Item", { "§7This is page 3" }), function(player, click_type)
        print("Player " .. player .. " clicked slot 1 in menu 3, click type: " .. click_type)
    end)
    container3:set_slot_interact(player_name, 2, true, true)
    container3:set_slot_interact(player_name, 3, true, true)

    -- Go to page 2
    container3:set_item(player_name, 9, items.create_custom("PAPER", "§eNext Page", { "§7Click to switch to Menu 2" }), function(player, click_type)
        print("Player " .. player .. " clicked the page switch button in menu 3, switching to menu 2")
        container2:open(player)
    end)
    -- Return to page 1
    container3:set_item(player_name, 8, items.create_custom("ARROW", "§eBack", { "§7Click to return to Menu 1" }), function(player, click_type)
        print("Player " .. player .. " clicked the back button in menu 3, returning to menu 1")
        container1:open(player)
    end)

    container1:open(player_name)
end)

Last updated