1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Create a GUI with as many pages it needs.

Discussion in 'Skript' started by KroterPvP, Jun 27, 2017.

Thread Status:
Not open for further replies.
  1. KroterPvP

    KroterPvP Active Member

    Joined:
    Apr 10, 2017
    Messages:
    178
    Likes Received:
    7
    Hello. I'm working on a smart inventory to show bans. I want it to create as many pages it needs. The gui has 6 rows, but the 6th row is used to manage aspects of the gui like changing the page and those things. So the bans are only sown in the first 5th rows. If the gui has more than 5 rows of bans, it must add a new page to show more bans. I don't know how to code it.

    Skript Version: Skript 2.2-dev27
    Skript Author: Bensku
    Minecraft Version: 1.8.8
    Addons I'm using: SkQuerry 3 and Skellet
    I have tried searching the docs, and I found nothing.
    I've also tried to search in the forums. Yes
    What other methods have you tried to fix it? I don't need to do it
    Skript code:
    Code (Skript):
    1. command /bans:
    2.     trigger:
    3.         player has permission "sb.bans":
    4.             clear {bans1::%player%::*}
    5.             open chest with 6 rows named "&0List of banned players" to player
    6.             wait 0.5 ticks
    7.             set slot 45 of player's current inventory to book named "&eMain Page"
    8.             wait 0.5 ticks
    9.             set slot 46 of player's current inventory to black stained glass pane named "&7"
    10.             wait 0.5 ticks
    11.             set slot 47 of player's current inventory to black stained glass pane named "&7"
    12.             wait 0.5 ticks
    13.             set slot 48 of player's current inventory to black stained glass pane named "&7"
    14.             wait 0.5 ticks
    15.             set slot 49 of player's current inventory to anvil named "&eSearch players" with lore "||&7Click here to &csearch &7banned players.||&7You will need to type it in chat."
    16.             wait 0.5 ticks
    17.             set slot 50 of player's current inventory to black stained glass pane named "&7"
    18.             wait 0.5 ticks
    19.             set slot 51 of player's current inventory to black stained glass pane named "&7"
    20.             wait 0.5 ticks
    21.             set slot 52 of player's current inventory to black stained glass pane named "&7"
    22.             wait 0.5 ticks
    23.             set slot 53 of player's current inventory to arrow named "&eNext Page"
    24.             set {_slot} to 0
    25.             wait 1 tick
    26.             loop {bans::*}:
    27.                 if {_slot} is less than 45:
    28.                     set slot {_slot} of player's current inventory to loop-value's skull named "&7Player &8» &c%loop-value%" with lore "||&7Ban ID &8» &7(&c##%loop-index%&7)||||&7Is Banned &8» &c%{sban.banned.%loop-value%}%||&7Banned by &8» &c%{sban.bannedby.%loop-value%}%||&7Banned on &8» &c%{sban.time.%loop-value%}%||"
    29.                     set {bans1::%player%::*} to true
    30.                     add 1 to {_slot}
    31.         else:
    32.             send "&8[&c&lBANS&8] &cYou don't have permission to do this!"
    33. on inventory click:
    34.     if name of player's current inventory is "&0List of banned players":
    35.         cancel event
    36.         if clicked slot is less than 45:
    37.             if clicked item is player head:
    38.                 if name of item contains "&7Player":
    39.                     set {_playername} to "%clicked item's name%"
    40.                     replace all "&7Player &8» &c" in {_playername} with ""
    41.                     execute player command "/unban %{_playername}%"
    42.                     execute player command "/bans"
    43.         if clicked slot is 45:
    44.             close player's inventory
    45.             execute player command "/bans"
    46.         if clicked slot is 49:
    47.             close player's inventory
    48.             set {bans.chat::%player%} to true
    49.             send "&8[&c&lBANS&8] &7You must write the player's name in chat. Type &ccancel &7to annullate the search."
    50.         if clicked slot is 53:
    51.             set {_slot} to -1
    52.             loop 44 times:
    53.                 add 1 to {_slot}
    54.                 set slot {_slot} of player's current inventory to air
    55.             set {_slot} to 0
    56.             loop {bans::*}:
    57.                 if {_slot} is less than 45:
    58.                     if {bans1::%player%::%loop-index%} is not set:
    59.                         set slot {_slot} of player's current inventory to loop-value's skull named "&7Player &8» &c%loop-value% &7(&c##%loop-index%&7)." with lore "||&7Is Banned &8» &c%{sban.banned.%loop-value%}%&7.||&7Banned by &8» &c%{sban.bannedby.%loop-value%}%&7.||&7Ban reason &8» &c%{sban.reason.%loop-value%}%&7.||&7Banned on &8» &c%{sban.time.%loop-value%}%&7.||&7"
    60.                         set {bans1::%player%::%loop-index%} to true
    61.                         add 1 to {_slot}
    Errors loading this skript: No errors
     
  2. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    I had to do something of the sort for a minigame invitation system, so I believe I can help you. In addition, if you plan to see yourself coding with Skript- or any basic language for that matter, I suggest you familiarize yourself with some basic coding practices, as they will help you in the future. We'll need to use recursive programming in order to achieve this; there may be different ways to do it, but I find this the easiest. We'll need to define a function, to then have that function call itself.

    Here's my code; I didn't touch the inventory clicking stuff, just the dynamic chest menu.
    Code (Skript):
    1. function bansPage(p: player, page: number):
    2.     set {_pageStart} to 45*{_page}
    3.     set {_i} to 1
    4.     set {_a} to 0
    5.     open chest with 6 rows named "&3Page %{_page}%" to {_p}
    6.     wait 2 ticks
    7.     loop {bans::*}:
    8.         (loop-index parsed as integer) > {_pageStart}
    9.         set {_player} to "%loop-value%" parsed as offline player
    10.         set slot {_a} of {_p}'s current inventory to skull of {_player} named "&7Player &8» &c%loop-value%" with lore "||&7Ban ID &8» &7(&c##%loop-index%&7)||||&7Is Banned &8» &c%{sban.banned.%loop-value%}%||&7Banned by &8» &c%{sban.bannedby.%loop-value%}%||&7Banned on &8» &c%{sban.time.%loop-value%}%||"
    11.         add 1 to {_a}
    12.         if {_a} = ((45*{_i})):
    13.             exit loop
    14.     format slot 49 of {_p} with book named "&eMain Page" to run [bansPage({_p}, 0)]
    15.     if (amount of {bans::*}) > {_pageStart} + 45:
    16.         format slot 53 of {_p} with arrow named "&9Next Page" to run [bansPage({_p}, ({_page} + 1))]
    17.     if {_page} > 0:
    18.         format slot 45 of {_p} with arrow named "&9Previous Page" to run [bansPage({_p}, ({_page} - 1))]
    19.  
    20. command /bans:
    21.     permission: sb.bans
    22.     permission message: &8[&c&lBANS&8] &cYou don't have permission to do this!
    23.     trigger:
    24.         bansPage(player, 0)
     
    • Winner Winner x 2
    • Informative Informative x 2
  3. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    222
    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page

Loading...