#[solved] Why can't I use "/scriptevent script:swing" in Minecraft version 1.21.70?

1 messages · Page 1 of 1 (latest)

lean pond
#
import { system, Player } from '@minecraft/server';

////Player/////

system.afterEvents.scriptEventReceive.subscribe(({ sourceEntity: player, id }) => {
    if (id !== 'script:swing') return;

    // Verificar se o sourceEntity é um jogador
    if (!(player instanceof Player)) return;

    // Obter a direção de visão do jogador
    const { x, y, z } = player.getViewDirection();

    // Normalizar o vetor horizontal (x, z) para garantir direção consistente
    const horizontalMagnitude = Math.sqrt(x * x + z * z);
    const normalizedX = x / horizontalMagnitude;
    const normalizedZ = z / horizontalMagnitude;

    // Ajustar a força para alcançar 10 blocos
    const horizontalForce = 1.2; // Valor ajustado para 10 blocos
    const verticalForce = 0.1; // Ajuste para simular um leve salto (opcional)

    // Aplicar o knockback ao jogador
    player.applyKnockback(normalizedX, normalizedZ, horizontalForce, verticalForce);
})
daring shoal
lean pond
#

I will test it right now. Thank you very much!

lean pond
#

It worked perfectly!