How would I make it so a mob gives itself an effect the first time it gets hit then once every couple of hits

Started by littledude47 on

Topic category: Help with modding (Java Edition)

Last seen on 18:17, 27. Feb 2021
Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How would I make it so a mob gives itself an effect the first time it gets hit then once every couple of hits

I want my mob to give itself a potion effect the first time you hit it and then not again for the next 5-10 hits but everything I try isn't working, has anyone done this successfully before I need to know for my mod

Last seen on 22:49, 17. Mar 2021
Joined Jan 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Here's an example image. I'm…
Mon, 08/17/2020 - 13:51

Here's an example image. I'm not 100% sure this will work, but I think it will.

This procedure is triggered by "When Entity Hurt" for your mob.

https://i.imgur.com/wvWc9nC.png

The "duration" of the effect is the number of seconds times 20 (so in this case it's 10 seconds), the level is the potion level (highest drinkable potions obtainable in Survival for Regen are something like 3 or 4, but it goes up to 255). And obviously, you can change what effect it is.

You can change the name of the NBT to whatever you want (nothing other than letters, though, so no spaces or special characters), but make sure all of them are the same.

To change the total number of hits needed, edit the "5" in "Set data number NBT tag 'healTimer' to 5." In this case (obviously) it takes 5 hits.

Again, not sure this will work (I haven't tested it), but I'm like 90% sure it will. Tell me if it does.

Last seen on 22:49, 17. Mar 2021
Joined Jan 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I can't edit my reply, but I…
Mon, 08/17/2020 - 13:54

I can't edit my reply, but I just realized the procedure will make it take 6 hits, not 5. The number for the number of hits is the total hits needed minus 1.

Also forgot to explain it, this is basically how it works:

Your mob will get, basically, a hit count that starts at 5. Every time it's hit (except for the sixth), that count goes down by 1. When it reaches 0, the next time it's hit, instead of decreasing again, the hit count goes back up to 5 and it gets the effect.

Last seen on 18:17, 27. Feb 2021
Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I tried it and the mob will…
Fri, 08/21/2020 - 20:43

I tried it and the mob will sometimes get the effect in less hits and sometimes the effect is endless, is there any way to fix that?

Last seen on 18:17, 27. Feb 2021
Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Correction to my last reply:…
Fri, 08/21/2020 - 20:51

Correction to my last reply: every time the mob gets the effect the second time it lasts forever and will happen before it is even hit the amount of times it's supposed to 2-3 hits earlier

Last seen on 18:17, 27. Feb 2021
Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I found a slight fix to it,…
Sat, 08/22/2020 - 01:53

I found a slight fix to it, I'm pretty sure the mob had the effect stuck at 0 seconds left so the effect wouldn't go away so I made it so every hit the mob has the effect added for 1 tick making it so if it's stuck at 0 the effect will cancel and it won't have enough time to do anything and if it already has the effect nothing will happen