How to check if damaged/killed by another entity with the damagesource dependency

Started by RedWirePlatinum on

Topic category: User side tutorials

Last seen on 18:17, 5. Jun 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to check if damaged/killed by another entity with the damagesource dependency
Thu, 09/28/2023 - 20:11 (edited)

Image

 

The "source" string var is only so i can have the provided damage source be a required dependency.

to get the source entity from damage source, use a custom code snippet and put this into it:

damagesource.getEntity() 

(In case you're confused why this says getEntity and not getDirectEntity like in the image, I realized that getDirectEntity is the same as immediatesourceentity)


(the local variable does not need to be named sourceentity by the way)
if sourceentity is null, do not try using it with anything otherwise it will likely cause game crashes

Edited by RedWirePlatinum on Thu, 09/28/2023 - 20:11
Last seen on 18:17, 5. Jun 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Aaaaaaaand I just shortly…
Thu, 09/28/2023 - 19:58

Aaaaaaaand I just shortly realized that it's actually damagesource.getEntity() since damagesource.getDirectEntity() could also refer to arrows or whatever