#is it possible to add cooldown to buttons in actionforms?

1 messages · Page 1 of 1 (latest)

proper bobcat
#

Like a 12h cooldown or 10minutes

#

If yes can someone explain how?

opal flume
#

explain more

sly relic
# opal flume explain more

I think what they mean is that they want it so that in a ui form that you can press a button like only one every 12 hours or something

opal flume
#

hmm

brave frigate
#

@proper bobcat im working on something rn

civic dome
brave frigate
#

@proper bobcat here is a script, it had a cool down of 10 mins, if you want to change it use a tick calculator, if you want to reset your cooldown do /scoreboard players set @s CoolDown 11999


import { ActionFormData } from "@minecraft/server-ui"
import { world, system } from "@minecraft/server"


class CoolCooldown {
    CoolDownForm(player) {
        const form = new ActionFormData()
            .button("CoolButton To Cool Thing")
        form.show(player).then((data) => {
            if (data.selection === 0) {
                if (!player.hasTag("CoolDown")) {
                    this.AwesomeThing(player)
                    system.runTimeout(() => {
                        player.addTag("CoolDown")
                    }, 5)
                } else if (player.hasTag("CoolDown")) {
                    return this.CoolDownWarning(player)
                }
            }
        })
    }

    CoolDownWarning(player) {
        const form = new ActionFormData()
            .body("You Have Used This Button, You Can Use It Again In 10 Mins From When You Clicked The Button\n\n\n\n\n\n")
            .button("Return")
        form.show(player).then((data) => {
            if (data.selection === 0) {
                return this.CoolDownForm(player)
            }
        })
    }

    AwesomeThing(player) {
        const form = new ActionFormData()
            .button("CoolTest")
            .button("back")
        form.show(player).then((data) => {
            if (data.selection === 1)
                return this.CoolDownForm(player)
        })
    }

}

export const CoolDown = new CoolCooldown




system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
        if (player.hasTag("CoolDown")) {

            const Score = world.scoreboard.getObjective("CoolDown")
            player.runCommandAsync("scoreboard players add @s CoolDown 1")
            if (Score.getScore(player) == 12000) {
                Score.setScore(player, 0)
                player.removeTag("CoolDown")
            }
        }
    }
}, 1)

proper bobcat
brave frigate
proper bobcat
#

Now I'll go combine the scripts ;-;

#

Thanks and cya

brave frigate
#

but I learned some things while making it so its cool beans

#

Np

proper bobcat
#

@brave frigate does it work if player is offline?

proper bobcat
proper bobcat
#

should i combine my into yours or yours into mine as im new at scripting

#

@brave frigate

proper bobcat
#

Also how does your form open with custom commands

#

Cuz I don't do much of scripting

brave frigate
#

Sorry I was asleep

proper bobcat
proper bobcat
#
import { ActionFormData } from "@minecraft/server-ui"
import { world, system } from "@minecraft/server"

class CoolCooldown {
    CoolDownForm(player) {
        const form = new ActionFormData()
            .button("CoolButton To Cool Thing")
        form.show(player).then((data) => {
            if (data.selection === 0) {
                if (!player.hasTag("CoolDown")) {
                    this.AwesomeThing(player)
                    system.runTimeout(() => {
                        player.addTag("CoolDown")
                    }, 5)
                } else if (player.hasTag("CoolDown")) {
                    return this.CoolDownWarning(player)
                }
            }
        })
    }

    CoolDownWarning(player) {
        const form = new ActionFormData()
            .body("You Have Used This Button, You Can Use It Again In 10 Mins From When You Clicked The Button\n\n\n\n\n\n")
            .button("Return")
        form.show(player).then((data) => {
            if (data.selection === 0) {
                return this.CoolDownForm(player)
            }
        })
    }

    AwesomeThing(player) {
        const form = new ActionFormData()
            .button("CoolTest")
            .button("back")
        form.show(player).then((data) => {
            if (data.selection === 1)
                return this.CoolDownForm(player)
        })
    }

}

export const CoolDown = new CoolCooldown

world.beforeEvents.chatSend.subscribe((eventData) => {
    const player = eventData.sender;

    if (eventData.message === "-test") {

        eventData.cancel = true;
        system.run(() => {
            CoolDown.CoolDownForm(player);
        })
    }
})


system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
        if (player.hasTag("CoolDown")) {

            const Score = world.scoreboard.getObjective("CoolDown")
            player.runCommandAsync("scoreboard players add @s CoolDown 1")
            if (Score.getScore(player) == 12000) {
                Score.setScore(player, 0)
                player.removeTag("CoolDown")
            }
        }
    }
}, 1)```