Solved every 2 seconds more elegant

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

    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!

JuliHatSpaB

Member
Aug 18, 2023
47
1
8
I want to let the Block in the GUI rotate and this would be my solution but I think, its very inefficient to do:
1. double so much code in the richblocks even though only the type of item changes
2. loop all players every 2 seconds
Code:
options:
        richblocks: diamond block with name "&l&5open Crates!" with lore "&fYou own: %{crates.number.%loop-player%}%", emerald block with name "&l&5open Crates!" with lore "&fYou own: %{crates.number.%loop-player%}%" and gold block with name "&l&5open Crates!" with lore "&fYou own: %{crates.number.%loop-player%}%"
# . . . creating the GUI . . .
every 2 seconds:
    loop all players:
        if name of loop-player's current inventory is "&eC&dR&aA&bT&cE&3S":
            set slot 2 of loop-player's current inventory to random element of {@richblocks}
Do you have any solution to do this more efficient?
 
Hey, I think you're the one I did the hopper script for. You can use the variable of the gui for the 2 seconds event, and you are chilling (You have to do global var on the previous one) and then add this:

Code:
on load:
    clear {richblocks::*}
    set {b1} to diamond block named "&l&5open Crates!" with lore "&fYou own: %{crates.number.%player%}%"
    set {b2} to emerald block named "&l&5open Crates!" with lore "&fYou own: %{crates.number.%player%}%"
    set {b3} to gold block named "&l&5open Crates!" with lore "&fYou own: %{crates.number.%player%}%"
    add {b1}, {b2} and {b3} to {richblocks::*}

every 2 seconds:
    set slot 2 of {crates.gui} to random element out of {richblocks::*}
 
Hey, I think you're the one I did the hopper script for. You can use the variable of the gui for the 2 seconds event, and you are chilling (You have to do global var on the previous one) and then add this:

Code:
on load:
    clear {richblocks::*}
    set {b1} to diamond block named "&l&5open Crates!" with lore "&fYou own: %{crates.number.%player%}%"
    set {b2} to emerald block named "&l&5open Crates!" with lore "&fYou own: %{crates.number.%player%}%"
    set {b3} to gold block named "&l&5open Crates!" with lore "&fYou own: %{crates.number.%player%}%"
    add {b1}, {b2} and {b3} to {richblocks::*}

every 2 seconds:
    set slot 2 of {crates.gui} to random element out of {richblocks::*}
Thank you. Yes I am the one with the hopper inventory. But it would be still every 2 seconds and isn't this really inefficent? Wouldn't my server lag if use this for too many GUIs?
 
And if the inventory is global, I could set the inventory one time and then just use the open {crates.gui} and delete the set slot ... right?
Hey, I think you're the one I did the hopper script for. You can use the variable of the gui for the 2 seconds event, and you are chilling (You have to do global var on the previous one) and then add this:

Code:
on load:
    clear {richblocks::*}
    set {b1} to diamond block named "&l&5open Crates!" with lore "&fYou own: %{crates.number.%player%}%"
    set {b2} to emerald block named "&l&5open Crates!" with lore "&fYou own: %{crates.number.%player%}%"
    set {b3} to gold block named "&l&5open Crates!" with lore "&fYou own: %{crates.number.%player%}%"
    add {b1}, {b2} and {b3} to {richblocks::*}

every 2 seconds:
    set slot 2 of {crates.gui} to random element out of {richblocks::*}
 
Thank you. Yes I am the one with the hopper inventory. But it would be still every 2 seconds and isn't this really inefficent? Wouldn't my server lag if use this for too many GUIs?
It will definitely have less lag than running through every player on the server every 2 seconds
 
  • Like
Reactions: JuliHatSpaB
And if the inventory is global, I could set the inventory one time and then just use the open {crates.gui} and delete the set slot ... right?
I don't know exactly what you mean right now, try to describe it a little bit.
 
I don't know exactly what you mean right now, try to describe it a little bit.
So I can change the original code:
Code:
command /crates:
    trigger:
        set {_crates.gui} to ...
        set slot 0 of {_crates.gui} to .....
        # set the other slots
to:
Code:
on load:
    set {crates.gui} to hopper...
    set slot 0 of {crates.gui} to .....
# set the other slots
command /crates:
    trigger:
        open {crates.gui} to player