import {
    world,
    system,
    EntityDamageCause
} from "@minecraft/server";

const bullets = ["wt:kwk40_he_shell","wt:kwk40_shell","wt:kwk46_he_shell","wt:kwk46_ap_shell","wt:kwk42_he_shell","wt:kwk42_ap_shell","wt:kwk36_he_shell","wt:kwk36_ap_shell"];

world.afterEvents.entityDie.subscribe((event) => {

    const {
        damageSource,
        deadEntity
    } = event;

    const {
        cause,
        damagingEntity,
        damagingProjectile
    } = damageSource;

    if (cause === EntityDamageCause.projectile && bullets.includes(damagingProjectile?.typeId)) {

        damagingEntity?.runCommand("execute as @s run function german_target_destroyed");

    }

});

world.afterEvents.projectileHitEntity.subscribe((event) => {

    const {
        dimension,
        hitVector,
        location,
        projectile,
        source
    } = event;

    const entityHit = event.getEntityHit()?.entity;

    if (bullets.includes(projectile?.typeId)) {

        source?.runCommand("title @s actionbar Hit");

    }

});