RPG Maker XP

RPG Maker XP

91 ratings
Simple alchemy / item combining
By Quentin
This guide will show you how to make a simple alchemy / item combining system with minimum scripting. This will be usefull for people that want more "hands on" aproach to crafting, instead of the usual menu driven crafting.
2
   
Award
Favorite
Favorited
Unfavorite
Introduction
Last time I taught you to make a simple plant colecting system. Now I will show you what to do with these plants. This will be simple alchemy system with minimal scripting.
Preparation
The system will be very simple, but expandable. It will combine two items and give you a potion depending on the items you used. First item will determine the effect, second will determine its strength. Plant and a flask.

Make a room and four events. One of them is optional, but I will use it for geting new ingredients
(the chest). This is a example:

Ingredients
It is time to prepare our ingredients. Potions will require two components. Plant, that determines the potions effect and a flask, that determines its strength. We will also need one useless item for testing and the potions them self. I will use only two ingredients and three flasks so this is how my database will look.


The "rock" is not really important. You can use it for testing puroses or not add it at all. It is up to you.

Go to the "system" tab in the database and add an "ingredient" element. You will need that later. Also, don't forget to asign EMPTY common event to every ingredient. Plants and flasks. I named my ALCHEMY.

Now we will need to do some scripting. This will help us to determine what item ID we used. Open the script editor and find "Scene_Item" and find the spot you can see in the picture, Insert the highlighted code here.


Here is the code if you want to copy it directly:


# Change variable to used item ID if it has the "Ingredient" element
if @item.element_set.include?(1)
$game_variables[2] = @item.id
end

Change the "@item.element_set.include?(1)" to whatever the ID of your "ingredient" element is "$game_variables[2]" will be the ID of the ingredient item you used. You can use a different variable.

This little script checks the item with common event asigned. If the item has the "ingredient" element, it will store its ID in the variable "2" so we can use it later.
Ingredient slots
Now it's time to start working on the ingredient spots. Open the first, leftmost event.
This event will be used for storing the "effect ingredients", in my case, the plants.

First, we need to tell the event what items are actualy the plants. Check you database and find the IDs of your effect items. In my case, healing plant (1) and stamina plant (2).

Create a array called "@effect_array" and put your IDs into it. This is how it's going to look for me:


Now we should reset the variable with the stored item ID. The same variable we used in the script editor. In my case, variable 2. This is done for one simple reason. Player might have used the item somewhere else by accident. This would still store the item ID in the variable and it might screw few things up so it is good to reset this variable before we actualy use it.


Then we need to open the inventory screen. Use this script code.


Here is the code itself:

$scene = Scene_Item.new

Player will sellect the item he wishes to put into the slot. The inventory will then automaticaly close. This is thanks to us adding empty common event to every ingredient.

Now we need to add a conditional branch.

This branch will check the "@effect_array" and see if any of the numbers inside are shared with the variable 2. If it is, the variable 2 will get stored in another variable (3) and player will loose the item. If it's not, player will get a message telling him he used wrong type of item.


Don't forget to reset the variable "2" as the last thing you do in this event. Also set up the page 2 of this event like in the following picture.


Now open the event rigth next to it. This event will be basicaly the same. The only difference is the array at the start and the variable for storing correct item ID.

Create new "@catalyst_array" and put your second batch of ingredients into them. In my case, small, medium and large flasks (4,5,6). Change the conditional branch acordingly and don't forget to asign the item ID to different variable (4 in my case). Change the second event page too.


Getting the potion
Now open the last event. This event will give us the resulting potion. This is how the entire thing looks.

First two conditional branches check if there is any item inserted in both slots. If not, the game shows the player the message saying he needs to put items in both slots. If both slots have items in them, the game starts checking the combinations. This is the condition:

"$game_variables[3] == 1 and $game_variables[4] == 4"

"$game_variables[SLOT_A] == SLOT_A_ITEM.ID and $game_variables[SLOT_B] == SLOT_B_ITEM.ID"

You wil have to do all combinations manualy so it is good to keep the amount of possible combinations manageable.
Don't forget to set both item slot variables to "0" after you get your potions.
Conclusion
And that's it. The system is pretty simple and straight forward. It can be easily repurposed to something completely different, like combining mold and metal to make weapons or magical stones and paper to make scrolls.

There are plenty of scripts focused on crafting, but this is a good alternative if you want to make something more interesting than a simple menus.

Hope this guide helped you. You can always ask me here if you end up having problems or questions.

And here is the result:
19 Comments
Land 15 Aug, 2024 @ 8:56pm 
note: I noticed that if I allocate the variable control values ​​to the last variables, skipping several blank variables, the system does not work. So I allocated them to the previous variables and it worked.
GalacticOven 7 Aug, 2024 @ 9:14am 
Yeah I figured as much. I assumed the array would be done via an array the same way one array defined what the ingredients are? (I'm not a programmer, so my scripting comprehension is limited)
Quentin  [author] 7 Aug, 2024 @ 4:54am 
Glad it worked. The non-alchemy item consumption is most likely happening because said item is set to "Consumable: Yes". This could be fixed by simply filtering out non-alchemy item when you use the alchemy machine, but there is no way to that without scripting. Doing so with scripts is really simple though.
GalacticOven 6 Aug, 2024 @ 11:27pm 
One tiny thing I did notice with the system is that if you call up the item menu when interacting with the first two events, selecting a non-alchemy healing item consumes it. And then it tells you it's not an alchemy item. XD Other than that, it works perfectly!
GalacticOven 6 Aug, 2024 @ 11:23pm 
OH MY GOD IT WORKED!!! Thank you so much for the fix and the sample game! I like your new set up for the Result event, much more organized and straightforward without a need to call up a script! Thank you!!!:steamhappy:
Quentin  [author] 6 Aug, 2024 @ 12:01pm 
Finished
https://drive.google.com/file/d/1JvgKhQv43BT8bbCqf9NFi1TOdykK2Ydv/view?usp=sharing

I think the problem was in calling the item scene. I forgot to add one frame wait command after opening the item scene and this can sometimes cause problems.
GalacticOven 6 Aug, 2024 @ 11:41am 
Thanks for taking the time to comment! I really want to implement your system into my game. I could do it with events and switches, but as you said in the introduction, this one is a cleaner, less menu-driven method.
Quentin  [author] 6 Aug, 2024 @ 10:53am 
Hard to say what went wrong. SE 057-Wrong01 doesn't play anywhere in my tutorial and it isn't default unusable item sound. I will try to re-make the tutorial project and upload it somewhere so people can download it.
GalacticOven 6 Aug, 2024 @ 10:23am 
I tried to tinker with it further (including changing the variable from 98 to 18 and copying the 105-Heal01 SFX property in your plant screenshot) and confirming the alchemy items are all set to "only from the menu" in addition to the following properties:
Scope: None
User Animation: 003: Use Item
Target Animation: None
Menu Use SE: 105-Heal01
Common Event: 042: Alchemy
Consumable: No
Parameter: None

Alas, the same wrong sfx sound (057-Wrong01) still goes off when I interact with the event, and it opens my item menu but does nothing else. :(
Quentin  [author] 6 Aug, 2024 @ 5:39am 
I don't have the source files anymore so I can't really check if there is anything wrong with your events. It looks alright at first glance.

The "alchemy menu" is just an item menu with some small edits. Adding a filter that would remove all non-ingredient items is possible with minimal scripting.

As for the "wrong sfx" sound, badly set-up items could be the culprid. Check if all ingredients have the common event set up correctly, if they are set up to "only from menu" use and so on.