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

const bullets = ["wt:he76shell_bullet","wt:m3_he_shell","wt:m3_ap_shell","wt:ap76_shell","wt:m4a1_he_shell","wt:m4a1_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 us_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");

    }

});