Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> Menu Common Event, Call a common event from the menu! (V5.0)
Night5h4d3
post Sep 17 2009, 09:52 AM
Post #1


The past tense
Group Icon

Group: +Gold Member
Posts: 1,199
Type: Scripter
RM Skill: Undisclosed




Menu Common Event
by: Night5h4d3
v5.0

Introduction:
This was a request of JoRu, and I figured I ought to add it to the the scripts (his topic here) This script basically allows you to run a common event from the menu (using the command window) it supports these features:

Features:
  • run a common event from the menu
  • display messages, choices, etc
  • Modify player stats such as gold, HP, etc
  • Modify variables, switches
  • Call shop processing
  • You can now process player transfers
  • Deleting commands from the array is now easier (see FAQ)
  • NEW!!! Infinite commands in menu! now you can use way more than just 4!
  • NEW!!! Adding commands is now automated!! (see FAQ)
  • NEW!!! You can now call a name change!
  • NEW!!! The 'gameover' command is now added, so you can have your player 'suicide,' great for death-note fan-games XP

Script:
V5.0 here!
CODE
#==============================================================================
# ** Menu Call Common Event (NS_CE)
# by Night5h4d3
# v 5.0
#==============================================================================
module NS_CE  
  # An array of the text that will appear in the menu selection
  EVENT_NAME = ["Some Text"]
  # An array of the common events to run
  EVENT_NUM  = [1]
  # These appear at game start, so if you dont want event options available at
  # the start of the game, then just remove the items.
  
#----------------------------------------------------------+
# DO NOT TOUCH BELOW UNLESS YOU REALLY KNOW WHAT YOUR DOING|
#----------------------------------------------------------+
  def self.delete_byname(name)
    EVENT_NAME.compact!
    EVENT_NUM.compact!
    for i in 0...EVENT_NAME.size
      if EVENT_NAME[i].downcase == name.downcase
        EVENT_NAME[i]  = nil
        EVENT_NUM[i]   = nil
        $scene.recreate_windows if $game_temp.from_menu == true and $game_temp.scene_now == "ME"
        break
      end
    end
  end
  def self.add_event(name, number, pos = -1)
    @name    = name
    @number  = number
    @pos     = pos
    EVENT_NAME.compact!
    EVENT_NUM.compact!
    if @name or @number != nil
      if @pos > 0
        EVENT_NAME[@pos - 1, 0] = @name
        EVENT_NUM[@pos - 1, 0]  = @number
      else
        EVENT_NAME.push(name.to_s)
        EVENT_NUM.push(number)
      end
      $scene.recreate_windows if $game_temp.from_menu == true and $game_temp.scene_now == "ME"
    end
  end
end
#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
#  This class handles temporary data that is not included with save data.
# The instance of this class is referenced by $game_temp.
#==============================================================================
class Game_Temp
  attr_accessor :from_menu
  attr_accessor :scene_now
  alias :initialize_new2 :initialize
  def initialize
    initialize_new2
    @from_menu = false
    @scene_now = nil
  end
end
#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
#  An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================
class Game_Interpreter
  attr_accessor :list
  alias :initialize_new :initialize
  def initialize(depth = 0, main = false)
    @list = nil
    initialize_new
  end
  #--------------------------------------------------------------------------
  # * Transfer Player
  #--------------------------------------------------------------------------
  def command_201
    return true if $game_temp.in_battle
    if $game_player.transfer? or            # Transferring Player
       $game_message.visible                # Displaying a message
      return false
    end
    if @params[0] == 0                      # Direct designation
      map_id = @params[1]
      x = @params[2]
      y = @params[3]
      direction = @params[4]
    else                                    # Designation with variables
      map_id = $game_variables[@params[1]]
      x = $game_variables[@params[2]]
      y = $game_variables[@params[3]]
      direction = @params[4]
    end
    $game_player.reserve_transfer(map_id, x, y, direction)
    @index += 1
    return false
    if $game_temp.from_menu == true
      $game_player.set_direction(direction)
      if $game_map.map_id != map_id
        $game_map.setup(map_id)
      end
      $game_player.moveto(x, y)
    end
  end
  #--------------------------------------------------------------------------
  # * Shop Processing
  #--------------------------------------------------------------------------
  alias :command_302_new :command_302
  def command_302
    command_302_new
    if $game_temp.from_menu == true
      $scene = Scene_Shop.new
    end
  end
  #--------------------------------------------------------------------------
  # * Shop Processing
  #--------------------------------------------------------------------------
  alias :command_303_new :command_303
  def command_303
    command_303_new
    if $game_temp.from_menu == true
      $scene = Scene_Name.new
    end
  end
  #--------------------------------------------------------------------------
  # * Game Over
  #--------------------------------------------------------------------------
  alias :command_353_new :command_353
  def command_353
    command_353_new
    if $game_temp.from_menu == true
      $game_temp.next_scene = nil
      $scene = Scene_Gameover.new
    end
  end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs the map screen processing.
#==============================================================================
class Scene_Map < Scene_Base
  def initialize
    $game_temp.from_menu = false
    $game_temp.scene_now = "MA"
  end
end
#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#  This class performs the menu screen processing.
#==============================================================================
class Scene_Menu < Scene_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     menu_index : command cursor's initial position
  #--------------------------------------------------------------------------
  def initialize(menu_index = 0)
    @menu_index = menu_index
    NS_CE::EVENT_NAME.compact!
    NS_CE::EVENT_NUM.compact!
    $game_temp.from_menu = true
    $game_temp.scene_now = "ME"
    $pause_interpreter = !$game_temp.from_menu
  end
  #--------------------------------------------------------------------------
  # * Start processing
  #--------------------------------------------------------------------------
  def start
    super
    create_menu_background
    create_command_window
    @command_window.active = false
    @message_window = Window_Message.new
    @gold_window = Window_Gold.new(0, 360)
    @status_window = Window_MenuStatus.new(160, 0)
  end
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  def terminate
    super
    @message_window.dispose
    dispose_menu_background
    @command_window.dispose
    @gold_window.dispose
    @status_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    update_menu_background
    @message_window.update
    @command_window.update
    @gold_window.update
    @status_window.update
    if @command_window.active
      update_command_selection
    elsif @status_window.active
      update_actor_selection
    elsif !@command_window.active and $game_map.interpreter.list == nil
      recreate_windows
    elsif $game_map.interpreter.running?
      @command_window.active = false
    end
    $pause_interpreter = !$game_temp.from_menu
    unless $pause_interpreter
      $game_map.interpreter.update
    end
  end
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  def create_command_window
    s1 = Vocab::item
    s2 = Vocab::skill
    s3 = Vocab::equip
    s4 = Vocab::status
    s5 = Vocab::save
    s6 = Vocab::game_end
    @command_array = [s1, s2, s3, s4, s5, s6]
    if NS_CE::EVENT_NAME.size > 0
      @command_window = Window_Command.new(160, @command_array + NS_CE::EVENT_NAME)
    else
      @command_window = Window_Command.new(160, @command_array)
    end
    @command_window.index = @menu_index
    if $game_party.members.size == 0          # If number of party members is 0
      @command_window.draw_item(0, false)     # Disable item
      @command_window.draw_item(1, false)     # Disable skill
      @command_window.draw_item(2, false)     # Disable equipment
      @command_window.draw_item(3, false)     # Disable status
    end
    if $game_system.save_disabled             # If save is forbidden
      @command_window.draw_item(4, false)     # Disable save
    end
  end
  #--------------------------------------------------------------------------
  # * Recreate Windows
  #--------------------------------------------------------------------------
  def recreate_windows
    @old_size = NS_CE::EVENT_NAME.size
    NS_CE::EVENT_NAME.compact! if NS_CE::EVENT_NAME.include?(nil)
    NS_CE::EVENT_NUM.compact! if NS_CE::EVENT_NUM.include?(nil)
    @gold_window.refresh
    @status_window.refresh
    @old_index = @command_window.index
    @command_window.dispose
    create_command_window
    unless @old_size == NS_CE::EVENT_NAME.size
      @command_window.index = @old_index - 1
    else
      @command_window.index = @old_index
    end
  end
  #--------------------------------------------------------------------------
  # * Update Command Selection
  #--------------------------------------------------------------------------
  def update_command_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      $scene = Scene_Map.new
    elsif Input.trigger?(Input::C)
      if $game_party.members.size == 0 and @command_window.index < 4
        Sound.play_buzzer
        return
      elsif $game_system.save_disabled and @command_window.index == 4
        Sound.play_buzzer
        return
      end
      Sound.play_decision
      case @command_window.index
      when 0      # Item
        $scene = Scene_Item.new
      when 1,2,3  # Skill, equipment, status
        start_actor_selection
      when 4      # Save
        $scene = Scene_File.new(true, false, false)
      when 5      # End Game
        $scene = Scene_End.new
      else
        if @command_window.index >= 6
          @command_window.active = false
          $game_map.interpreter.setup($data_common_events[NS_CE::EVENT_NUM[@command_window.index - 6]].list, 0)
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Start Actor Selection
  #--------------------------------------------------------------------------
  def start_actor_selection
    @command_window.active = false
    @status_window.active = true
    if $game_party.last_actor_index < @status_window.item_max
      @status_window.index = $game_party.last_actor_index
    else
      @status_window.index = 0
    end
  end
  #--------------------------------------------------------------------------
  # * End Actor Selection
  #--------------------------------------------------------------------------
  def end_actor_selection
    @command_window.active = true
    @status_window.active = false
    @status_window.index = -1
  end
  #--------------------------------------------------------------------------
  # * Update Actor Selection
  #--------------------------------------------------------------------------
  def update_actor_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      end_actor_selection
    elsif Input.trigger?(Input::C)
      $game_party.last_actor_index = @status_window.index
      Sound.play_decision
      case @command_window.index
      when 1  # skill
        $scene = Scene_Skill.new(@status_window.index)
      when 2  # equipment
        $scene = Scene_Equip.new(@status_window.index)
      when 3  # status
        $scene = Scene_Status.new(@status_window.index)
      end
    end
  end
end
#==============================================================================
# ** Scene_Shop
#------------------------------------------------------------------------------
#  This class performs shop screen processing.
#==============================================================================
class Scene_Shop < Scene_Base
  def initialize
    $game_temp.next_scene = nil
    $game_temp.scene_now = "SH"
  end
  #--------------------------------------------------------------------------
  # * Update Command Selection
  #--------------------------------------------------------------------------
  def update_command_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      if $game_temp.from_menu == true
        $scene = Scene_Menu.new
      else
        $scene = Scene_Map.new
      end
    elsif Input.trigger?(Input::C)
      case @command_window.index
      when 0  # buy
        Sound.play_decision
        @command_window.active = false
        @dummy_window.visible = false
        @buy_window.active = true
        @buy_window.visible = true
        @buy_window.refresh
        @status_window.visible = true
      when 1  # sell
        if $game_temp.shop_purchase_only
          Sound.play_buzzer
        else
          Sound.play_decision
          @command_window.active = false
          @dummy_window.visible = false
          @sell_window.active = true
          @sell_window.visible = true
          @sell_window.refresh
        end
      when 2  # Quit
        Sound.play_decision
        if $game_temp.from_menu == true
          $scene = Scene_Menu.new
        else
          $scene = Scene_Map.new
        end
      end
    end
  end
end
#==============================================================================
# ** Scene_Name
#------------------------------------------------------------------------------
#  This class performs name input screen processing.
#==============================================================================
class Scene_Name < Scene_Base
  def initialize
    $game_temp.next_scene = nil
    $game_temp.scene_now = "NM"
  end
  #--------------------------------------------------------------------------
  # * Return to Original Screen
  #--------------------------------------------------------------------------
  def return_scene
    if $game_temp.from_menu == true
      $scene = Scene_Menu.new
    else
      $scene = Scene_Map.new
    end
  end
  def update
    super
    update_menu_background
    @edit_window.update
    @input_window.update
    if Input.repeat?(Input::B)
      if @edit_window.index > 0             # Not at the left edge
        Sound.play_cancel
        @edit_window.back
      end
    elsif Input.trigger?(Input::C)
      if @input_window.is_decision          # If cursor is positioned on [OK]
        if @edit_window.name == ""          # If name is empty
          @edit_window.restore_default      # Return to default name
          if @edit_window.name == ""
            Sound.play_buzzer
          else
            Sound.play_decision
          end
        else
          @actor.name = @edit_window.name
          Sound.play_decision
          @actor.name = @edit_window.name unless @actor.name == @edit_window.name
          return_scene
        end
      elsif @input_window.character != ""   # If text characters are not empty
        if @edit_window.index == @edit_window.max_char    # at the right edge
          Sound.play_buzzer
        else
          Sound.play_decision
          @edit_window.add(@input_window.character)       # Add text character
        end
      end
    end
  end
end

Demo:
Check it out, i'm V5.0!

Screenshots:
Open Me!



Compatibility:

Compatible with anything that isn't a CMS, or revisions to the original Scene_Menu. RGSS2 ONLY

Instructions:
Just put this where you put your other scripts, above main, under the materials section.

FAQ/Configuration:

QUOTE
Q: How do i change the text in the command window?

A: find EVENT_NAME[<number>] and change the text to what you desire

QUOTE
Q: How do i add more menu commands for more than one common event call?

A: change the values of EVENT_NAME[<number>] and EVENT_NUM[<number>] from nil to what you want them to be. To remove event calls from the menu, set them to nil

QUOTE
Q: I know what event command I want to remove, but I dont know where in the array it is, how do i remove it?

A: Well, thanks to v4.0, you can now delete event commands if you just know the name of it IE: "Teleporta" you simply add the script call "NS_CE.delete_byname("name of event")" and it will do the work for you!

QUOTE
Q: I want to add an event command, but I hate using the manual way, how do I use the automated add event?

A: it's simple, in a 'call script' type this:
CODE
NS_CE.add_event("<name to show in menu>", <common event number>)

and if you want to add it to a specific position:
CODE
NS_CE.add_event("<name to show in menu>", <common event number>, <position 1~N>)

NOTE: putting 1 as position is right after the 'end game' command, 0 or less adds to the end.


Terms and Conditions:

you cannot:

> claim as your own
> not give credit
> post on other sites without my permission first

you can:

> use this script
> modify this script
> suggest modifications to this script
> distribute this script personally

Notes:
Enjoy! If you'd like to use this script in a commercial game, please ask me first. Don't forget to give credit smile.gif
This may not work on select calls, such as call battle, call menu(uh, who'd need this one?).
If you find any bugs, lemme know ASAP.


__________________________
Got 30 minutes? Then you've enough time to play this awesome game:

- potentially promising project page
- thanks holder
My growing space of user-bars:

about me:







I made the following!





Go to the top of the page
 
+Quote Post
   
 
Start new topic
Replies
ArcticYoshi45
post Nov 7 2010, 05:32 PM
Post #2


Level 1
Group Icon

Group: Member
Posts: 6
Type: Event Designer
RM Skill: Intermediate




There seems to be an issue when interacting with events. When "talking" to other events, they will face you, but after that they will not turn toward you and stay in that direction, and if they have an "autonomous movement" option turned on, they will not move. I'm sure it's this script, since I tested it in a new project without any scripts and the same problem occurred. Any help?

EDIT: Also, for an unexplained reason, Shop Processing commands always seem to skip the action that occurs right afterward. Not quite sure why this happens either on a common event script.

This post has been edited by ArcticYoshi45: Nov 7 2010, 06:12 PM


__________________________
Since I can't type cursive, I don't know what's supposed to go in my signature.
Go to the top of the page
 
+Quote Post
   

Posts in this topic
- Night5h4d3   Menu Common Event   Sep 17 2009, 09:52 AM
- - JoRu   Works splendid! Thanks!   Sep 17 2009, 12:04 PM
- - Sparrowsmith   This is something you've just gotta love, a be...   Sep 17 2009, 12:24 PM
- - Night5h4d3   updated to V 2.9! demo added too!   Sep 17 2009, 12:26 PM
- - Sparrowsmith   you're a machine! You only posted it today...   Sep 17 2009, 12:32 PM
- - SuperMega   I've seen some of these scripts before, but th...   Sep 17 2009, 01:43 PM
- - Night5h4d3   *GASP!* well, thanks everyone. I'm bumping...   Sep 18 2009, 11:51 AM
- - Locke   Cool script. YO!   Sep 19 2009, 12:52 AM
- - JoRu   Works nice, but it doesn't seem like it suppor...   Sep 22 2009, 07:56 AM
- - Night5h4d3   actually, i am trying to work on that.   Sep 22 2009, 07:57 AM
- - Night5h4d3   woo! we're now up to v4.0! additions i...   Sep 29 2009, 07:12 AM
- - JoRu   Nice! Didn't work all that well in the beg...   Sep 29 2009, 09:43 AM
- - Night5h4d3   Bump sorta, the links (which were broken) are now ...   Nov 5 2009, 12:55 PM
- - forestwanderer   So I don't get it. This cannot be used to dire...   Dec 1 2009, 12:13 AM
- - runefreak   I was gonna request for a script like this before ...   Dec 1 2009, 04:11 PM
- - Sparrowsmith   QUOTE (Sparrowsmith @ Sep 17 2009, 08:24 ...   Dec 11 2009, 03:21 PM
- - Night5h4d3   yes, please send me the event, this script isnt co...   Dec 15 2009, 07:13 AM
- - Night5h4d3   This is a bump, the script is now at V5.0, see wha...   Dec 28 2009, 10:18 AM
- - Shanghai   You may want to change the back opacity of the mes...   Dec 28 2009, 11:32 AM
- - Uindo_Ookami   help, i wanna use this script...but i cant open th...   Jun 18 2011, 10:27 AM
- - RandSummers   Alas the script link is broken.   Jun 28 2011, 09:09 AM
- - Uindo_Ookami   Epic bummer   Jun 29 2011, 02:18 AM
- - Night5h4d3   I re-uploaded it guys!   Jun 29 2011, 05:51 AM
- - Uindo_Ookami   woohoo!   Jul 6 2011, 09:27 AM
- - RPGMakerVX52   This is a good script but it's really similar ...   Jul 6 2011, 10:50 AM
- - CastorOnline   I know this is necroposting, but maybe the best pl...   Mar 31 2012, 11:12 PM


Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th May 2013 - 11:32 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker