4

I need help with commands, again

DinoDesmond 2/26/21 5:13 pm history
1.8k
2/27/2021 5:49 am
Does any one know how to make it so if a certain entity hits a entity a it will give them a effect like if a husk hits a player.




And I will put other command questions here
Posted by
DinoDesmond
Level 57 : Grandmaster Dinosaur Theorist
342

  Have something to say?

JoinSign in

6

Bertiecrafter
02/27/2021 2:52 am
Level 72 : Legendary System
history
For mobs hitting players, maybe hidden advancements are the solution. Refer to HoboMaggot's answer for generic entity to entity interaction.
3
HoboMaggot
02/27/2021 3:47 am
Level 55 : Grandmaster Blob
Actually you are correct. Theres a entity_hurt_player criteria, and it allows any mobs to be hurt by another mob (theoretically) although the commands you want executed when that happens have to be executed through the player.
However its a certainty that a mob hurting a player will work for this criteria

DinoDesmond you need to make a custom advancement that detects when a husk hits the player (the criteria is minecraft:entity_hurt_player), so when the husk actually hits the player that player will get the advancement. Then you detect if the player has that advancement in a function/command block with an execute command, give them the effect and then remove the advancement.
You can use these 2 sites to generate your advancement
more visually friendly
more cleaner and has presets (vanilla advancements) to help you start
I can make a datapack if you're not up for it
1
Bertiecrafter
02/27/2021 5:49 am
Level 72 : Legendary System
The advancement can run a function as the player once achieved, no need to check for players having the advancement in a tick function.
2
HoboMaggot
02/26/2021 8:53 pm
Level 55 : Grandmaster Blob
There's no real way, and the closest workaround I can think of is detecting when the player gets hurt using the "HurtTime" nbt tag and finding if the specified mob is basically next to the player
So an example command would be like this:
/execute as @a[nbt={HurtTime:10}] at @s if entity @e[type=husk,limit=1,distance=..3] run <command>You can see the flaws with this, but that's (in my knowledge) the only workaround
2
Mr-villager
02/27/2021 2:21 am
Level 54 : Grandmaster Farmer
so the HurtTime is real not tag or not?
1
HoboMaggot
02/27/2021 3:32 am
Level 55 : Grandmaster Blob
HurtTime is the nbt tag you need to use
minecraft.gamepedia.com/Mob#Common_NBT_data
2

Welcome