Topic category: Help with Minecraft modding (Java Edition)
Hello, I need help making a "mana" counter for my mod, well, mana is actually called magic particles in my mod, but its the same thing as mana. I just want to have a number that appears on the top right of the screen after the player injects themselves with the potion required to unlock the ability to use mana for magic, and depending on what they do, that number will decrease or increase, when the player first unlocks it it will say 100 magic particles and then if they do something like use a spell that takes 50 mana or something it will go down to 50 magic particles but will rise back up over time to 100. Then i also want to add like an item to the game that if used will increase their mana/magic particles number by a certain amount.
um....save variables?
I don't really know but variables seem to be the thing you use, make things to increase/deacrease it, but then it's single-player exclusive. a price to pay I guess ¯\_(ツ)_/¯
or look it up
i have tried looking up how to do this but i ended up empty handed, so i shall wait for more replies and hopefully someone knows.
Create a variable for your counter, set it to number type and set it to player lifetime. Then create overlays that will show up when variable = number of your bar you need. ( for exemple, to show bar that has 1 left, you need: (Variable) > 0 AND (Variable) ≤ 1. (exemple For 2 left:) (Variable) > 1 AND (Variable) ≤ 2 and so on. ) Then create procedures:
Here's procedure:
[ON PLAYER TICK UPDATE:]
--------------------------------------------------------------------------
IF: [(Variable) > (Number) AND (variable) ≤ (Number)]
DO: [Return: true]
--------------------------------------------------------------------------
[Renturn: false]
For your variable regenerate on time, set following procedure:
[ON PLAYER TICK UPDATE:]
[Set (variable) to: [(Variable + 0.05)]] <(that will regenerate your bar for 1 number per second, to understand how much does regenerates per second, multiply the number by 20)
To prevent you number going above you want:
[ON PLAYER TICK UPDATE:]
------------------------------------------------------------------------
IF: [(Get variable] > [(number you want)]
DO: Set (variable) to: (your max number of bar)
------------------------------------------------------------------------
I think thats all
thanks, can you send pictures of the procedures just so that way i know exactly what to do?
and which procedure is for which overlays
idk how to send images, but you need to select procedure so it would match the overlay, like if u want to 0.5 number overlay show up when your number is at one, in overlay conditions select mathcing procedure
is this what im supposed to do for the first procedure, then do i link it to "display overlay in-game"
also how to make it so that it goes down when player does certain thing?
create a procedure for tht, for example:
at tool's trigger, that triggers on right click:
Make a procedure to check if needed amount of you bar is aviable, and if it is, it will run the ability and take from you, for example, 2 . That the procedure to take it away: [(Set (Variable)) to: {(Get (variable)) - (2)}].
Else if its not enough of it, just make it play some sound (for example, blocks.note.bass) and say something like "Not enough mana!"
i made it so it wont go under 0, but for some reason it also still lets the player use the spell even after it reaches zero, they can keep using the spell and the number will regen when they stop using the spell but how do i make it so that they cant use the ranged item anymore until it regenerates a certain amount?
also, it shows 999999 when regenerating unless i set it the [(Variable + 0.05)]] to 1 instead of 0.05 it shows 99999999 but 1 is too fast and i don't want it to show those 9's is there a way to fix that, if not thats fine.
make your tools consume less of it and make regeneration less. that's only thing i can suggest. To prevent players use smth when your number is at 0, make a procdedure to check if there is amount you need, and if there's not, it will dont do it, instead it will do smth else, like send a messege in chat, like that:
https://ibb.co/rt8kjzQ , image doesnt works in desc
well alright, i tried everything i can but its not working how i want it to, i think im gonna make players have to use mana potions instead of having a mana counter that goes up they will have to use different variations of potions that hold different amounts of mana.