4
I need help with commands, again
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
And I will put other command questions here
6
For mobs hitting players, maybe hidden advancements are the solution. Refer to HoboMaggot's answer for generic entity to entity interaction.
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
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
The advancement can run a function as the player once achieved, no need to check for players having the advancement in a tick function.
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:
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 workaroundso the HurtTime is real not tag or not?
HurtTime is the nbt tag you need to use
minecraft.gamepedia.com/Mob#Common_NBT_data
minecraft.gamepedia.com/Mob#Common_NBT_data
