#how to i add cooldown to item?
1 messages · Page 1 of 1 (latest)
do u have an example ?
You basically already did the check in the sceond function:
const cooldownComp = itemStack.getComponent('minecraft:cooldown');
if (cooldownComp) {
const remainingTime = cooldownComp.getCooldownTicksRemaining(player);
if (remainingTime == 0) {
// execute whatever you want the item to do here
}
}
i kinda have 0 clue where to place this.
world.afterEvents.itemUse.subscribe((event) => {
const item = event.itemStack
const player = event.source
if (item.typeId != "cata:floretstone") return
const cooldownComp = item.getComponent('minecraft:cooldown');
if (!cooldownComp) return
const remainingTime = cooldownComp.getCooldownTicksRemaining(player);
if (remainingTime > 0) return
player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, 5, 1,)
player.runCommandAsync("particle cata:small_impact ~ ~ ~")
player.runCommandAsync("playsound random.explode @a[r=10] ~ ~ ~ 10 2.5 10")
})
The first function could look something like this
like this?
import * as server from "@minecraft/server"
const world = server.world
world.afterEvents.itemUse.subscribe((event) => {
const item = event.itemStack
const player = event.source
if (item.typeId != "cata:floretstone") return
const cooldownComp = item.getComponent('minecraft:cooldown');
if (!cooldownComp) return
const remainingTime = cooldownComp.getCooldownTicksRemaining(player);
if (remainingTime > 0) return
player.applyKnockback(player.getViewDirection().x, player.getViewDirection().z, 5, 1,)
player.runCommandAsync("particle cata:small_impact ~ ~ ~")
player.runCommandAsync("playsound random.explode @a[r=10] ~ ~ ~ 10 2.5 10")
})
import { world, system } from '@minecraft/server';
world.beforeEvents.itemUse.subscribe(({ source: player, itemStack }) => {
let event = system.run(() => {
if (itemStack.typeId === 'cata:floretstone') {
const cooldownComp = itemStack.getComponent('minecraft:cooldown');
if (cooldownComp) {
const remainingTime = cooldownComp.getCooldownTicksRemaining(player);
if (remainingTime == 0) {
cooldownComp.startCooldown(player);
}
}
}
})
})
Yeah, that should work
it has the cooldown it just doesnt do anything
Isn't that what it should do?
its suppose to do this but only work when the cooldown is finished