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


function strange_sounds(player) {  
    try {
          system.runTimeout(() => {
                    player.runCommandAsync("playsound sound.strange_sound_mcark @s");
                }, 40000);
    } catch (error) {
        console.error("Error en narcotic_arrow_plane_system:", error);
    }
}


// Funciones para narcotic_arrow_plane
function narcotic_arrow_plane_system(player) { 
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let narcotic_arrow_plane = false;
        let botellaIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:narcotic_arrow_plane") {
                narcotic_arrow_plane = true;
                botellaIndex = i;
                break;
            }
        }

        if (narcotic_arrow_plane) {
            if (!player.hasTag("reward_lvl3") && !player.hasTag("ad_required2")) {
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s arrow 1");
                player.runCommandAsync("give @s mc_ark:narcotic 1");

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title narcotic_arrow_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(botellaIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                player.runCommandAsync("give @s arrow 1 35");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title narcotic_arrow_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(botellaIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            }
        }
    } catch (error) {
        console.error("Error en narcotic_arrow_plane_system:", error);
    }
}

// Funciones para raptor_saddle_plane
function raptor_saddle_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let raptor_saddle_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:raptor_saddle_plane") {
                raptor_saddle_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (raptor_saddle_plane) {
            if (!player.hasTag("reward_lvl3") && !player.hasTag("ad_required2")) {
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s minecraft:leather 3");
                player.runCommandAsync("give @s mc_ark:wood_log 3");
                player.runCommandAsync("give @s minecraft:string 2");
                player.runCommandAsync("give @s minecraft:bone_block 1");

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title raptor_saddle_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:raptor_saddle");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title raptor_saddle_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en raptor_saddle_plane_system:", error);
    }
}

// Funciones para ghillie_chestplate_plane
function ghillie_chestplate_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let ghillie_chestplate_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:ghillie_chestplate_plane") {
                ghillie_chestplate_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (ghillie_chestplate_plane) {
            if (!player.hasTag("reward_lvl3") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s minecraft:azalea_leaves 2");
                player.runCommandAsync("give @s minecraft:tallgrass 3");
  

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title ghillie_chestplate_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:ghillie_chestplate");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title ghillie_chestplate_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en ghillie_chestplate_plane_system:", error);
    }
}
function ghillie_helmet_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let ghillie_helmet_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:ghillie_helmet_plane") {
                ghillie_helmet_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (ghillie_helmet_plane) {
            if (!player.hasTag("reward_lvl3") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s minecraft:azalea_leaves 4");
                player.runCommandAsync("give @s minecraft:tallgrass 4");
 

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title ghillie_helmet_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:ghillie_helmet");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title ghillie_helmet_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en ghillie_helmet_plane_system:", error);
    }
}
function ghillie_boots_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let ghillie_boots_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:ghillie_boots_plane") {
                ghillie_boots_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (ghillie_boots_plane) {
            if (!player.hasTag("reward_lvl3") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s minecraft:azalea_leaves 2");
                player.runCommandAsync("give @s minecraft:tallgrass 2");
 

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title ghillie_boots_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:ghillie_boots");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title ghillie_boots_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en ghillie_boots_plane_system:", error);
    }
}
function ghillie_leggings_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let ghillie_leggings_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:ghillie_leggings_plane") {
                ghillie_leggings_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (ghillie_leggings_plane) {
            if (!player.hasTag("reward_lvl3") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s minecraft:azalea_leaves 2");
                player.runCommandAsync("give @s minecraft:tallgrass 5");
 

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title ghillie_leggings_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:ghillie_leggings");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title ghillie_leggings_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en ghillie_leggings_plane_system:", error);
    }
}


// Funciones para wooden_club_plane
function wooden_club_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let wooden_club_plane = false;
        let botellaIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:wooden_club_plane") {
                wooden_club_plane = true;
                botellaIndex = i;
                break;
            }
        }

        if (wooden_club_plane) {
            if (!player.hasTag("reward_lvl3") && !player.hasTag("ad_required2")) {
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s mc_ark:wood_log 2");
                player.runCommandAsync("give @s stick 1");
                player.runCommandAsync("give @s mc_ark:thatch 1");

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title wooden_club_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(botellaIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:wooden_club");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title wooden_club_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(botellaIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            }
        }
    } catch (error) {
        console.error("Error en wooden_club_plane_system:", error);
    }
}

// Funciones para bowler_plane
function bowler_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let bowler_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:bowler_plane") {
                bowler_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (bowler_plane) {
            if (!player.hasTag("reward_lvl3") && !player.hasTag("ad_required2")) {
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s minecraft:leather 2");
                player.runCommandAsync("give @s minecraft:string 1");
                player.runCommandAsync("give @s mc_ark:rock 3");

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title bowler_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:bowler");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title bowler_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en bowler_plane_system:", error);
    }
}

// Funciones para whip_plane
function whip_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let whip_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:whip_plane") {
                whip_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (whip_plane) {
            if (!player.hasTag("reward_lvl3") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s mc_ark:wood_log 3");
                player.runCommandAsync("give @s minecraft:string 2");
                player.runCommandAsync("give @s minecraft:leather 1");
 

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title whip_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:whip");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title whip_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en whip_plane_system:", error);
    }
}

 
// Funciones para spear_plane
function spear_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let spear_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:spear_plane") {
                spear_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (spear_plane) {
            if (!player.hasTag("reward_lvl5") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s minecraft:leather 1");
                player.runCommandAsync("give @s mc_ark:wood_log 2");
                player.runCommandAsync("give @s minecraft:string 1");
                player.runCommandAsync("give @s minecraft:flint 1");
 

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title spear_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:spear");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title spear_plane_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en spear_plane_system:", error);
    }
}


// Funciones para pachy_saddle_plane
function pachy_saddle_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let pachy_saddle_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:pachy_saddle_plane") {
                pachy_saddle_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (pachy_saddle_plane) {
            if (!player.hasTag("reward_lvl5") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s minecraft:leather 3");
                player.runCommandAsync("give @s mc_ark:wood_log 3");
                player.runCommandAsync("give @s minecraft:string 2");
                player.runCommandAsync("give @s minecraft:bone 1");
 

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title pachy_saddle_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required5")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:pachy_saddle");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title pachy_saddle_plane_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en pachy_saddle_plane_system:", error);
    }
} 

// Funciones para whip_special_plane
function whip_special_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let whip_special_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:whip_special_plane") {
                whip_special_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (whip_special_plane) {
            if (!player.hasTag("reward_lvl10") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s mc_ark:wood_log 1");
                player.runCommandAsync("give @s minecraft:string 2");
                player.runCommandAsync("give @s minecraft:leather 1");
                player.runCommandAsync("give @s minecraft:iron_ingot 2");
 

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title whip_special_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:special_whip");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title whip_special_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en whip_special_plane_system:", error);
    }
}
// Funciones para chitin_chestplate_plane
function chitin_chestplate_plane_system(player) { 
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let chitin_chestplate_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:chitin_chestplate_plane") {
                chitin_chestplate_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (chitin_chestplate_plane) {
            if (!player.hasTag("reward_lvl10") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s mc_ark:chitin 8");
                player.runCommandAsync("give @s minecraft:leather_chestplate 1");
 

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title chitin_chestplate_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:chitin_chestplate");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title chitin_chestplate_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en chitin_chestplate_plane:", error);
    }
} 
// Funciones para iron_chestplate_plane
function iron_chestplate_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let iron_chestplate_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:iron_chestplate_plane") {
                iron_chestplate_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (iron_chestplate_plane) {
            if (!player.hasTag("reward_lvl10") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s minecraft:iron_ingot 5");
                player.runCommandAsync("give @s minecraft:iron_block 1");
                player.runCommandAsync("give @s minecraft:leather 2");



                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title iron_chestplate_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s minecraft:iron_chestplate");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title iron_chestplate_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en iron_chestplate_plane:", error);
    }
}
function iron_helmet_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let iron_helmet_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:iron_helmet_plane") {
                iron_helmet_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (iron_helmet_plane) {
            if (!player.hasTag("reward_lvl10") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s minecraft:iron_ingot 2");
                player.runCommandAsync("give @s minecraft:iron_block 1");
                player.runCommandAsync("give @s minecraft:leather 2");


                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title iron_helmet_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s minecraft:iron_helmet");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title iron_helmet_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en iron_helmet_plane:", error);
    }
}
function iron_boots_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let iron_boots_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:iron_boots_plane") {
                iron_boots_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (iron_boots_plane) {
            if (!player.hasTag("reward_lvl10") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s minecraft:iron_ingot 2");
                player.runCommandAsync("give @s minecraft:leather 2");


                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title iron_boots_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s minecraft:iron_boots");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title iron_boots_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en iron_boots_plane:", error);
    }
}
function iron_leggings_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let iron_leggings_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:iron_leggings_plane") {
                iron_leggings_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (iron_leggings_plane) {
            if (!player.hasTag("reward_lvl10") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s minecraft:iron_ingot 4");
                player.runCommandAsync("give @s minecraft:iron_block 1");
                player.runCommandAsync("give @s minecraft:leather 2");

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title iron_leggings_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s minecraft:iron_leggings");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title iron_leggings_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en iron_leggings_plane:", error);
    }
}


// Funciones para gas_mask_plane
function gas_mask_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let gas_mask_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:gas_mask_plane") {
                gas_mask_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (gas_mask_plane) {
            if (!player.hasTag("reward_lvl3") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s mc_ark:glass_ore_item 3");
                player.runCommandAsync("give @s minecraft:iron_ingot 3");
                player.runCommandAsync("give @s minecraft:leather_helmet 1");
 
 

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title gas_mask_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:gas_mask_plane");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title gas_mask_plane_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en gas_mask_plane_system:", error);
    }
}
 


function chitin_helmet_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let chitin_helmet_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:chitin_helmet_plane") {
                chitin_helmet_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (chitin_helmet_plane) {
            if (!player.hasTag("reward_lvl10") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s mc_ark:chitin 5");
                player.runCommandAsync("give @s minecraft:leather_helmet 1");
 

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title chitin_helmet_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:chitin_helmet");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title chitin_helmet_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en chitin_helmet_plane:", error);
    }
} 
function chitin_leggings_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let chitin_leggings_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:chitin_leggings_plane") {
                chitin_leggings_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (chitin_leggings_plane) {
            if (!player.hasTag("reward_lvl10") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s mc_ark:chitin 7");
                player.runCommandAsync("give @s minecraft:leather_leggings 1");
 

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title chitin_leggings_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:chitin_leggings");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title chitin_leggings_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en chitin_leggings_plane:", error);
    }
} 
function chitin_boots_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let chitin_boots_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:chitin_boots_plane") {
                chitin_boots_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (chitin_boots_plane) {
            if (!player.hasTag("reward_lvl10") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s mc_ark:chitin 4");
                player.runCommandAsync("give @s minecraft:leather_boots 1");
 

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title chitin_boots_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:chitin_boots");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title chitin_boots_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en chitin_boots_plane:", error);
    }
} 

function hook_crossbow_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let hook_crossbow_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:hook_crossbow_plane") {
                hook_crossbow_plane = true;
                planeIndex = i;
                break;
            }
        }

        if (hook_crossbow_plane) {
            if (!player.hasTag("reward_lvl18") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s mc_ark:wood_log 1");
                player.runCommandAsync("give @s minecraft:crossbow 1");
                player.runCommandAsync("give @s minecraft:iron_ingot 2");
                player.runCommandAsync("give @s minecraft:iron_block 1");
                player.runCommandAsync("give @s minecraft:string 2");
 

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title hook_crossbow_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:hook_crossbow");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title hook_crossbow_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en hook_crossbow_plane:", error);
    }
} 

function hook_plane_system(player) {
    try {
        const inventory = player.getComponent("minecraft:inventory").container;
        let hook_plane = false;
        let planeIndex = -1;

        for (let i = 0; i < inventory.size; i++) {
            const item = inventory.getItem(i);
            if (item?.typeId === "mc_ark:hook_plane") {
                hook_plane = true;
                planeIndex = i;
                break;
            }
        }
 
        if (hook_plane) {
            if (!player.hasTag("reward_lvl18") && !player.hasTag("ad_required2")) { 
                player.runCommandAsync("gamerule sendcommandfeedback false");
                player.runCommandAsync("give @s minecraft:iron_ingot 3");
                player.runCommandAsync("give @s minecraft:string 3");
 

                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s title hook_ad_required2");
                player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run tag @s add ad_required2");
                player.runCommandAsync("gamerule sendcommandfeedback true");
                inventory.setItem(planeIndex, undefined);

                system.runTimeout(() => {
                    player.runCommandAsync("tag @s remove ad_crafting3");
                    player.runCommandAsync("tag @s remove ad_required2");
                    player.runCommandAsync("execute as @s[tag=!ad_newrecipe1] run execute as @s[tag=!ad_required2] run title @s clear");
                }, 50);
            } else {
                if (!player.hasTag("ad_required2")) {
                    player.runCommandAsync("gamerule sendcommandfeedback false");
                    player.runCommandAsync("playsound sound.crafting_mc_ark @s");
                    player.runCommandAsync("give @s mc_ark:hook_ammo");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run tag @s add ad_crafting3");
                    player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s title hook_ad_crafting3");
                    player.runCommandAsync("gamerule sendcommandfeedback true");

                    inventory.setItem(planeIndex, undefined);

                    system.runTimeout(() => {
                        player.runCommandAsync("tag @s remove ad_crafting3");
                        player.runCommandAsync("execute as @s[tag=!ad_required2] run execute as @s[tag=!ad_newrecipe1] run title @s clear");
                    }, 50);
                }
            } 
        }
    } catch (error) {
        console.error("Error en hook_plane:", error);
    }
} 

// Eventos para ambos planos
world.afterEvents.itemUse.subscribe((event) => {
    try {
        const player = event.source;
        hook_plane_system(player);
        hook_crossbow_plane_system(player);
    narcotic_arrow_plane_system(player);
        whip_plane_system(player);
        wooden_club_plane_system(player);
        ghillie_chestplate_plane_system(player);
        ghillie_helmet_plane_system(player);
        ghillie_leggings_plane_system(player);
        ghillie_boots_plane_system(player);
        bowler_plane_system(player);
        pachy_saddle_plane_system(player);
        raptor_saddle_plane_system(player);
        spear_plane_system(player);
 
        gas_mask_plane_system(player);
    iron_chestplate_plane_system(player);
    iron_helmet_plane_system(player);
    iron_boots_plane_system(player);
    iron_leggings_plane_system(player);
        chitin_chestplate_plane_system(player);
        chitin_leggings_plane_system(player);
        chitin_helmet_plane_system(player);
        chitin_boots_plane_system(player);
        whip_special_plane_system(player);

    } catch (error) {
        console.error("Error en itemUse event:", error);
    }
});

world.afterEvents.playerSpawn.subscribe((event) => {
    try {
        const player = event.player;
 
    narcotic_arrow_plane_system(player);
        whip_plane_system(player);
        wooden_club_plane_system(player);
        ghillie_chestplate_plane_system(player);
        ghillie_helmet_plane_system(player);
        ghillie_leggings_plane_system(player);
        ghillie_boots_plane_system(player);
        bowler_plane_system(player);
        pachy_saddle_plane_system(player);
        hook_plane_system(player);
        hook_crossbow_plane_system(player);
        raptor_saddle_plane_system(player);
        spear_plane_system(player);
        gas_mask_plane_system(player);
    iron_chestplate_plane_system(player);
    iron_helmet_plane_system(player);
    iron_boots_plane_system(player);
    iron_leggings_plane_system(player);
        chitin_chestplate_plane_system(player);
        chitin_leggings_plane_system(player);
        chitin_helmet_plane_system(player);
        chitin_boots_plane_system(player);
        whip_special_plane_system(player);
    } catch (error) {
        console.error("Error en playerSpawn event:", error);
    } 
});

system.runInterval(() => { 
    try {
        const players = world.getPlayers();
        for (const player of players) {
 
        hook_plane_system(player);
        hook_crossbow_plane_system(player);
    narcotic_arrow_plane_system(player);
        whip_plane_system(player);
        wooden_club_plane_system(player);
        ghillie_chestplate_plane_system(player);
        ghillie_helmet_plane_system(player);
        ghillie_leggings_plane_system(player);
        ghillie_boots_plane_system(player);
        bowler_plane_system(player);
        pachy_saddle_plane_system(player);
        raptor_saddle_plane_system(player);
        spear_plane_system(player);
        gas_mask_plane_system(player);
    iron_chestplate_plane_system(player);
    iron_helmet_plane_system(player);
    iron_boots_plane_system(player);
    iron_leggings_plane_system(player);
        chitin_chestplate_plane_system(player);
        chitin_leggings_plane_system(player);
        chitin_helmet_plane_system(player);
        chitin_boots_plane_system(player);
        whip_special_plane_system(player);
        strange_sounds(player);
        }
    } catch (error) {
        console.error("Error en runInterval:", error);
    }
}, 20);


// El tag pross_lvlx detecta la secuencia para no sobre poner titulos


// Nueva función para detectar el tag "new_recipes_lvl3"
function verificarTagNewRecipesLvl3(player) { 

        if ((player.hasTag("new_recipes_lvl3")) && (!player.hasTag("finish_lvl3")) && (!player.hasTag("pross_lvl15"))) {
            
            
            
                player.runCommandAsync("tag @s add pross_lvl3");
                player.runCommandAsync("tag @s add ad_newrecipe1");
                player.runCommandAsync("tag @s remove ad_crafting3");
                player.runCommandAsync("tag @s remove ad_required2");

                player.runCommandAsync("title @s[tag=not_engram_lvl3_wooden_club_1] title wooden_club_ad_newrecipe1");
                player.runCommandAsync("title @s[tag=not_engram_lvl3_bowler_1] title bowler_ad_newrecipe1");
                    player.runCommandAsync("playsound sound.new_recipe_mc_ark @s");
                    player.runCommandAsync("tag @s add finish_lvl3"); 
                    // Intentar esto y de no funcionar, veridicar el clear 

                system.runTimeout(() => {
                    

 
                player.runCommandAsync("title @s  title bowler_ad_newrecipe1"); 
                    player.runCommandAsync("execute as @s[tag=!new_recipes_lvl5] run title @s[tag=not_engram_lvl3_wooden_club_1] clear"); 
                    player.runCommandAsync("playsound sound.new_recipe_mc_ark @s");
                    player.runCommandAsync("tag @s[tag=not_engram_lvl3_wooden_club_1] add yes_engram_lvl3_wooden_club_1");
                    player.runCommandAsync("tag @s[tag=not_engram_lvl3_wooden_club_1] remove not_engram_lvl3_wooden_club_1");
                    player.runCommandAsync("tag @s remove ad_newrecipe1");
                    player.runCommandAsync("tag @s remove new_recipes_lvl3"); 
                    // Reiniciar la función invocando la misma función nuevamente.
                    
                }, 100);
                system.runTimeout(() => {

                      
                    player.runCommandAsync("tag @s[tag=not_engram_lvl3_bowler_1] add yes_engram_lvl3_bowler_1");
                     player.runCommandAsync("tag @s[tag=not_engram_lvl3_bowler_1] remove not_engram_lvl3_bowler_1");

                    player.runCommandAsync("tag @s remove ad_newrecipe1");
                    player.runCommandAsync("tag @s remove new_recipes_lvl3");
                player.runCommandAsync("execute as @s[tag=yes_engram_lvl3_bowler_1] run title @s[tag=not_engram_lvl3_whip_1] title whip_ad_newrecipe1");
                    player.runCommandAsync("playsound sound.new_recipe_mc_ark @s");
                    // Reiniciar la función invocando la misma función nuevamente.
                    
                }, 200);  
                system.runTimeout(() => {
 
                player.runCommandAsync("tag @s remove pross_lvl3");
                    player.runCommandAsync("tag @s[tag=not_engram_lvl3_whip_1] add yes_engram_lvl3_whip_1");
                     player.runCommandAsync("tag @s[tag=not_engram_lvl3_whip_1] remove not_engram_lvl3_whip_1");
                    player.runCommandAsync("execute as @s[tag=!new_recipes_lvl5] run title @s[tag=not_engram_lvl3_whip_1] clear");
                    player.runCommandAsync("execute as @s[tag=!new_recipes_lvl5] run title @s[tag=yes_engram_lvl3_whip_1] clear"); 
                    player.runCommandAsync("tag @s remove ad_newrecipe1");

                    player.runCommandAsync("tag @s remove new_recipes_lvl3");


                    // Reiniciar la función invocando la misma función nuevamente.
                    
                }, 300);  
                system.runTimeout(() => {
                               player.runCommandAsync("title @s clear");
                    
                }, 380);  
                
            }
    
} 
 
// Nueva función para detectar el tag "new_recipes_lvl5"
function verificarTagNewRecipesLvl5(player) { 
    try {  
        if (player.hasTag("new_recipes_lvl5") && (!player.hasTag("pross_lvl3")) && (!player.hasTag("finish_lvl5")) && (!player.hasTag("pross_lvl15"))) { 
            
            
                player.runCommandAsync("tag @s add pross_lvl5");
                player.runCommandAsync("tag @s add ad_newrecipe1");
                player.runCommandAsync("tag @s remove ad_crafting3");
                player.runCommandAsync("tag @s remove ad_required2");


                    player.runCommandAsync("tag @s add finish_lvl5"); 

                system.runTimeout(() => {
                player.runCommandAsync("title @s title pachy_saddle_ad_newrecipe1");

 

                    player.runCommandAsync("tag @s[tag=not_engram_lvl5_pachy_saddle_plane_1] add yes_engram_lvl5_pachy_saddle_plane_1");
                    player.runCommandAsync("tag @s[tag=not_engram_lvl5_pachy_saddle_plane_1] remove not_engram_lvl5_pachy_saddle_plane_1");





                    // Reiniciar la función invocando la misma función nuevamente.
                    player.runCommandAsync("playsound sound.new_recipe_mc_ark @s");
                }, 100); 
                system.runTimeout(() => {
                player.runCommandAsync("title @s title gas_mask_ad_newrecipe1");
 

                    player.runCommandAsync("tag @s[tag=not_engram_lvl5_gas_mask_plane_1] add yes_engram_lvl5_gas_mask_plane_1");
                    player.runCommandAsync("tag @s[tag=not_engram_lvl5_gas_mask_plane_1] remove not_engram_lvl5_gas_mask_plane_1");

   

                    player.runCommandAsync("playsound sound.new_recipe_mc_ark @s");

                    // Reiniciar la función invocando la misma función nuevamente.
                    
                }, 200); 
                system.runTimeout(() => {
                player.runCommandAsync("title @s title spear_ad_newrecipe1");
 

                    player.runCommandAsync("tag @s[tag=not_engram_lvl5_spear_plane_1] add yes_engram_lvl5_spear_plane_1");
                    player.runCommandAsync("tag @s[tag=not_engram_lvl5_spear_plane_1] remove not_engram_lvl5_spear_plane_1");
                    player.runCommandAsync("playsound sound.new_recipe_mc_ark @s");
 

  


                    // Reiniciar la función invocando la misma función nuevamente.
                    
                }, 300); 
                system.runTimeout(() => {
                               player.runCommandAsync("title @s clear");
                    player.runCommandAsync("tag @s remove ad_newrecipe1");
                    player.runCommandAsync("tag @s remove new_recipes_lvl5");
                player.runCommandAsync("tag @s remove pross_lvl5");
                    player.runCommandAsync("tag @s add finish_lvl5"); 
                }, 400);  
                
                
            }
    } catch (error) {
        console.error("Error en verificarTagNewRecipesLvl5:", error);
    }
}   
 
// Nueva función para detectar el tag "new_recipes_lvl8"
function verificarTagNewRecipesLvl8(player) {
    try {  
        if ((player.hasTag("new_recipes_lvl8")) && (!player.hasTag("pross_lvl3")) && (!player.hasTag("new_recipes_lvl5")) && (!player.hasTag("finish_lvl8")) && (!player.hasTag("pross_lvl15"))) { 
                player.runCommandAsync("tag @s add pross_lvl8");
                player.runCommandAsync("tag @s add ad_newrecipe1");
                player.runCommandAsync("tag @s remove ad_crafting3");
                player.runCommandAsync("tag @s remove ad_required2");

                player.runCommandAsync("execute as @s[tag=!new_recipes_lvl5] run title @s[tag=not_engram_lvl8_narcotic_arrow_1] title narcotic_arrow_ad_newrecipe1");

                    player.runCommandAsync("tag @s add finish_lvl8");  
                    player.runCommandAsync("playsound sound.new_recipe_mc_ark @s");
                system.runTimeout(() => {
                player.runCommandAsync("title @s title raptor_saddle_ad_newrecipe1");

                    player.runCommandAsync("tag @s[tag=not_engram_lvl8_narcotic_arrow_1] add yes_engram_lvl8_narcotic_arrow_1");
                    player.runCommandAsync("tag @s[tag=not_engram_lvl8_narcotic_arrow_1] remove not_engram_lvl8_narcotic_arrow_1");
                    player.runCommandAsync("tag @s remove ad_newrecipe1");
                    player.runCommandAsync("tag @s remove new_recipes_lvl8");

                    // Reiniciar la función invocando la misma función nuevamente.
                    player.runCommandAsync("playsound sound.new_recipe_mc_ark @s");
                }, 100);
                system.runTimeout(() => {
                    player.runCommandAsync("tag @s[tag=not_engram_lvl8_raptor_saddle_1] add yes_engram_lvl8_raptor_saddle_1");
                     player.runCommandAsync("tag @s[tag=not_engram_lvl8_raptor_saddle_1] remove not_engram_lvl8_raptor_saddle_1");



                player.runCommandAsync("execute as @s[tag=yes_engram_lvl8_raptor_saddle_1] run title @s[tag=not_engram_lvl8_ghillie_chestplate_1] title ghillie_chestplate_ad_newrecipe1");

                    // Reiniciar la función invocando la misma función nuevamente.
                    player.runCommandAsync("playsound sound.new_recipe_mc_ark @s");
                }, 200);  
                system.runTimeout(() => {
             
             
                    player.runCommandAsync("tag @s[tag=not_engram_lvl8_ghillie_chestplate_1] add yes_engram_lvl8_ghillie_chestplate_1");
                     player.runCommandAsync("tag @s[tag=not_engram_lvl8_ghillie_chestplate_1] remove not_engram_lvl8_ghillie_chestplate_1");
                    player.runCommandAsync("title @s[tag=not_engram_lvl8_ghillie_chestplate_1] clear");
                    player.runCommandAsync("title @s[tag=yes_engram_lvl8_ghillie_chestplate_1] clear"); 
                    player.runCommandAsync("tag @s remove ad_newrecipe1");

                    player.runCommandAsync("tag @s remove new_recipes_lvl8");
                player.runCommandAsync("tag @s remove pross_lvl8");

                    // Reiniciar la función invocando la misma función nuevamente.
                      
                }, 300);  
                system.runTimeout(() => {
                               player.runCommandAsync("title @s clear");
                    player.runCommandAsync("tag @s remove new_recipes_lvl8");
                }, 330);  

            }
    } catch (error) {
        console.error("Error en verificarTagNewRecipesLvl8:", error);
    }
}

// Nueva función para detectar el tag "new_recipes_lvl10"
function verificarTagNewRecipesLvl10(player) {
    try {  
        if ((player.hasTag("new_recipes_lvl10")) && (!player.hasTag("pross_lvl3")) && (!player.hasTag("pross_lvl5")) && (!player.hasTag("new_recipes_lvl8")) && (!player.hasTag("finish_lvl10")) && (!player.hasTag("pross_lvl15"))) { 
                player.runCommandAsync("tag @s add pross_lvl10");
                player.runCommandAsync("tag @s add ad_newrecipe1");
                player.runCommandAsync("tag @s remove ad_crafting3");
                player.runCommandAsync("tag @s remove ad_required2");

                    player.runCommandAsync("tag @s remove new_recipes_lvl10");




                system.runTimeout(() => {
                player.runCommandAsync("title @s title whip_special_ad_newrecipe1");
 



 
                    player.runCommandAsync("tag @s[tag=not_engram_lvl10_whip_special_1] add yes_engram_lvl10_whip_special_1");
                    player.runCommandAsync("tag @s[tag=not_engram_lvl10_whip_special_1] remove not_engram_lvl10_whip_special_1");
                    player.runCommandAsync("tag @s remove ad_newrecipe1");
                    player.runCommandAsync("tag @s remove new_recipes_lvl10");
                    player.runCommandAsync("playsound sound.new_recipe_mc_ark @s");
                    // Reiniciar la función invocando la misma función nuevamente.
                      
                }, 100);
                system.runTimeout(() => {
                player.runCommandAsync("title @s title whip_special_ad_newrecipe1");
                player.runCommandAsync("title @s title chitin_chestplate_ad_newrecipe1");
                    player.runCommandAsync("tag @s[tag=not_engram_lvl10_chitin_chestplate_1] add yes_engram_lvl10_chitin_chestplate_1");
                     player.runCommandAsync("tag @s[tag=not_engram_lvl10_chitin_chestplate_1] remove not_engram_lvl10_chitin_chestplate_1");

                    player.runCommandAsync("tag @s remove ad_newrecipe1");
                    player.runCommandAsync("tag @s remove new_recipes_lvl10");
                    // Reiniciar la función invocando la misma función nuevamente.
                    player.runCommandAsync("playsound sound.new_recipe_mc_ark @s");
                }, 200);  
                system.runTimeout(() => {
                               player.runCommandAsync("title @s clear");
                player.runCommandAsync("tag @s remove pross_lvl10");
 
                }, 280);  

                    player.runCommandAsync("tag @s add finish_lvl10");  
            }  
    } catch (error) {  
        console.error("Error en verificarTagNewRecipesLvl10:", error);
    }  
}  

function verificarTagNewRecipesLvl15(player) {
    try {     
                if ((player.hasTag("new_recipes_lvl15")) && (!player.hasTag("pross_lvl3")) && (!player.hasTag("pross_lvl5")) &&  (player.hasTag("finish_lvl8")) && (!player.hasTag("pross_lvl10")) && (!player.hasTag("new_recipes_lvl10")) && (!player.hasTag("finish_lvl15"))) { 
               
 
                player.runCommandAsync("tag @s add pross_lvl15");
                player.runCommandAsync("tag @s add ad_newrecipe1");
                player.runCommandAsync("tag @s remove ad_crafting3");
                player.runCommandAsync("tag @s remove ad_required2"); 




                system.runTimeout(() => {
                player.runCommandAsync("title @s title iron_chestplate_ad_newrecipe1");
 
                    player.runCommandAsync("tag @s[tag=not_engram_lvl15_iron_chestplate_plane_1] add yes_engram_lvl15_iron_chestplate_plane_1");
                    player.runCommandAsync("tag @s[tag=not_engram_lvl5_pachy_saddle_plane_1] remove not_engram_lvl15_iron_chestplate_plane_1");

                    player.runCommandAsync("tag @s remove ad_newrecipe1");
                    player.runCommandAsync("tag @s remove new_recipes_lvl15");
                player.runCommandAsync("tag @s remove pross_lvl15");


                    player.runCommandAsync("playsound sound.new_recipe_mc_ark @s");

                    // Reiniciar la función invocando la misma función nuevamente.
                    
                }, 100); 
                system.runTimeout(() => {
                               player.runCommandAsync("title @s clear");
                    
                }, 200);  
                    player.runCommandAsync("tag @s add finish_lvl15");
            }
    } catch (error) {
        console.error("Error en verificarTagNewRecipesLvl15:", error);
    }
} 
 
 
function verificarTagNewRecipesLvl18(player) {
    try {  
                if ((player.hasTag("new_recipes_lvl18")) && (!player.hasTag("pross_lvl3")) && (!player.hasTag("pross_lvl5")) &&  (player.hasTag("finish_lvl15")) && (!player.hasTag("pross_lvl15")) && (!player.hasTag("new_recipes_lvl15")) && (!player.hasTag("finish_lvl18"))) { 
               
                player.runCommandAsync("tag @s add pross_lvl18");
                player.runCommandAsync("tag @s add ad_newrecipe1");
                player.runCommandAsync("tag @s remove ad_crafting3");
                player.runCommandAsync("tag @s remove ad_required2"); 

                    player.runCommandAsync("tag @s remove new_recipes_lvl18");




                system.runTimeout(() => {
                player.runCommandAsync("title @s title hook_crossbow_ad_newrecipe1");
 



 
                    player.runCommandAsync("tag @s[tag=not_engram_lvl18_hook_crossbow_1] add yes_engram_lvl18_hook_crossbow_1");
                    player.runCommandAsync("tag @s[tag=not_engram_lvl18_hook_crossbow_1] remove not_engram_lvl18_hook_crossbow_1");
                    player.runCommandAsync("tag @s remove ad_newrecipe1");
                    player.runCommandAsync("tag @s remove new_recipes_lvl18");
                    player.runCommandAsync("playsound sound.new_recipe_mc_ark @s");
                    // Reiniciar la función invocando la misma función nuevamente.
                      
                }, 100);
                system.runTimeout(() => {
                player.runCommandAsync("title @s title hook_crossbow_ad_newrecipe1");
                player.runCommandAsync("title @s title hook_ad_newrecipe1");
                    player.runCommandAsync("tag @s[tag=not_engram_lvl18_hook_1] add yes_engram_lvl18_hook_1");
                     player.runCommandAsync("tag @s[tag=not_engram_lvl18_hook_1] remove not_engram_lvl18_hook_1");

                    player.runCommandAsync("tag @s remove ad_newrecipe1");
                    player.runCommandAsync("tag @s remove new_recipes_lvl18");
                    // Reiniciar la función invocando la misma función nuevamente.
                    player.runCommandAsync("playsound sound.new_recipe_mc_ark @s");
                }, 200);  
                system.runTimeout(() => {
                               player.runCommandAsync("title @s clear");
                player.runCommandAsync("tag @s remove pross_lvl18");
 
                }, 280);  

                    player.runCommandAsync("tag @s add finish_lvl18");  
            }  
    } catch (error) {  
        console.error("Error en verificarTagNewRecipesLvl18:", error);
    }  
}  
 

// Ejecutar la nueva función en cada tick para verificar constantemente
system.runInterval(() => {
    try { 
        const players = world.getPlayers();
        for (const player of players) {
            verificarTagNewRecipesLvl3(player);
            verificarTagNewRecipesLvl5(player);
            verificarTagNewRecipesLvl8(player);
            verificarTagNewRecipesLvl10(player);
            verificarTagNewRecipesLvl15(player);
            verificarTagNewRecipesLvl18(player);
        }  
    } catch (error) {
        console.error("Error en runInterval de verificarTagNewRecipesLvl:", error);
    }
}, 1);    
