#How to detect when an entity takes damage by an arrow

1 messages · Page 1 of 1 (latest)

stray coyote
#

It is in the version 26.1

fathom barnBOT
fathom barnBOT
#

-# (helpers summoned) <@&1166082198152159386> <@&1202694677766348840>

dusty sinew
#

Depends a little bit about what all you want to be checking. The most consistent and reliable way is to make a custom enchantent that you either apply to the bow, or modify the data of the arrows to make them think they were shot by a how with that enchantment, but either may not be ideal for your given usecase

stray coyote
#

I just want it to play a function that deals damage to surrounding entities

dusty sinew
#

What is "it"

stray coyote
#

The entity it hit

#

Or the arrow as it hits the entity

dusty sinew
#

...okay, that doesn't give me any new or useful information to provide a different answer than what I already have

stray coyote
#

I'll try out what you said

#

Oh yeah, I'm using /summon for the arrows

#

with a music disc

#

How do I do the modifying data of the arrow and which effect do I use

stray coyote
#

So how do i modify the data?

dusty sinew
#

If you're summoning the arrows, just define the NBT of it when you do so

#

You care about the weapon nbt

stray coyote
#

It isn't working

#

summon arrow ~ ~ ~ {Tags:["test_arrow"],weapon:{id:bow,components:{enchantments:{"trial_by_combat:test":1}}}}

This is what it's using currently

dusty sinew
#

Looks like correct NBT, so let's see the enchantment

stray coyote
#

{
"criteria": {
"example": {
"trigger": "minecraft:player_hurt_entity",
"conditions": {
"damage": {
"type": {
"direct_entity": {
"type": "minecraft:arrow",
"nbt": "{Tags:"test_arrow"}"
}
}
}
}
}
},
"rewards": {
"function": "trial_by_combat:test/test_tell"
}
}

winter glade
#

that's player hurt entity

#

you want to detect when an entity hurts a player

stray coyote
#

It doesnt load the shared one

#

the link

#

No wait it does

#

It still doesnt work even with that enchantment

winter glade
#

any errors in the logs?

thorny cragBOT
stray coyote
#

Not sure if this is mod stuff since Im launching with modrinth with mods

#

pretty sure it isnt though

winter glade
#

That's just your pack.mcmeta being incorrect

#

anything else?

stray coyote
#

Nope

#

It isnt detecting the damage

#

i gave myself the advancement manually and it worked

winter glade
#

oh ok

#

You could try removing the tag check and hitting yourself with a normal arrow

stray coyote
#

alright

#

It works that way

#

Doesnt work on mobs though

winter glade
#

when mobs hit you?

stray coyote
#

When the arrow hits a mob

winter glade
#

Yeah obviously

#

mobs can't get advancements

stray coyote
#

Yeah

#

but it should do a function when the arrow hits a mob

#

not just a player

dusty sinew
stray coyote
#

Yeah, i know that

#

I have an enchantment too

#

{
"description": "",
"supported_items": [
"minecraft:music_disc_11"
],
"weight": 1,
"max_level": 1,
"min_cost": {
"base": 0,
"per_level_above_first": 0
},
"max_cost": {
"base": 0,
"per_level_above_first": 0
},
"anvil_cost": 0,
"slots": [
"mainhand"
],
"effects": {
"minecraft:post_attack": [
{
"effect": {
"type": "minecraft:run_function",
"function": "trial_by_combat:test/test_tell"
},
"enchanted": "attacker",
"affected": "attacker"
}
]
}
}

#

this is the enchantment

dusty sinew
#

So you want the function to run as the entity that shot the arrow?

stray coyote
#

It should run at the entity

dusty sinew
#

The entity that got hit?

stray coyote
#

Yes

dusty sinew
#

Then you need to change the affected field

#

Cause right now it's trying to run the function as the entity that shot the arrow, but since you're summoning the arrow, no one shot it

stray coyote
#

True

#

Still doesnt run it though

#

i changed the affected to victim

dusty sinew
#

Did you exit and reopen the world?

stray coyote
#

Forgot about that but i just did it and it still doesnt work

dusty sinew
#

Are you positive the function isn't running? What's in the function?

stray coyote
#

advancement revoke @a only trial_by_combat:summon_projectile
tell @a Test

dusty sinew
#

Well revoking an advancement isn't gonna do anything here

#

And try say instead of tell

stray coyote
#

yeah the advancement thing was just trying out the advancment

#

Still doesn't work

dusty sinew
#

Show the current enchantment?

stray coyote
#

{
"description": "",
"supported_items": [
"minecraft:music_disc_11",
"minecraft:bow"
],
"weight": 1,
"max_level": 1,
"min_cost": {
"base": 0,
"per_level_above_first": 0
},
"max_cost": {
"base": 0,
"per_level_above_first": 0
},
"anvil_cost": 0,
"slots": [
"mainhand"
],
"effects": {
"minecraft:post_attack": [
{
"effect": {
"type": "minecraft:run_function",
"function": "trial_by_combat:test/test_tell"
},
"enchanted": "attacker",
"affected": "victim"
}
]
}
}

dusty sinew
#

Could be because there's no attacker, try doing damaging_entity for the enchanted field

stray coyote
#

Didn't work

dusty sinew
#

Hm, not sure then

stray coyote
#

It works when the arrow hits me but not for mobs

dusty sinew
#

Doesn't seem right, what's in your function now?

stray coyote
#

It was just, say test, but now I changed it to, tellraw @a {"text":"Testing"}

#

The tellraw doesnt work