GUI Skript with buttons that execute commands

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

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Polarsk

New Member
Mar 1, 2024
7
1
3
24
Hello, i'm trying to make it so when a player clicks on the green wool (clear inventory confirm) it does this: execute console command "clear %player%" and when you click the red wool (cancel) it closes the GUI. I'm quite new to skript, don't know much. Any ideas?

Code:
command /ci:
    permission: ci.sk
    permission message: &cNo Permission.
    trigger:
        wait 2 ticks
        open chest with 3 rows named "&8Clear Inventory" to player
        format slot 0 of player with gray stained glass pane named " " to be unstealable
        format slot 1 of player with gray stained glass pane named " " to be unstealable
        format slot 2 of player with gray stained glass pane named " " to be unstealable
        format slot 3 of player with gray stained glass pane named " " to be unstealable
        format slot 4 of player with gray stained glass pane named " " to be unstealable
        format slot 5 of player with gray stained glass pane named " " to be unstealable
        format slot 6 of player with gray stained glass pane named " " to be unstealable
        format slot 7 of player with gray stained glass pane named " " to be unstealable
        format slot 8 of player with gray stained glass pane named " " to be unstealable
        format slot 9 of player with gray stained glass pane named " " to be unstealable
        format slot 10 of player with gray stained glass pane named " " to be unstealable
        format slot 11 of player with lime wool named "&a&l✔ &2&lCONFIRM " with lore "&aDescription:" and " &a&l| &r&7Confirm that you want to clear" and " &a&l| &r&7the items from your inventory." and " " and "&eClick to clear your inventory. " to be unstealable
        format slot 12 of player with gray stained glass pane named " " to be unstealable
        format slot 13 of player with gray stained glass pane named " " to be unstealable
        format slot 14 of player with gray stained glass pane named " " to be unstealable
        format slot 15 of player with red wool named "&c&l❌ &4&lCANCEL " with lore "&cDescription:" and " &c&l| &r&7Click to cancel and close menu." and " " and "&eClick to cancel. " to be unstealable
        format slot 16 of player with gray stained glass pane named " " to be unstealable
        format slot 17 of player with gray stained glass pane named " " to be unstealable
        format slot 18 of player with gray stained glass pane named " " to be unstealable
        format slot 19 of player with gray stained glass pane named " " to be unstealable
        format slot 20 of player with gray stained glass pane named " " to be unstealable
        format slot 21 of player with gray stained glass pane named " " to be unstealable
        format slot 22 of player with gray stained glass pane named " " to be unstealable
        format slot 23 of player with gray stained glass pane named " " to be unstealable
        format slot 24 of player with gray stained glass pane named " " to be unstealable
        format slot 25 of player with gray stained glass pane named " " to be unstealable
        format slot 26 of player with gray stained glass pane named " " to be unstealable
 
this should work but I havent tested it
Code:
command /ci:
    permission: ci.sk
    permission message: &cNo Permission.
    trigger:
        wait 2 ticks
        open chest with 3 rows named "&8Clear Inventory" to player
        format slot 0 of player with gray stained glass pane named " " to be unstealable
        format slot 1 of player with gray stained glass pane named " " to be unstealable
        format slot 2 of player with gray stained glass pane named " " to be unstealable
        format slot 3 of player with gray stained glass pane named " " to be unstealable
        format slot 4 of player with gray stained glass pane named " " to be unstealable
        format slot 5 of player with gray stained glass pane named " " to be unstealable
        format slot 6 of player with gray stained glass pane named " " to be unstealable
        format slot 7 of player with gray stained glass pane named " " to be unstealable
        format slot 8 of player with gray stained glass pane named " " to be unstealable
        format slot 9 of player with gray stained glass pane named " " to be unstealable
        format slot 10 of player with gray stained glass pane named " " to be unstealable
        format slot 11 of player with lime wool named "&a&l✔ &2&lCONFIRM " with lore "&aDescription:" and " &a&l| &r&7Confirm that you want to clear" and " &a&l| &r&7the items from your inventory." and " " and "&eClick to clear your inventory. " to be unstealable
        format slot 12 of player with gray stained glass pane named " " to be unstealable
        format slot 13 of player with gray stained glass pane named " " to be unstealable
        format slot 14 of player with gray stained glass pane named " " to be unstealable
        format slot 15 of player with red wool named "&c&l❌ &4&lCANCEL " with lore "&cDescription:" and " &c&l| &r&7Click to cancel and close menu." and " " and "&eClick to cancel. " to be unstealable
        format slot 16 of player with gray stained glass pane named " " to be unstealable
        format slot 17 of player with gray stained glass pane named " " to be unstealable
        format slot 18 of player with gray stained glass pane named " " to be unstealable
        format slot 19 of player with gray stained glass pane named " " to be unstealable
        format slot 20 of player with gray stained glass pane named " " to be unstealable
        format slot 21 of player with gray stained glass pane named " " to be unstealable
        format slot 22 of player with gray stained glass pane named " " to be unstealable
        format slot 23 of player with gray stained glass pane named " " to be unstealable
        format slot 24 of player with gray stained glass pane named " " to be unstealable
        format slot 25 of player with gray stained glass pane named " " to be unstealable
        format slot 26 of player with gray stained glass pane named " " to be unstealable

on inventory click:
    if name of event-inventory is "&8Clear Inventory":
        cancel event
        if index of event-slot is 11:
            clear player's inventory
            close player's inventory
        else if index of event-slot is 15:
            close player's inventory
 
Hello, i'm trying to make it so when a player clicks on the green wool (clear inventory confirm) it does this: execute console command "clear %player%" and when you click the red wool (cancel) it closes the GUI. I'm quite new to skript, don't know much. Any ideas?

Code:
command /ci:
    permission: ci.sk
    permission message: &cNo Permission.
    trigger:
        wait 2 ticks
        open chest with 3 rows named "&8Clear Inventory" to player
        format slot 0 of player with gray stained glass pane named " " to be unstealable
        format slot 1 of player with gray stained glass pane named " " to be unstealable
        format slot 2 of player with gray stained glass pane named " " to be unstealable
        format slot 3 of player with gray stained glass pane named " " to be unstealable
        format slot 4 of player with gray stained glass pane named " " to be unstealable
        format slot 5 of player with gray stained glass pane named " " to be unstealable
        format slot 6 of player with gray stained glass pane named " " to be unstealable
        format slot 7 of player with gray stained glass pane named " " to be unstealable
        format slot 8 of player with gray stained glass pane named " " to be unstealable
        format slot 9 of player with gray stained glass pane named " " to be unstealable
        format slot 10 of player with gray stained glass pane named " " to be unstealable
        format slot 11 of player with lime wool named "&a&l✔ &2&lCONFIRM " with lore "&aDescription:" and " &a&l| &r&7Confirm that you want to clear" and " &a&l| &r&7the items from your inventory." and " " and "&eClick to clear your inventory. " to be unstealable
        format slot 12 of player with gray stained glass pane named " " to be unstealable
        format slot 13 of player with gray stained glass pane named " " to be unstealable
        format slot 14 of player with gray stained glass pane named " " to be unstealable
        format slot 15 of player with red wool named "&c&l❌ &4&lCANCEL " with lore "&cDescription:" and " &c&l| &r&7Click to cancel and close menu." and " " and "&eClick to cancel. " to be unstealable
        format slot 16 of player with gray stained glass pane named " " to be unstealable
        format slot 17 of player with gray stained glass pane named " " to be unstealable
        format slot 18 of player with gray stained glass pane named " " to be unstealable
        format slot 19 of player with gray stained glass pane named " " to be unstealable
        format slot 20 of player with gray stained glass pane named " " to be unstealable
        format slot 21 of player with gray stained glass pane named " " to be unstealable
        format slot 22 of player with gray stained glass pane named " " to be unstealable
        format slot 23 of player with gray stained glass pane named " " to be unstealable
        format slot 24 of player with gray stained glass pane named " " to be unstealable
        format slot 25 of player with gray stained glass pane named " " to be unstealable
        format slot 26 of player with gray stained glass pane named " " to be unstealable
Not related to solving your issue, but you can format multiple GUI slots at once by separating the numbers via commas and that could help your code in general to be more readable.

Example:
format slot 16,17,18,18,19,20,21,22,23,24,25 and 26 of player with gray stained glass pane named “ “ to be unstealable
 
Also not related to solving your issue but you can do something similar (if slightly larger) and it looks a bit more readable.
Code:
set {_i} to 0
loop 26 times:
    {_i} is not 11 or 15:
        format slot {_i} of player with gray stained glass pane named " " to be unstealable
    add 1 to {_i}
And this above code should handle all 25 gray stained glass panes in your gui--however, it is untested.
 
  • Like
Reactions: Luke_Sky_Walker
Not related to solving your issue, but you can format multiple GUI slots at once by separating the numbers via commas and that could help your code in general to be more readable.

Example:
format slot 16,17,18,18,19,20,21,22,23,24,25 and 26 of player with gray stained glass pane named “ “ to be unstealable
Okay thanks ill be using this!
 
  • Like
Reactions: Luke_Sky_Walker
this should work but I havent tested it
Code:
command /ci:
    permission: ci.sk
    permission message: &cNo Permission.
    trigger:
        wait 2 ticks
        open chest with 3 rows named "&8Clear Inventory" to player
        format slot 0 of player with gray stained glass pane named " " to be unstealable
        format slot 1 of player with gray stained glass pane named " " to be unstealable
        format slot 2 of player with gray stained glass pane named " " to be unstealable
        format slot 3 of player with gray stained glass pane named " " to be unstealable
        format slot 4 of player with gray stained glass pane named " " to be unstealable
        format slot 5 of player with gray stained glass pane named " " to be unstealable
        format slot 6 of player with gray stained glass pane named " " to be unstealable
        format slot 7 of player with gray stained glass pane named " " to be unstealable
        format slot 8 of player with gray stained glass pane named " " to be unstealable
        format slot 9 of player with gray stained glass pane named " " to be unstealable
        format slot 10 of player with gray stained glass pane named " " to be unstealable
        format slot 11 of player with lime wool named "&a&l✔ &2&lCONFIRM " with lore "&aDescription:" and " &a&l| &r&7Confirm that you want to clear" and " &a&l| &r&7the items from your inventory." and " " and "&eClick to clear your inventory. " to be unstealable
        format slot 12 of player with gray stained glass pane named " " to be unstealable
        format slot 13 of player with gray stained glass pane named " " to be unstealable
        format slot 14 of player with gray stained glass pane named " " to be unstealable
        format slot 15 of player with red wool named "&c&l❌ &4&lCANCEL " with lore "&cDescription:" and " &c&l| &r&7Click to cancel and close menu." and " " and "&eClick to cancel. " to be unstealable
        format slot 16 of player with gray stained glass pane named " " to be unstealable
        format slot 17 of player with gray stained glass pane named " " to be unstealable
        format slot 18 of player with gray stained glass pane named " " to be unstealable
        format slot 19 of player with gray stained glass pane named " " to be unstealable
        format slot 20 of player with gray stained glass pane named " " to be unstealable
        format slot 21 of player with gray stained glass pane named " " to be unstealable
        format slot 22 of player with gray stained glass pane named " " to be unstealable
        format slot 23 of player with gray stained glass pane named " " to be unstealable
        format slot 24 of player with gray stained glass pane named " " to be unstealable
        format slot 25 of player with gray stained glass pane named " " to be unstealable
        format slot 26 of player with gray stained glass pane named " " to be unstealable

on inventory click:
    if name of event-inventory is "&8Clear Inventory":
        cancel event
        if index of event-slot is 11:
            clear player's inventory
            close player's inventory
        else if index of event-slot is 15:
            close player's inventory
Didn't work
 
Didn't work
Correct. For that example you need SkQuery. Aka the worst addon in the world that breaks everything.
I would recommend this:
code_language.skript:
on inventory click:
  if name of event-inventory is "my gui":
    cancel event
This was not tested
Then you could add this after canceling the event:
code_language.skript:
if type of event-item is green wool:
  make server execute command "clear %player%"
  send "done"
 
Last edited: