#Any way to detect if the player has taken damage and if yes run a command without changing player.js

1 messages · Page 1 of 1 (latest)

sour marlin
#

I dont know how to do scripts tho. If its the last resort can anyone pls pls expalin how will it work

full wharf
#

Yes

#

Il get it now

#

@sour marlin

#
    const hitPlr = data.hurtEntity
    const dmgPlr = data.damageSource.damagingEntity
    if (hitPlr.typeId == "minecraft:player") {
        hitPlr.runCommandAsync(`title @s actionbar Hello There`)
        dmgPlr.runCommandAsync(`title @s actionbar Hello There`)
    }
})```
#

Hit plr is the player who hit the person and dmg is the person whos taken the hit hope it helps 👍

sour marlin
#

Tnx

solar falcon
full wharf
#

Yh

#

Shat tag

#

@solar falcon

solar falcon
full wharf
#

Alr

#

Wait

#

So what u want it to do explain i can do it for u

solar falcon
#

I wanted to add a hit system, so that "blood" would come out of the player when he was hit, you know.

#

With this system you created, I could use a command to make the particle execute

full wharf
#

Cant do that i cant lol

#

Yh i can do that

solar falcon
#

wdym?

full wharf
#

I make make the particle show

solar falcon
#

Oh

#

I have the particle

full wharf
#

Name?

solar falcon
#

I just need the script to make it happen

solar falcon
full wharf
#

Particle name?

#

Alr

#
    const hitPlr = data.hurtEntity;
    const dmgPlr = data.damageSource.damagingEntity;
    if (hitPlr.typeId == "minecraft:player" && hitPlr.hasTag("Test")) {
        hitPlr.runCommandAsync(`particle ~~1~ cs:blood`);
    }
})```
#

Try it lol

#

Only the player whos being hit does the particle

#

~~1~ is one block from the ground

#

So it looks better

#

But yh

solar falcon
#

ok, I'll try

#

I'll be right back

full wharf
#

Ok

solar falcon
#

It worked! Thanks

#

I just have one more question...

full wharf
#

Sure

solar falcon
#

How do I make the script IGNORE players that have the "test" tag?

#

Is !==

full wharf
#

Use it

#

If

#

Wait im confused

#

Th useb!

solar falcon
#

what?

full wharf
#

!

#

For people who dont have the tag

#

Like

solar falcon
full wharf
#

Yh

#

.!hastag

#

I think

#

Sjould be

solar falcon
#

like that:

full wharf
#

?

solar falcon
#

world.afterEvents.entityHurt.subscribe(data => {
const hitPlr = data.hurtEntity;
const dmgPlr = data.damageSource.damagingEntity;
if (hitPlr.typeId == "minecraft:player" && hitPlr.!hasTag("Test")) {
hitPlr.runCommandAsync(particle ~~1~ cs:blood);
}
})

#

Placing an exclamation mark before "hasTag"?

full wharf
#

Wait

solar falcon
#

k

full wharf
#
    const hitPlr = data.hurtEntity;
    const dmgPlr = data.damageSource.damagingEntity;
    if (hitPlr.typeId == "minecraft:player" && !hitPlr.hasTag("Test")) {
        hitPlr.runCommandAsync(`particle ~~1~ cs:blood`);
    }
})```
#

This should do it

#

See the ! By the &&

solar falcon
#

yh

full wharf
#

That is it

solar falcon
#

I'll try

#

brb

full wharf
#

So like commands execute at @a[!tag=Test]

solar falcon
#

yea ik, I only know why "!" Works because of commands

#

@full wharf

IT WORKED!

#

Thanks a lot man, you just improved my addon

#

I was using a really weird way to detect if players were hit lol