import { world } from "@minecraft/server";

world.afterEvents.entityHurt.subscribe((event) => {
    const damagingEntity = event.damageSource.damagingEntity;
    const hurtEntity = event.hurtEntity;
    
    if (!damagingEntity || damagingEntity.typeId !== "minecraft:player") return;
    if (!hurtEntity.hasComponent("health")) return;
    
    const health = hurtEntity.getComponent("health");
    if (health.currentValue > 0) {
        damagingEntity.runCommandAsync("event entity @s hitmarker").catch(() => {});
    } else {
        damagingEntity.runCommandAsync("event entity @s hitmarker_kill").catch(() => {});
    }
});