Started by
Univern
on
Topic category: Help with Minecraft modding (Java Edition)
I want to make a money currency for my mod. I think an overlay might do the trick, but I don't know how to have the money amount go up or down; i want to make it when you kill anything you get random amounts of cash for the kill, but i don't want cash to be an item, so it doesn't fill your inventory. How would I make this? (The money currency dosen't have to be an overlay, it could be shown in the inventory)
Use a variable to keep track of your currency.
I'm not very good with variables, which one would i use? Number or string? (i don't know what string is) and if its number, how do i set the variable to add 10 cash? what i see is: [if mob killed set variable to 10], but doesn't that mean every time I kill my money is set to ten, not added ten? should i put in +10? and how will i make it so you can see your cash?
Number variables are just like normal variables, but can only hold numbers,
Strings can hold words and stuff,
Examples: Number: "6" String: "Six" (or "words" or even "Notice creepers are on the rise!")
how to add the currency into the game: Go into the "Variables and stuff" and make a new NUMBER Var (Variable) and enter a name, lets just say "Money" and set the default to 0. in the "global events" section in your workplace should be a "when entity is killed" add an event, find "variable set" and there should be a way to add a random amount, if not, just try and set it to 5 or 10 or how ever you want it! i know this is a little not specific, but i hope this helps!
just make a dollar bill item or something.
You can use variables.
Numer variables use numbers that are ≥ 0. They can be used for things that can be counted.
Boolean variables can only be true or false. They can be used to check if something is happing/happened or not.
String variables are words. They can be something like "Hello", "12345", "Hi, I'm a variable", etc. They can be used to make in-game messages in the chat.
Mcreator also uses 3 "bonus" elements: block, item and entity. These elements can be found in the "minecraft elements" tab.
To make currency as a variable that should be shown in a Overlay you should use number.
Keep in mind however that global variables reset everytime you close minecraft and are shared between worlds, while local variables are local per procedure and are reset when the procedure ends (so they last 1 minecraft tick).
Since variables are quite limited at the moment, you should use items as currency.
I hope you learnt something about variables with this.
I put a message in my phone mod with a shopping app that says you should redeem all your currency to emeralds before you exit the world
use this pseudo code to increase variables:
Set variable to : variable + (number you want to increase it by)
use this pseudo code to buy stuff:
if variable > (cost of item)
Add an item to player's inventory
Set variable to : variable - (cost)