#Gateway code issued

14 messages · Page 1 of 1 (latest)

blissful berry
#
onEvent("entity.hurt", event => {
    let hurtEntity = event.entity
    let entityType = hurtEntity.getType()
    console.log(`entityType: ${entityType}`);
    
    if (entityType == "minecraft:ender_dragon") {
        let player = event.source.getActual()
        console.log(`player: ${player}`);
        
        if (player) {
            if (player.isPlayer()) {
                let lastgate = hurtEntity.persistentData.lastretaliationgate
                player.tell(`lastgate : ${lastgate}`)

                let hpPercent = (hurtEntity.getHealth() / hurtEntity.getMaxHealth()) * 100
                player.tell(`hpPercent: ${hpPercent}`)

                if (lastgate > 1 && hpPercent <= lastgate) {
                    //dragon summons a reinforcement gate at 100%, 75%, 50% and 25% health
                    let x = Math.floor(player.x)
                    let y = Math.floor(player.y)
                    let z = Math.floor(player.z)
                    player.tell(`coord: ${x}, ${y}, ${z}`)
                    
                    let command = `execute in minecraft:the_end run open_gateway ${x} ${y} ${z} gateways:dragon_retaliation`
                    player.tell("The Dragon roars in anger in response to your attack, and summons reinforcements")
                    hurtEntity.persistentData.lastretaliationgate -= 25
                    player.getServer().runCommandSilent(command)
                }
            }
        }
    }
})

The code's intention is that it would spawn a gateway (from gateways to eternity) on specific hp intervals during the ender dragon bossfight, specifically 25%, 50%, and 75%. No errors are thrown back at me but at the same time it isn't working. Anything wrong with the code that could be causing it?

rose narwhalBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

vague prism
#

Which version are you on? onEvent should be for 1.18 and earlier.

blissful berry
#

oh wait, old code let me get the new one up

#
EntityEvents.hurt(event => {
    let hurtEntity = event.entity
    let entityType = hurtEntity.getType()
    console.log(`entityType: ${entityType}`);
    
    if (entityType == "minecraft:ender_dragon") {
        let player = event.source.getActual()
        console.log(`player: ${player}`);
        
        if (player) {
            if (player.isPlayer()) {
                let lastgate = hurtEntity.persistentData.lastretaliationgate
                player.tell(`lastgate : ${lastgate}`)

                let hpPercent = (hurtEntity.getHealth() / hurtEntity.getMaxHealth()) * 100
                player.tell(`hpPercent: ${hpPercent}`)

                if (lastgate > 1 && hpPercent <= lastgate) {
                    //dragon summons a reinforcement gate at 100%, 75%, 50% and 25% health
                    let x = Math.floor(player.x)
                    let y = Math.floor(player.y)
                    let z = Math.floor(player.z)
                    player.tell(`coord: ${x}, ${y}, ${z}`)
                    
                    let command = `execute in minecraft:the_end run open_gateway ${x} ${y} ${z} gateways:dragon_retaliation`
                    player.tell("The Dragon roars in anger in response to your attack, and summons reinforcements")
                    hurtEntity.persistentData.lastretaliationgate -= 25
                    player.getServer().runCommandSilent(command)
                }
            }
        }
    }
})
vague prism
#

How does the log look like?

blissful berry
#

i'll check again

blissful berry
#

just checked the logs through testing, the hp check works but the 'lastgate' variable doesn't

#

let lastgate = hurtEntity.persistentData.lastretaliationgate

this line is probably wrong but I don't know how to fix it

blissful berry
#

nvm fixed it, just need the gateway to spawn on the ground now

blissful berry
#

...i'm at a loss here as well. I was thinking of trying a code from another user's thing but ig asking for professional help would be a better first option

blissful berry
# vague prism So the thing is fixed now?

the initial problem is fixed, took a while but now i'm trying to add new functionality to have the gateway spawn on the ground regardless of what height the player is at (the gateway sometimes breaks if its too high up in the air and has no ground to spawn the mobs)

vague prism