#Dash item error

1 messages · Page 1 of 1 (latest)

proven widget
#

I was trying to make it so that when using a certain item, the player would dash to wherever they were looking. I asked a friend for help and he gave me this, but when using the item, the dash doesn't work. Does anyone know how to fix this or what's wrong?

import { world, system, ItemStack, Vector, MinecraftItemTypes, Player } from "@minecraft/server";

const COOLDOWN_CATEGORY = "dash_item";
const COOLDOWN_DURATION = 600;

world.beforeEvents.itemUse.subscribe(event => {
const { source: player, itemStack } = event;

if (!(player instanceof Player)) return;
if (itemStack?.typeId !== "deadcore:dash") return;

const cooldownComp = player.getComponent("cooldown");
if (cooldownComp?.isCooldownActive(COOLDOWN_CATEGORY)) {
    player.runCommand(`title @s actionbar Dash in cooldown...`);
    return;
}

const view = player.getViewDirection();

if (Math.abs(view.y) > 0.4) {
    player.runCommand(`title @s actionbar ¡you can't use the dash up or down!`);
    return;
}

const speed = 1.5;
const dash = new Vector(view.x * speed, 0, view.z * speed);
player.applyKnockback(dash.x, dash.z, 0.5, 0.5);

player.startItemCooldown(COOLDOWN_CATEGORY, COOLDOWN_DURATION);

player.runCommand(`playsound random.orb @s`);
player.runCommand(`title @s actionbar ¡Dash used!`);

});

weak beacon
# proven widget I was trying to make it so that when using a certain item, the player would dash...
import { world, system, Player } from '@minecraft/server';

world.beforeEvents.itemUse.subscribe(({ source, itemStack }) => {
  if (!(source instanceof Player) || itemStack?.typeId !== 'deadcore:dash') return;

  const cooldown = itemStack.getComponent('cooldown');
  
  if (cooldown.getCooldownTicksRemaining(source) > 0) system.run(() => source.onScreenDisplay.setActionBar('Cooldown')), return;

  const { x, y, z } = source.getViewDirection();
  if (Math.abs(y) > 0.4) system.run(() => source.onScreenDisplay.setActionBar("No vertical dash")), return;

  system.run(() => {
    try {
      source.applyKnockback({ x: x * 0.75, z: z * 0.75 }, 0.5);
    } catch {
      source.applyKnockback(x * 1.5, z * 1.5, 0.5, 0.5);
    }

    source.startItemCooldown('dash_item', 600);
    source.playSound('random.orb');
    source.onScreenDisplay.setActionBar('Dashed!');
  });
});```
proven widget
weak beacon
proven widget
#

Ok, tysm

proven widget
#

@weak beacon Sorry to bother you, but how do I also add the cooldown to the dash? The item has the cooldown, but I can still use the dash as many times as I want (even flying without Creative).

weak beacon
proven widget
proven widget
#

forget it, I already fixed it