Detecting how much Damage a Player or Mob does to you

Started by CaiGuyCrafter on

Topic category: Feature requests and ideas for MCreator

Joined Dec 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Detecting how much Damage a Player or Mob does to you

So, we all know some people like to use their mods in Multiplayer. This feature that I'm requesting works both ways, Single Player and Multiplayer. For the purpose of my mod, I need to know how much damage a mob or player deals and subtract a few points off of that based on how many points of something the player has. (I'm sorry if this is really easy to do with code or something because I couldn't figure it out) It could be something like, "Get Attacker Damage". That would work because I could get the Math block and do: "Get Attacker Damage" minus "Get Defense Points". (Defense points are the number that decides how many points are taken off the incoming attack. This would be an AMAZING feature to have, thanks!

Joined Dec 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I did not sadly. If anyone…
Fri, 07/09/2021 - 21:02

I did not sadly. If anyone has any ideas, please help.

I think global trigger…
Sat, 07/10/2021 - 10:26

I think global trigger provides a dependency amount that you can use to determine damage. Then just check if the target entity is of type player.

Joined Feb 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How should i use the "amount…
Wed, 12/15/2021 - 04:09

How should i use the "amount" dependency in the Entity Attacked trigger, i found it but i don't know how to actually use it properly

Joined Aug 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Amount just specifies how…
Thu, 12/16/2021 - 08:44

Amount just specifies how much damage the entity takes. Use just like a regular number. 

Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I wasn't able to find a…
Mon, 09/18/2023 - 15:04

I wasn't able to find a method of simply doing this within MCreator's procedure blocks, so I went in and did it by code, which took me way longer to figure out than it should have. For anyone wondering, here's how I got this set up:

This code was set up with 1.19.2 for either the LivingAttackEvent or the LivingHurtEvent - https://imgur.com/SojlZ2Y

 

@Mod.EventBusSubscriber
public class WhenPlayerAttackedProcedure {
	@SubscribeEvent
	public static void onEntityAttacked(LivingHurtEvent event) {
		if (event != null && event.getEntity() != null) {
			execute(event, event.getEntity().level, event.getEntity(), event.getAmount());
		}
	}

	public static void execute(LevelAccessor world, Entity entity, float amount) {
		execute(null, world, entity, amount);
	}

	private static void execute(@Nullable Event event, LevelAccessor world, Entity entity, float amount) {
		if (entity == null)
			return;
		double damage = 0;
		float damageTaken = 0;
		damageTaken = amount;
		damage = 3.4 * Math.pow(10, 38);
Joined Mar 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You can make a procedure…
Sat, 03/23/2024 - 09:29

You can make a procedure with Event Trigger: "Before entity is hurt", then set custom nbt nuber tag with (for example) name prior health, set prior health to current health and wait one tick, then subtract the current health from prior health.

I already tested it, it works