• The Eevee Expo Game Jam #10 has concluded, congratulations to all participants! Now it's time for the judges to play through the games, and you can play along to vote who deserves the community choice spotlight.
    You can check out the submitted games here!
    Play through the games and provide some feedback to the devs while you're at it!
  • Hi, Guest!
    Some images might be missing as we move away from using embedded images, sorry for the mess!
    From now on, you'll be required to use a third party to host images. You can learn how to add images here, and if your thread is missing images you can request them here.
    Do not use Discord to host any images you post, these links expire quickly!
Simple item crafting system + interface

Resource Simple item crafting system + interface 1.2.2

chip929

Rookie
Member
Joined
Oct 5, 2023
Posts
9
This is actually possible and doesn't require many changes to the original script.
Find def pbItemCrafter at the bottom of the script that comes with this resource and replace it with this:
Ruby:
Expand Collapse Copy
def pbItemCrafter(stock)
  for i in 0...stock.length
    raise _INTL("You are missing an ingredient or quantity value.") if stock[i][1].length%2 !=0
    itemdata = GameData::Item.try_get(stock[i][0])
    for j in 0...stock[i][1].length/2
      ingr = stock[i][1][2*j]
      cost = stock[i][1][2*j+1]
      if !GameData::Item.try_get(ingr) || cost==0
        raise _INTL("At least one ingredient or quantity value is invalid.")
      end
    end
    if !itemdata # If target item does not exist
      stock[i] = nil
    end
  end
  stock.compact! # Remove nils
  if stock.empty?
    raise _INTL("After data validation, there are no items left in your input array. Please check for typos before trying again.")
  end
end

Then, in UI_PauseMenu, find these lines:
Ruby:
Expand Collapse Copy
cmdPokedex   = -1
cmdPokemon   = -1
cmdBag       = -1
cmdTrainer   = -1
cmdSave      = -1
cmdOption    = -1
cmdPokegear  = -1
cmdDebug     = -1
cmdQuit      = -1
cmdEndGame   = -1
Add cmdCraft = -1 somewhere in that block of code. I don't think it matters where.

Just below that, you'll see lines that look like this:
Ruby:
Expand Collapse Copy
commands[cmdPokegear = commands.length]  = _INTL("Pokégear") if $Trainer.has_pokegear
Add this new line:
Ruby:
Expand Collapse Copy
commands[cmdCraft = commands.length]     = _INTL("Crafting") if !(pbGet(123)==0 || pbGet(123).empty?)

Finally, scroll down a bit more and you'll see various blocks of codes that start with something like this:
Ruby:
Expand Collapse Copy
elsif cmdPokegear>=0 && command==cmdPokegear
Add this somewhere (I believe the position here determines where the "Crafting" option will appear in the pause menu):
Ruby:
Expand Collapse Copy
elsif cmdCraft>=0 && command==cmdCraft
  pbPlayDecisionSE
  pbItemCrafter(pbGet(123))
  pbFadeOutIn {
    scene = ItemCraft_Scene.new
    screen = ItemCraft_Screen.new(scene,pbGet(123))
    screen.pbStartScreen
    @scene.pbRefresh
  }

You might have noticed that the number 123 appears a few times in these new lines you've added. That's because I've used game variable 123 to store the crafting recipes. This approach allows you to have the player "learn" new recipes on the fly by adding those recipes into this game variable. Here's an example of what I mean (this bit will need to be in an event):
Ruby:
Expand Collapse Copy
pbGet(123).push(
[:SITRUSBERRY,[:POTION,2]]
)
Here, we take our game variable 123 (which is an array - I'll get onto that at the end) and we append it with our Sitrus Berry recipe. You'll notice that the formatting is identical to the original resource.
You can have the player learn multiple recipes at once like this:
Ruby:
Expand Collapse Copy
pbGet(123).push(
[:SITRUSBERRY,[:POTION,2]],
[:LAGGINGTAIL,[:HARDSTONE,1,:IRONBALL,1]]
)
If you want to use a different game variable, you just have to change the 123 everywhere.

Now for the most important part. Before the player is to learn a new recipe, you need to put this bit of code somewhere:
Ruby:
Expand Collapse Copy
pbSet(123,[]) if pbGet(123)==0
You can put it in the same event where the player learns their first recipe or, if you're not adding this to a game with players already having save files, you can put it in the intro event. It's up to you. All I'll say is if you don't put it before the first recipe is learned, your game will crash.

I think that's all you need. If you're using a custom pause menu, I'll let you work out how to get this working with that based on the information I've given.
Let me know if there are any issues with this. ☺️
Having trouble finding cmd____ = -1 lines in the UI_PauseMenu script (accessed via Tools -> Script Editor). It might be because I'm working on Pokemon Essentials 21.1 and they've changed things?
 
Back
Top