Player take damage when see a entity hurt

Started by GSantos on

Topic category: Help with modding (Java Edition)

Last seen on 18:10, 26. Apr 2024
Joined Apr 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Player take damage when see a entity hurt

Hello everyone, Im trying to make the player take damage when see a entity hurt, not when he hurts the mob, but yes when The entity take damage for some thing. I don't find it, can someone help me?

Last seen on 13:54, 28. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
...This would be tricky, but…
Fri, 04/12/2024 - 11:01

...This would be tricky, but not impossible. There is a global trigger for 'when entity hurt.' You would need to make a procedure with this trigger, and then target either every player in the world, or every nearby player, (in, say, a 64 block radius), as an entity iterator. (An entity iterator is a special type of bracket that runs code on every entity in its radius.)

Then comes the tricky part. Essentially, you need to check if the entity iterator is a player, and if their look angle vectors intersect with the hitbox of the entity being hurt. (Or are in the general vicinity.) So you need to use trig to caclulate a vector between the entity's position and the player's position, and then check if their look angle vector is near enough to the first vector to determine whether or not they should take damage.

This is, uh, kind of advanced even for me, but again, not totally impossible. There isn't a built in trigger for it though.

Last seen on 18:10, 26. Apr 2024
Joined Apr 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok thanks you, Im probably…
Fri, 04/12/2024 - 12:30

Ok thanks you, Im probably saying some thing about it after

Last seen on 18:10, 26. Apr 2024
Joined Apr 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yeah, I really don't know…
Fri, 04/12/2024 - 18:06

Yeah, I really don't know how make the make the second part. I only do the iterator is a player the part of vectors I dont know

Last seen on 18:10, 26. Apr 2024
Joined Apr 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If you know a way to player…
Fri, 04/12/2024 - 18:49

If you know a way to player take damage when he attack with a sword its usefull too, less then take damage when see a entity hurt but also usefull

Last seen on 18:10, 26. Apr 2024
Joined Apr 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Forget the thing about sword…
Fri, 04/12/2024 - 19:08

Forget the thing about sword cause damage, because I already do it

 

Last seen on 13:54, 28. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
An easier method might be to…
Sat, 04/13/2024 - 12:19

An easier method might be to just try to detect if the player is facing in the direction of the entity that got hurt. (You would subtract the x/y/z positions of the entity and the player to determine if it's to the north, south, east, or west; and then check if the player is facing that direction.) Of course, this doesn't take into account any solid blocks in between them, or the elevation of the entity.