#Bow Ping.

1 messages · Page 1 of 1 (latest)

wild bobcat
#

Could someone please help me make it when the player gets hit with a bow it tells them the health and just with a bow not any other projectile

#
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.
tight topaz
#
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

tight topaz
#
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

wild bobcat
#

what diffrence

#

?

tight topaz
#

let health = hitPlr.entity.getComponent("health").current / 2

wild bobcat
#

ah

#

ty

#

wait

tight topaz
#

leaving that outside cause a annoying console log

wild bobcat
#

is there a way I can display a player health with player.nameTag =?

tight topaz
wild bobcat
#

it says undefined

#

oh

#

ty

tight topaz
#

like an actionbar or something

#

?

wild bobcat
#

see

#

you can make custom playernametags

#

but Idk how to display health

#

i can remove there name

#

it can be anything

tight topaz
#
    if (data.blockHit) {
        return;
    }``` also mb i removed that but put it back in
tight topaz
#

^ Theres an example

#

just use
target.nameTag = 'whatEver'

wild bobcat
#

so I would just put ${health}?

tight topaz
#

yes

wild bobcat
#

ty

tight topaz
#

but that will just make there name the number of their health

wild bobcat
#

ye ik

tight topaz
#

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

wild bobcat
#

hm

#

@tight topaz I forget stuff how do I define stuf

#

lemme try something

#

wait i dont know how

#

I always forget this

#

const?

tight topaz
#

const =...
or
let =...

wild bobcat
#

ok I have const {health} =

#

idk what to do

tight topaz
#

nope

#

const health =

#

so

wild bobcat
#

k

tight topaz
#

const health = target.getComponent("health").current / 2

wild bobcat
#

ty

tight topaz
#

target being

wild bobcat
#

ty

tight topaz
#

whoever you defined

wild bobcat
#

ye

#

health is not initalized

#

@tight topaz

#

sorry for pings but your only one helping me:(

#

😦

#

oh it a function I dont have it 😦