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

const bullets = ["wt:mg_bullet","wt:20mm_bullet","wt:12_7mm_bullet","wt:500kg_bomb","wt:7_92mm_bullet","wt:100_kg_bomb"];

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 mg_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");

    }

});