// why are you here?
// want to steal my code , right?
// wow , you are a loser 🤣🤣🤣
// you can learn with my code but don't steal it , if you want to use it , inbox me , okay?
// OWNER OF THIS ADDON : @PnTMCvn on Youtube
// Addon Made By PnTMC
// Addon Coded By PnTMC
// shut this down now
// Understand???
// click X or ALT + F4 right now
// I'M PnTMC !!!!!!!!!!!!!!
// Beware The Rain Add-ON MCPE Made , Coded By PnTMC
// Assets from Beware The Rain Mod
// You can read the README!!!.txt to know more


// My Discord : @pntytb
// My Youtube : @PnTMCvn













































// Coded by PnTMC

import { world , system } from "@minecraft/server";
world.afterEvents.entityDie.subscribe(pntmc => {
    const deadEntity = pntmc.deadEntity;
    const damagingEntity = pntmc.damageSource.damagingEntity;
    
    if (deadEntity.typeId == "minecraft:player" && damagingEntity.typeId == "pntmc:spider_skull") {
        damagingEntity.runCommandAsync("event entity @s pntmc:despawn");
    }
    if (deadEntity.typeId == "minecraft:player" && damagingEntity.typeId == "pntmc:rosemary") {
        deadEntity.runCommandAsync("function pntmc_rosemary_jumpscare");
    }
    if (deadEntity.typeId == "pntmc:vapor") {
        deadEntity.runCommandAsync("tag @a remove pntmcvaporjumpscares");
    }
    if (deadEntity.typeId == "minecraft:player") {
        deadEntity.runCommandAsync("tag @s remove pntmcvaporjumpscares");
    }
});
world.afterEvents.entityHurt.subscribe(pntmc => {
    const hurtEntity = pntmc.hurtEntity;
    const damagingEntity = pntmc.damageSource.damagingEntity;

    if (hurtEntity.typeId == "minecraft:player" && damagingEntity.typeId == "pntmc:valem") {
        damagingEntity.runCommandAsync("event entity @s pntmc:despawn");
        hurtEntity.runCommandAsync("effect @s resistance 300 255 true");
        hurtEntity.runCommandAsync("function pntmc_valem_kill_player");
        system.runTimeout(() => {
            hurtEntity.runCommandAsync("function pntmc_valem_jumpscare");
            system.runTimeout(() => {
                hurtEntity.runCommandAsync("kill @s");
                hurtEntity.runCommandAsync("effect @s clear")
            },45)
        },180)
    };

    if (hurtEntity.typeId == "minecraft:player" && damagingEntity.typeId == "pntmc:vapor") {
        hurtEntity.runCommandAsync("function pntmc_vapor_jumpscareend");
        hurtEntity.runCommandAsync("effect @s resistance 300 255 true");
        damagingEntity.runCommandAsync("function pntmc_vapor_afterkillplayer");
        system.runTimeout(() => {
            hurtEntity.runCommandAsync("kill @s");
            hurtEntity.runCommandAsync("effect @s clear")
        },62)
    }
});
// register SCRIPT EVENTS
system.afterEvents.scriptEventReceive.subscribe(pntmc => {
    const pntmcEvents = pntmc.id;
    const pntmcPlayerEvents = pntmc.sourceEntity;
    if (pntmcEvents == "pntmc:vaporjumpscares") {
        pntmcPlayerEvents.runCommandAsync("title @s title pntmcvaporscare." + Math.floor(Math.random() * 3 + 1));
        pntmcPlayerEvents.runCommandAsync("playsound pntmc:glitch1 @s")
    };
    if (pntmcEvents == "pntmc:randommessages1") {
        if (Math.floor(Math.random() * 3) + 1 == 1) {
            world.sendMessage("Just come closer . . .")
        } else if (Math.floor(Math.random() * 3) + 1 == 2) {
            world.sendMessage("Follow me . .")
        } else {
            world.sendMessage("Don't be afraid.")
        }
    };
    if (pntmcEvents == "pntmc:randommessages2") {
        if (Math.floor(Math.random() * 5) + 1 <= 3) {
            world.sendMessage("Rest now . . .");
        } else if (Math.floor(Math.random() * 5) + 1 == 4) {
            world.sendMessage("Sleep . . .");
        } else {
            world.sendMessage("Goodbye . . .");
        }
    }
});
// JUMPSCARES appear when Vapor chases
system.runInterval(() => {
    for (const player of world.getPlayers()) {
        player.runCommandAsync("execute as @e[type=pntmc:vapor] at @s run execute as @a[r=10] run function pntmc_vapor_jumpscares_function");
        player.runCommandAsync("execute as @e[type=pntmc:valem] at @s run execute as @a[r=10] run playsound pntmc:valemheart @s")
    }
},20);
system.runInterval(() => {
    for (const player of world.getPlayers()) {
        if (player.hasTag("pntmcvaporjumpscares")) {
            player.runCommandAsync("scriptevent pntmc:vaporjumpscares")
        }
    }
},200);
world.afterEvents.playerSpawn.subscribe(pntmc => {
    const pntmcinitialSpawn = pntmc.initialSpawn;
    if (pntmcinitialSpawn) {
        world.sendMessage("§o§9Like , Share And Subscribe for PnTMC for more§r")
    }
})
system.runInterval(() => {
    for (const player of world.getPlayers()) {
        player.runCommandAsync("weather rain 60")
    }
},36000);