Random execution method

Started by koyote on

Topic category: Help with modding (Java Edition)

Last seen on 18:43, 16. Nov 2023
Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Random execution method

I am creating a procedure that is triggered when a MOB is injured , and I have a question about it. I would like to randomly select a potion effect from a list of potions that I have prepared and also randomize whether or not the effect is triggered. Please be specific.

Last seen on 21:55, 20. Feb 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You will need two different…
Thu, 11/02/2023 - 02:15

You will need two different methods of randomization to do this. The first uses percentages, and the second uses random integers.

Make a procedure with the global trigger 'before entity is hurt.' Then use an if bracket to check if the entity is your desired entity type. If it is, you're then going to need to use the 'Do with 70% chance' procedure template. (You can find procedure templates in the upper left-hand corner of the code builder.) The idea of this is that it generates a random decimal number between 0 and 1, and checks if the number is below a certain value, only running the code inside if it is. (a value of 0.7 means that whatever you put inside will run with a 70% chance. You can raise or lower this value as you require.) 

Then, you need to randomly select which potion effect you want to apply. Nesting a bunch of these percentage random chances can make it very difficult to determine the actual probabilities of things.

Instead, make a local number variable for your procedure, (I'll call it 'potion_type,') and use the 'random integer' function from the math tab to set this random variable to a number between one and the number of potion effects you want to be possible. If potion_type equals one, apply the first potion effect. Otherwise, if it equals two, apply the second potion effect... and so on and so forth. You could also use random integers to randomize the duration and level of these potion effects, if you wanted. 

Anyways, hope that helps. I can send a screenshot if needed.

Last seen on 18:43, 16. Nov 2023
Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks to you I realized the…
Thu, 11/02/2023 - 19:25

Thanks to you I realized the mistake in the procedure I made! It was right up to the point where I was setting the local variables, but apparently I was using "random number" instead of "random integer" for the block that randomly sets the local variables. Thank you so much!