#cooldown (kit claiming in a gui)

1 messages · Page 1 of 1 (latest)

heavy jay
#

if {obsidiancooldown.%player%} is not set:
give player 1 coal
set {obsidiancooldown.%player%} to now + 1 day
send "&aYou claimed the Obsidian kit!" to player
close player's inventory
kitsGUI(player)
else:
set {_remaining} to {obsidiancooldown.%player%} - now
send "&cYou must wait &e%{_remaining}%&c before claiming this kit again!" to player

how would i make the %{_remaining}% display how much longer is left?

teach me dont just do it for me

snow radish
#

wrong one

#

oops

#

here

heavy jay
snow radish
#

np

heavy jay
# snow radish np

ok so it works when i make it send the player the cooldown but im trying to include it in a lore and its displaying as <none> any clue why?

snow radish
heavy jay
#

oh no

snow radish
#

its not gonna update in the lore

#

though

#

because lore is static

heavy jay
#

oh

#

so how would i change this tio make it work?

snow radish
#

i mean you cant make it so it updates in the lore unless you use every tick: and loop all players

heavy jay
#

how would i make that update it mb im only js getting into skripting

coral pike
# heavy jay how would i make that update it mb im only js getting into skripting

not sure if this will help, but this is how i update my GUI that has an item with a constantly changing timer in it

every 1 second:
    set {smuggler::globalTimer} to 300 if {smuggler::globalTimer} is not set
    if {smuggler::globalTimer} > 0:
        subtract 1 from {smuggler::globalTimer}
        #attempt to update timer in GUI if currently opened
        loop all players:
            if name of loop-player's open inventory is "%yaml value "GUI.AlienShopMain.Title" from "aliens.yml"%":
                set slot 44 of loop-player's open inventory to clock named "&aʀᴇѕᴛᴏᴄᴋ ᴛɪᴍᴇʀ" with lore "", and "&a| &7Time Left: &a%secondsToTime({smuggler::globalTimer})%"
    #Refresh Smuggler + reopen GUI if currently opened
    if {smuggler::globalTimer} is 0:
        broadcast "%yaml value "Tools.Prefix" from "aliens.yml"% %yaml value "Tools.SmugglerRefresh" from "aliens.yml"%"
        #add play sound function when done
        set {smuggler::globalTimer} to 300
        loop all players:
            generatePlayerStock(loop-player)
            if name of loop-player's open inventory is "%yaml value "GUI.AlienShopMain.Title" from "aliens.yml"%":
                open alienShop(loop-player) for loop-player
snow radish
#

periodical as in subtracting 1 every second

coral pike
#

that would work for the timer iteself, but i want a visual representation of the timer for players to know when the shop reset is upcoming

snow radish
#

minutes of or seconds of %timespan% exists

#

and there are many snippets for formatting timespans

coral pike
#

how do i set a timespan? i've never used those before

snow radish
#

i'd use: set {smuggler::globalTimer} to 300 seconds from now
and then compare it by doing: ```
if {smuggler::globalTimer} > now:
this is when its on cooldown

else:
this is when its off cooldown

#

300 seconds from now is 300 seconds in the future

#

so if the variable is greater than now which is the current time, then it hasnt been 300 seconds yet

coral pike
#

ahhhhhhhhhhhhhhhhh, i didn't realize i could just do x seconds from now as a variable

coral pike
#

wouldn't i have to still use an every second update to get the real time timer?

snow radish
#

yes but this is still more accurate & would just the code look more readable

#

imo

coral pike
#

this would probably fix the desync error i have then

the timer in the GUI and the timer displayed are about 1 second off from each other (scoreboard is 1 second behind)

snow radish
coral pike
#

ye, its been an issue i've been trying my hardest to solve LOL

snow radish
#

also scoreboard might just be behind because its refresh rate is lower

coral pike
#

scoreboard update is every 1second as well

snow radish
#

oh

#

well idk if this is going to fix the error in your case but it might

coral pike
#

idk if maybe they are just updating on different seconds or what

#

like the GUI is updating on 1s and scoreboard on 2s

snow radish
#

also one more thing. when you do loop all players: you can filter the players so that you avoid unnecessary iterations with: loop all players where [name of player input's open inventory is "%yaml value "GUI.AlienShopMain.Title" from "aliens.yml"%"]:

coral pike
#

so id look like

gui
board
gui
board

snow radish
snow radish
#

for example, loop all players where [player input is op]: would only look players that are op and you dont have to do:

loop all players:
    if loop-player is op:
coral pike
#

ahhh, but i need to loop all players anyways in this instance

loop all
generate all players' stock
also if the shop gui is upen then reopen it

snow radish
coral pike
#

yee

heavy jay
#

skript

coral pike
heavy jay
#

well ive read thrpough what you use and what the other person suggested and im just lost can i send my bit of code here ( im not asking for you to do it for me i js need more of an explantation)

coral pike
heavy jay
#

alr

#
            if {obsidiancooldown.%player%} is not set:
                give player 1 coal
                set {obsidiancooldown.%player%} to now + 24 hours
                send "&aYou claimed the Obsidian kit!" to player
                close player's inventory
                kitsGUI(player)
            else:
                send "&cYou must wait till &e%{obsidiancooldown.%player%}%&c before claiming this kit again!" to player```
#

so when the kit isnt on a cooldown it shows as <none> but when it is on cooldown it shows how i want it do

#

to*

coral pike
#

just wondering cause i don't see an interaction here

#

also, you're setting the cooldown after the item's name, lore, etc is created

#

you need to set it before

#

unless you are setting it before somewhere? but in the snippet you've given me its not set

#

also

you're saying

if cooldown is not set:
give player kit
if cooldown IS set:
tell player kit is on cooldown
#

you don't have any sort of system to check if their cooldown is ready yet

#

threw this together slopily, idk if you have the same addons i have or not so it might not work for you

function kitObsidian(p:player):
    give {_p} 1 coal
    set {obsidiancooldown.%{_p}%} to now + 24 hours
    send "&aYou claimed the Obsidian kit!" to {_p}

function kitsGUI(p: player) :: inventory:
    #pre setting the variable when the player opens the GUI
    set {obsidiancooldown.%{_p}'s uuid%} to now - 24 hours if {obsidiancooldown.%{_p}%} is set

    create gui with virtual chest inventory with 3 rows named "&0Kits":
        make gui slot 24 with purple shulker box named "<#6A37FF>&lO<#7D50FF>&lb<#9069FF>&ls<#A282FF>&li<#B59BFF>&ld<#9C7AFF>&li<#8358FF>&la<#6A37FF>&ln &fKit" with lore "&8ᴅᴏɴᴀᴛᴏʀ ᴋɪᴛ%nl%%nl%  <#6A37FF>&l| &fLeft-click to claim!%nl%  <#6A37FF>&l| &fRight-click to preview!%nl%%nl%<#6A37FF>&lSTATUS:%nl%%nl%&fᴄᴏᴏʟᴅᴏᴡɴ: <#6A37FF>%{obsidiancooldown.%{_p}%}%":
            if gui click type is lmb:
                if {obsidiancooldown.%{_p}'s uuid%} is not set:
                    kitObsidian({_p})
                    kitsGUI({_p})
                else:
                    if {obsidiancooldown.%{_p}'s uuid%} <= now:
                        kitObsidian({_p})
                        kitsGUI({_p})
                    else:
                        send "&cYou must wait till &e%{obsidiancooldown.%{_p}'s uuid%}%&c before claiming this kit again!" to {_p}
#

added a function for the obsidian kit to make it easier to apply to multiple places & change quicker down the road

heavy jay
coral pike
heavy jay
coral pike
heavy jay
#

the whole thing?

coral pike
#

yeah

heavy jay
#

ill do it in dms not here

coral pike
#

ok

#

you keep trying to use player in your variables, dont do that

#

use the player uuid

#

like i did

snow radish
#

if you use just the player then it resets if they change username 👍

coral pike
#

^

#

they also lose ALL DATA assigned to them if they change their username

#

replace the following

#
function kitObsidian(p:player):
    give {_p} 1 coal
    set {obsidiancooldown.%{_p}'s uuid%} to now + 24 hours
    send "&aYou claimed the Obsidian kit!" to {_p}
#
set {obsidiancooldown.%{_p}'s uuid%} to now - 24 hours if {obsidiancooldown.%{_p}'s uuid%} is set
#
make gui slot 24 with purple shulker box named "<#6A37FF>&lO<#7D50FF>&lb<#9069FF>&ls<#A282FF>&li<#B59BFF>&ld<#9C7AFF>&li<#8358FF>&la<#6A37FF>&ln &fKit" with lore "&8ᴅᴏɴᴀᴛᴏʀ ᴋɪᴛ%nl%%nl%  <#6A37FF>&l| &fLeft-click to claim!%nl%  <#6A37FF>&l| &fRight-click to preview!%nl%%nl%<#6A37FF>&lSTATUS:%nl%%nl%&fᴄᴏᴏʟᴅᴏᴡɴ: <#6A37FF>%{obsidiancooldown.%{_p}'s uuid%}%":
            if gui click type is lmb:
                if {obsidiancooldown.%{_p}'s uuid%} is not set:
                    kitObsidian({_p})
                    kitsGUI({_p})
                else:
                    if {obsidiancooldown.%{_p}'s uuid%} <= now:
                        kitObsidian({_p})
                        kitsGUI({_p})
                    else:
                        send "&cYou must wait till &e%{obsidiancooldown.%{_p}'s uuid%}%&c before claiming this kit again!" to {_p}
heavy jay
sage carbon
#
    send "1" to {_player}
    if name of {_item} = {@SanguineArtItemName}:
        send "2" to {_player}
        set lore of {_item} to {@SanguineArtItemLoreFunction}
        send "3" to {_player}```
Can someone please explain why this doesnt update the lore? and is there a better way to update lore.
keen cloak
#

This is not your post…

coral pike
sage carbon
#

Oh mb