Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Item Case?

I am somewhat new to the whole RPG maker thing. I know nothing about scripting. Anyways, I am making a MP3 Player using a common event. To listen to the songs on it, you need to find items in the game called MP3 song-title of song. The only problem I am having is that these fill up the invetory space really fast. Is there anyway to put these inside of another item in the invetory? I know that I can use switches instead of items, but I want to use items if it is at all possible. Can anyone help me???':|':|:-/:s
 

OS

Sponsor

I needed a break from my work for a few when I saw this. I wrote you a little script that may help. It is an early version, and may have bugs in it, but I will be glad to fix whatever I can if you can show me the errors that may arise.
Code:
class MP3_Case
  attr_accessor :contents
  def initialize
    @contents = []
  end
  
  def add_item(item_id)
    @contents += item_id
    return
  end
  
  def delete_item(item_id)
    for i in 0..@contents.size - 1
      if @contents[i] == item_id
        @contents.delete_at(i)
        return
      end
    end
    return
  end
end

class Scene_MP3
  def initialize
    $spriteset = Spriteset_Map.new
    @window_mp3 = Window_Command.new(160, $mp3_case.contents)
  end
  
  def main
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
    end
    Graphics.freeze
    $spriteset.dispose
    @window_mp3.dispose
  end
  
  def update
    $spriteset.update
    @window_mp3.update
    update_action
  end
  
  def update_action
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to map screen
      $scene = Scene_Map.new
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      $game_system.bgm_play("#{@window_mp3[@window_mp3.index]}.mp3")
      $scene = Scene_Map.new
    end
  end
      
class Scene_Title
  alias os_cng command_new_game
  def command_new_game
    $mp3_case = MP3_Case.new
    os_cng
  end
end

class Scene_Save
  alias os_wsd write_save_data
  def write_save_data(file)
    os_wsd
    Marshal.dump($mp3_case, file)
  end
end

class Scene_Load
  def read_save_data(file)
    # Read character data for drawing save file
    characters = Marshal.load(file)
    # Read frame count for measuring play time
    Graphics.frame_count = Marshal.load(file)
    # Read each type of game object
    $game_system        = Marshal.load(file)
    $game_switches      = Marshal.load(file)
    $game_variables     = Marshal.load(file)
    $game_self_switches = Marshal.load(file)
    $game_screen        = Marshal.load(file)
    $game_actors        = Marshal.load(file)
    $game_party         = Marshal.load(file)
    $game_troop         = Marshal.load(file)
    $game_map           = Marshal.load(file)
    $game_player        = Marshal.load(file)
    $mp3_case           = Marshal.load(file)
    # If magic number is different from when saving
    # (if editing was added with editor)
    if $game_system.magic_number != $data_system.magic_number
      # Load map
      $game_map.setup($game_map.map_id)
      $game_player.center($game_player.x, $game_player.y)
    end
    # Refresh party members
    $game_party.refresh
  end
end

It may not work perfectly just yet. I am really worried about whether or not music will actually play. I called for a BGM to play before sending the player back to the map, so the music may reset. If it does, just let me know.

Now, to use:
Place above Main and below Scene_Debug.
When the player uses the MP3 Case, it should call a common event called "Open MP3 Case" or something. That common event should just have the Call Script event command: $scene = Scene_MP3.new

To add MP3's to the case, use $mp3_case.add_item(item_id), where item_id is the id in the database of the mp3.

To delete MP3's in the case, use $mp3_case.delete_item(item_id).

Now, I hope this is helpful. It would really be easier on your part to use a common event and a single variable: $mp3s. If you want to know this easier way, let me know. Peace!
 
This is my fault sorry. I didn't fully explain how this works. The MP3 Player uses conditional branches. When you access the MP3 Player and select a song, it checks using conditional branches to see if you have the song in the inventory. The songs are set so that they can't be used from anywhere because they don't need to be. This is somewhat what it looks like. I am only going to run down the first branch though.


@>Text: You turn on your MP3 Player
@>Label: Music Type Menu
@>Show Choices: Battle Music, Theme Music, Field Music, More
: When [Battle Music]
@>Label: Battle Music Menu
@>Show Choices: Battle Music, Boss Music, Final Boss Music
: When [Battle Music]
@>Label: Battle Music
@>Show Choices: Battle 01, Battle 02, Battle 03, Battle 04
: When [Battle 01]
@>Conditional Branch: [MP3 Song-Battle 01] in inventory
@>Play BGM: '001-Battle01',100,100
@>
: else
@>Jump to Label: No MP3 Song Battle

Then down at the Label No MP3 Song Battle.....


Label: No MP3 Song Battle
Show Text: You need the MP3 Song to play that song.
Jump to Label: Battle Music

I am not sure if I would have to redo this for the items in an item case (if it's at all possible. Let me know. Thanks

Here is a couple of screen shots.
 

OS

Sponsor

Oh, my bad. Use this:

In Scene_Title, at the end of the $game_* definitions in the command_new_game method, add this:
Code:
$game_mp3 = []

Then, in Scene_Save, go to the large group of Marshal.dump lines. After the last Marshal.dump, add:

Code:
Marshal.dump($game_mp3, file)

Then go to Scene_Load, and after the Marshal.load lines, add:

Code:
$game_mp3 = Marshal.load(file)

When you want to add an MP3 to the player's inventory, use a call script command instead:

Code:
$game_mp3.push(mp3_item_id)

Where mp3_item_id is the ID in the database.

Then, when you want to see if the player has the MP3, use the script command on the last page of the Conditional Branch:

Code:
if $game_mp3.include?(mp3_item_id)

That is all you have to do. I guess my first post was overkill, but I hope this suits your needs more? Peace!
 
I think I understand what you are saying. The only problem I am having is that I get a syntax error everytime right after I get the MP3 Song. I'm not sure where the error is. So, how would this look for the item "MP3 Song-Music Box"?

Also, is this really supossed to have nothing in it? $game_mp3 = []

Thanks for your help
 

OS

Sponsor

I just tested it for myself. Just change:

Code:
if $game_mp3.include?(ITEM_ID)

to

Code:
$game_mp3.include?(ITEM_ID)

The 'if' was the problem. It should all be fine now. Peace!
 
okay, I changed what you said to change and I got a new error message. It reads:

Name Error While Running Script.

Uninitialized Constant Interpeter::MP3_Song

':|':|':|I don't know what this means at all. I put in the script the item ID which is
"MP3 Song-Music Box". I put it in like this: "(MP3_Song-Music_Box)"
Should I take out the dash in the middle and put an underscore? Because the dash is in the item ID. I dunno what is going on here. Thanks for the help.
 

OS

Sponsor

No, the item ID is a number. In the database in the Items Tab you will find that each item has a name and an ID. The ID is the number next to the name in the list to the left. That is what you should use.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top