How do I make a limiter?

Started by BurntDonut on

Topic category: Help with modding (Java Edition)

Last seen on 08:03, 7. Jul 2024
Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do I make a limiter?
Fri, 12/29/2023 - 11:32 (edited)

I'm making a mana system in which every 15 ticks adds 1 mana but it keeps on going beyond its limit and I'm not sure what to do exactly. How do I make some sort of limiter for this? I'm kind of new to this and just wanna have fun.

Edited by BurntDonut on Fri, 12/29/2023 - 11:32
Last seen on 20:37, 26. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You will probably want to…
Fri, 12/29/2023 - 12:27

You will probably want to use the 'on player tick' trigger to add mana to the player. The problem you're likely running into is that the procedure tiggers every tick, (20 times a second), which causes it to go up far to quickly.

What you can do is make an additional player-lifetime number variable, (I assume you're using a number variable already for the mana counter), that starts at zero, and increases the mana counter by 1 every time it reaches 15. You would have a procedure that triggers every update tick, increasing the first variable by one. When the first variable reaches 15, reset it to zero, and increase the second variable by one. To limit the second variable, add an if bracket that only increases the second variable if it's less than your desired threshold. (But still resets the first variable.) 

You could also make these thresholds both variables themselves, if you wanted items or gamerules that increased mana recharge speed or maximum mana. 

Last seen on 08:03, 7. Jul 2024
Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'm a little confused on how…
Fri, 12/29/2023 - 15:33

I'm a little confused on how I could do this. I did create a player-lifetime number variable but I don't really know how or exactly how to do the next as I do not understand.