#Bow Ping.
1 messages · Page 1 of 1 (latest)
import { Player, world, system } from "@minecraft/server";
world.events.projectileHit.subscribe((arg,player) => {
if (arg.entityHit?.entity instanceof Player && arg.source instanceof Player) {
const soundOption = {
volume: 0.4,
pitch: 0.5,
};
arg.source.playSound("random.orb", soundOption);
};
});
// could someone also help me make it so it only works with a bow to please.
world.events.projectileHit.subscribe(data => {
const projectile = data.projectile
const shootingPlr = data.source
const hitPlr = data.entityHit
const health = hitPlr.entity.getComponent("health").current / 2
if (projectile.typeId == "minecraft:arrow" && hitPlr.entity.typeId == "minecraft:player") {
shootingPlr.playSound(`random.orb`)
shootingPlr.tell(`${hitPlr.entity.name}'s Health is now ${Math.floor(health)}`)
}
})
@wild bobcat there
idk if its the best way to do it but it works
tyy
world.events.projectileHit.subscribe(data => {
const projectile = data.projectile
const shootingPlr = data.source
const hitPlr = data.entityHit
if (projectile.typeId == "minecraft:arrow" && hitPlr.entity.typeId == "minecraft:player") {
let health = hitPlr.entity.getComponent("health").current / 2
shootingPlr.playSound(`random.orb`)
shootingPlr.tell(`${hitPlr.entity.name}'s Health is now ${Math.floor(health)}`)
}
})
@wild bobcat this seems a little better
let health = hitPlr.entity.getComponent("health").current / 2
leaving that outside cause a annoying console log
is there a way I can display a player health with player.nameTag =?
wdym?
like an actionbar or something
?
see
you can make custom playernametags
but Idk how to display health
i can remove there name
it can be anything
if (data.blockHit) {
return;
}``` also mb i removed that but put it back in
hitPlr.entity.nameTag = `${health}`
^ Theres an example
just use
target.nameTag = 'whatEver'
so I would just put ${health}?
yes
ty
but that will just make there name the number of their health
ye ik
hitPlr.entity.nameTag = ${hitPlr.entity.name}\nHealth: ${Math.floor(health)}
heres a better looking one
but you may wanna put that in a runSchedule
so it always is updated
hm
@tight topaz I forget stuff how do I define stuf
lemme try something
wait i dont know how
I always forget this
const?
const =...
or
let =...
k
const health = target.getComponent("health").current / 2
ty
target being
ty
whoever you defined