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.

Common Events Closing the menu

Hi, I made an item that, when selected, becomes consumed and then calls a Common Event that gives you new items, but for some reason it closes the menu when used. I was wondering if there was a way to get around this. I need for it to stay in the items menu.
 
the simplest way is to go into the Window_Item part of the script editor and under the item selection part, add a conditional such as

Code:
if item.id == K

   for x in items_given

      $game_party.gain_item(x[0], x[1])

   end

  $game_party.lose_item(K, 1)

else

    <Normal occurance of using an item>

end

Where K is the id of the item that you are using to do this with and items_given is an array of pairs [x, y] with x the id and y the number given.

You can add the SE in manually if you want, though I don't have rmxp with me at the moment so I can't remember the exact code. Again, not being able to test this, you may need to refresh the widnow for the items to show.
 
Sorry, my first post was not meant to be an actual solution so much as a rough outline; I don't know how much you know about scripting, so it might have been all you need. (Actually, it was a rather bad outline since it should have been scene_item, not window_item; I usually only post her when I'm at work, I was in a rush, sorry.)

Anyways,
This works;
Go to the script editor
Go to scene_item
Go into the update_item method and paste:
Code:
if @item.id == ID

        for i in ARR

          $game_party.gain_item(i[0], i[1])

        end

        $game_party.lose_item(ID, 1)

        Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)

        @item_window.refresh

        return

      end
Beneath the block
Code:
unless @item.is_a?(RPG::Item)

        # Play buzzer SE

        $game_system.se_play($data_system.buzzer_se)

        return

      end

Notes
ID is the ID of the item that does this.
Replace ARR with an array of pairs [x,y].
For each pair [x,y] in ARR you will get y items with id x.
Finally, the Audio part is self explanatory, if you don't want to use an extra audio, just erase it out.
If you want to use the plain old descion se, just replace it with
$game_system.se_play($data_system.decision_se).
 
That's odd, I tested on my computer and didn't seem to encounter any problems.

A few questions
-Have you modified scene_item for any other reason?
-Are you using the default scripts? (shouldn't matter, but might...)
-Does it play the item se, etc when you use it; it shouldn't as is?
-What did you replace "ARR" with?
-How is the item setup in the DB?

Suggestions
-Double check that both ID's in the code I gave you match that of the item you are using.
-Replace "ARR" with [[1,1]] and try it. It should give you 1 of the item with id 1.
-Make a copy of the potion item in the database to the ID of the item you are trying to setup, then try it. (This is the item I used to test it.)

If none of this seems to resolve it, then right beneath the
"if @item.id == ID" line add "p 5"
and test the item. If a comment box pops up with a 5 in it, then the code is getting run, but isn't working right. If no 5 pops up, then the code is getting skipped.
 
Not to double post, but here is another way of doing what you want; a better simpler way, actually.

Go into scene_item
Under the update_item method look for the block
Code:
if @item.common_event_id > 0

   # Command event call reservation

   $game_temp.common_event_id = @item.common_event_id

   # Play item use SE

   $game_system.se_play(@item.menu_se)

   # If consumable

   if @item.consumable

      # Decrease used items by 1

       $game_party.lose_item(@item.id, 1)

       # Draw item window item

       @item_window.draw_item(@item_window.index)

   end

  # Switch to map screen

   $scene = Scene_Map.new

   return

end

Just change
Code:
$scene = Scene_Map.new
to
Code:
$scene = Scene_Map.new unless @item.common_event_id == ID
ID being the id of the common event you are using.
 

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