How to make a potion effect that does random effects as time goes on?

Started by swelkinn_n on Mon, 07/11/2022 - 22:15

Topic category: Help with modding (Java Edition)

Last seen on 23:37, 4. Oct 2022
Joined Oct 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
How to make a potion effect that does random effects as time goes on?
Mon, 07/11/2022 - 22:15

Very similar in concept to the Feral Bite effect from Terraria, I want to make a potion effect that will, as the player has it, randomly inflict other potion effects, or (for example) play a sound, etc

I am unsure on how exactly to go about this, since I want those effects to be independent from the custom potion effect, and have their own timers and can expire separately from the custom effect, etc

I know that it would be an RNG procedure along with a timer procedure (to make sure it doesnt randomly inflict an effect every tick or so), but I am unable to get any I know to work

Last seen on 20:08, 25. Sep 2022
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I've tried doing something…
Mon, 07/11/2022 - 22:44

I've tried doing something similar- an RNG thing that randomly decides the duration between applying effects and the effect to apply should suffice, but I have had some issues where potion effects that are chosen using random generation sometimes don't work properly. (To fix this, I made the effects based on something sort of random- like the cycles of the moon.) You could also make it so that the duration between applying effects is random, and the potion effect itself is determined based on, say, the position of the entity, or the last digit of the time of day. (Something that's random enough to be... random, but not actually an RNG generator.)

Last seen on 23:37, 4. Oct 2022
Joined Oct 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Mindthemoods, mind sending…
Thu, 07/14/2022 - 18:04

Mindthemoods, mind sending an example ? I'm not the best with these things lol

Last seen on 20:08, 25. Sep 2022
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Ideally, something like this…
Thu, 07/14/2022 - 21:58

Ideally, something like this should work- the only thing you need to change is make the 'delay' a global, player-lifetime variable rather than a local one.

Hook this up to your custom effect; every second, if the player has no delay left from the effect, there's a 10% chance of the player getting one minute of one of the randomly selected status effects. Afterwords, it sets the delay to one minute. If the player has any delay left, the effect decreases the delay instead. 

You can add as many effects as you want, and can have this trigger other custom effects as well; you could also add another variable to randomize the duration of the effect, and set the delay to the same duration.

...The only thing I'd be careful of is I have had bugs in the past where trying to randomly inflict a potion effect adds particles and the effect icon, but not the effect itself. However, this is probably the most straightforward solution.

Last seen on 23:37, 4. Oct 2022
Joined Oct 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Finally got around to…
Fri, 07/22/2022 - 20:28

Finally got around to testing this, it seems like the first time it doesn't work but all subsequent procs of the effect work which I'm more than fine with

You actually had it right in the image, as (at least in my testing) it doesn't actually work with the global variable for some reason.

Nonetheless, thank you a lot for this !! I'm very glad to get this working