• 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!

WrexBG

Supporter
Mar 3, 2020
24
0
1
22
These are functions you may find useful when working with GUI's. It's just an easy way to add border, border with preset pattern, and fill or clear the inventory.

Some things to know beforehand:
- These are functions
- Required addons: none
- Tested on Minecraft 1.15.2 and Skript 2.4.1
- There are default values for the functions mention after each one
- It automatically gets the GUI size

★ Borders​
Code:
function addGUIBorder(p: player, item: item = stained glass pane, itemName: string = "&7"):
    set {_menuSize} to (rows of {_p}'s current inventory)
    set {_slot} to 0
    loop 9 times: #Top
        set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName}
        add 1 to {_slot}
    set {_slot} to 9
    loop {_menuSize}-2 times: #Sides
        set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName}
        set slot {_slot}+8 of {_p}'s current inventory to {_item} named {_itemName}
        add 9 to {_slot}
    set {_slot} to ({_menuSize}-1)*9
    loop 9 times: #Bottom
        set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName}
        add 1 to {_slot}
Usage:
addGUIBorder(player, red stained glass pane, "&7")
addGUIBorder(player) #Default values for the name is "&7" and for the item is a random colored glass pane

Code:
function addGUIBorder2(p: player, item: item = stained glass pane, item2: item = stained glass pane, itemName: string = "&7"):
    set {_menuSize} to (rows of {_p}'s current inventory)
    set {_slot} to 0
    loop 9 times: #Top
        set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName}
        set slot {_slot} of {_p}'s current inventory to {_item2} named {_itemName} if floor({_slot}/2) != ({_slot}/2)
        add 1 to {_slot}
    set {_slot} to 9
    loop {_menuSize}-2 times: #Sides
        set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName}
        set slot {_slot} of {_p}'s current inventory to {_item2} named {_itemName} if floor({_slot}/2) != ({_slot}/2)
        set slot {_slot}+8 of {_p}'s current inventory to {_item} named {_itemName}
        set slot {_slot}+8 of {_p}'s current inventory to {_item2} named {_itemName} if floor(({_slot}+8)/2) != (({_slot}+8)/2)
        add 9 to {_slot}
    set {_slot} to ({_menuSize}-1)*9
    loop 9 times: #Bottom
        set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName}
        set slot {_slot} of {_p}'s current inventory to {_item2} named {_itemName} if floor({_slot}/2) != ({_slot}/2)
        add 1 to {_slot}
Note: A GUI with odd number of rows is recommended
Usage:
addGUIBorder2(player, red stained glass pane, orange stained glass pane, "&7")
addGUIBorder2(player) #Default values for the name is "&7" and for both items is a random colored glass pane

★ Other (Misc)​
Code:
function fillGUI(p: player, item: item = light gray stained glass pane, itemName: string = "&7", keepItems: boolean = true):
    set {_menuSize} to (rows of {_p}'s current inventory)
    set {_slot} to 0
    loop 9*{_menuSize} times:
        if {_keepItems} is true:
            set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName} if slot {_slot} of {_p}'s current inventory is air
        else:
            set slot {_slot} of {_p}'s current inventory to {_item} named {_itemName}
        add 1 to {_slot}
Usage:
fillGUI(player, white stained glass pane, "&7", false)
fillGUI(player) #Default values for the name is "&7", for the item is light gray glass pane, and whether to keep or overwrite items in the GUI: true(keep). Setting the last value or false will overwrite

Code:
function clearGUI(p: player):
    delete all items in {_p}'s current inventory
Usage:
clearGUI(player)

This is work I felt like sharing. If you are looking for something simpler but more efficient I strongly recommend the following function by Blue:
Code:
function border(size: integer) :: integers:
  stop if {_size} is 1 or 2
  add (integers between 0 and 8) to {_r::*}
  add (integers between ({_size}-1)*9 and ({_size}-1)*9+8) to {_r::*}
  loop integers from 1 to {_size}:
   add loop-value*9 to {_r::*} if {_r::*} doesn't contain loop-value*9
   add loop-value*9+8 to {_r::*} if {_r::*} doesn't contain loop-value*9+8
  return {_r::*}

Usage:
Code:
set {_i} to chest inventory with 3 rows
set slots border(3) of {_i} to red wool
open {_i} to player