Custom SOUND variations using procedures. The problem with proccedurecall "When Mob is Hurt"

Started by StellaeLux on

Topic category: Help with MCreator software

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Custom SOUND variations using procedures. The problem with proccedurecall "When Mob is Hurt"
Thu, 08/29/2019 - 12:25 (edited)

When creating a mob, you can select their ambient, hurt and death sound, which will play it at a random pitch to create variation. I however want to use multiple hurt sounds to create variation.

The way I planned on doing this was by adding a death sound and ambience sound and leaving the hurt sound empty. Then I'd go to procedures and entered the following in the Mob Is Hurt procedure call:

Set Local randNum to Random[0,1]

repeat 1 times

     if Get Local randNum < 0.2

          Play at x y z level 1 pitch 1 sound Entity_Hurt1

          break out of loop

     if Get Local randNum < 0.4

          Play at x y z level 1 pitch 1 sound Entity_Hurt2

          break out of loop

     if Get Local randNum < 0.6

          Play at x y z level 1 pitch 1 sound Entity_Hurt3

          break out of loop

     if Get Local randNum < 0.8

          Play at x y z level 1 pitch 1 sound Entity_Hurt4

          break out of loop

     else

          Play at x y z level 1 pitch 1 sound Entity_Hurt5

          break out of loop

One problem with this approach however is that Mob Is Hurt is also called when the mobs dies, meaning that I heard both the death and the hurt procedure. (To me it seems counterproductive to have Mob Is Hurt procedure call called on the death blow as there already is "When Mob Dies", which simply could call the same procedure.

 

So I tried removing the death sound also and calling the sound through the Mob is Hurt procedure: 

Set Local randNum to Random[0,1]

if entity health > 0

     repeat 1 times... (And the rest you find above)

else          

     Play at x y z level 1 pitch 1 sound Entity_DYING

But again there is a problem. When this procedure is called, the entity's health has not been set to 0/below yet! This results in the same as the first implementation as the death sound is never played. I tried entity health - attack damage of item > 0, but this didn't work out for me the way I did it.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

So as for my question: How do you create a sound procedure like this that doesn't play both the hurt sound and death sound at the same time?

Additionally in future Mcreator versions, will Mob-is-Hurt no longer trigger when When-Mob-Dies"triggers as When-Mob-Dies makes Mob-is-Hurt in that instance redundant as When Mob Dies can already be used for that?

Edited by StellaeLux on Thu, 08/29/2019 - 12:25
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Do you still have the file…
Mon, 10/07/2019 - 20:49

Do you still have the file for the workspace? Maybe I can help you look at it

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I no longer do. Though all…
Mon, 10/07/2019 - 21:25

I no longer do. Though all it requires is 2 sounds, triggered customarily through procedures. 1 must play on death and the other on mob is hurt but not on hurt if the mob dies to that attack.

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Is this for a custom mob of…
Mon, 10/07/2019 - 22:55

Is this for a custom mob of yours? If so, on the very first page of the mob you got ambient, hurt, and death sound. Use those

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I know about those options,…
Mon, 10/07/2019 - 23:17

I know about those options, however, I want to have multiple hurt sounds and multiple death sounds rather than only have it variate in pitch.

Not using the ambient option on page 1 and replacing it with On Tick Update with a counter of about 400 ticks works fine, allowing the ability to use an if statement to randomly pick between the ambient sounds. But the same strategy failed for Hurt and Death as they are in each-other's way.

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ah I see. So like DrZhark's…
Tue, 10/08/2019 - 14:15

Ah I see. So like DrZhark's werewolf one where it's multiple hurt sounds as a human? I'll do some testing and see if I can help you out there!

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Okay I believe I figured it…
Tue, 10/08/2019 - 14:28

Okay I believe I figured it out. I tested it too. Try this code

Event trigger-triggered by external call or when (global trigger): Entity attacked
If is current entity (sub)type of [entity]
do
    if random[o,1) < 0.9
    do Play at x: x y: y z: z level: 1 pitch: 1 sound: (chosen sound)
    else if random[o,1) > 0.9
    do Play at x: x y: y z: z level: 1 pitch: 1 sound: (chosen sound)

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sadly, just like Entity Hurt…
Tue, 10/08/2019 - 15:13

Sadly, just like Entity Hurt procedure on the mob, it is called before on Entity death. Thus when selecting a death sound, the procedure of the entity hurt will also play. It doesn't work.

The core issue here is that

1. Entity Hurt is also called on Entity Death.

2. Entity Hurt is called before Entity Death, preventing us from setting an NBT tag in Entity Death that prevents Entity Hurt from playing.

3. Health is subtracted AFTER Entity Hurt procedure. Meaning that when we check Entity Hurt whether HP is 0 or smaller, then this will not work, as health is subtracted after this procedure call.

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The problem isn't getting…
Tue, 10/08/2019 - 15:20

The problem isn't getting variation in sound. The problem is that the hurt sound and death sound will play both on mob death as a result.

What we need is a way to detect whether the entity has died FROM the entity is hurt procedure, so that we can disrupt it from playing a hurt sound on the Mob Death.

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Okay, try duplicating the…
Tue, 10/08/2019 - 19:48

Okay, try duplicating the procedure but replace hurt with death. change the sounds too

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I really don't see how that…
Wed, 10/09/2019 - 00:10

I really don't see how that would help xD

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I gave it a go before…
Wed, 10/09/2019 - 15:30

I gave it a go before writing this post and obviously it failed.

Both death and hurt sounds will play on the hit the mob is killed as both Mob is Hurt and Mob is killed are called.

Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You got discord? Maybe you…
Wed, 10/09/2019 - 19:52

You got discord? Maybe you can show me screenshots and I can help better

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I don't have Discord, but…
Wed, 10/09/2019 - 20:30

I don't have Discord, but there's not a lot of information needed:

---------------------What I want: (mob takes 4 hits for this example)---------------------

hit1: random hurt sound.

hit2: random hurt sound.

hit3: random hurt sound.

hit4: death sound

---------------------What I don't want but currently happens:---------------------

hit1: random hurt sound.

hit2: random hurt sound.

hit3: random hurt sound.

hit4: death sound + random hurt sound.

---------------------------------------------------------------------------------------------------------

It looks easier than it is.