Hi, I tried to make a option menu (
like Blizz-ABS premenu):
(http://a.imageshack.us/img842/6529/menud.png)
Looking into Scene_Menu and Command_Menu I finally do it (
I´m not a scripter but like to play with code sometimes):
#==============================================================================
# ** My_Window
#------------------------------------------------------------------------------
# This window deals with general command choices.
#==============================================================================
class My_Window < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
# width : window width
# commands : command text string array
#--------------------------------------------------------------------------
def initialize(width, commands)
# Compute window height from command quantity
super(100, 100, 205, commands.size * 32 + 32)
@item_max = commands.size
@commands = commands
self.contents = Bitmap.new(width - 32, @item_max * 32)
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...@item_max
draw_item(i, normal_color)
end
#Shows the picture on the window
#Stores the picture into the battler
@bitmap = RPG::Cache.battler("t1.png", 0)
self.contents.blt(2, 5, @bitmap, Rect.new(0, 0, @bitmap.width, @bitmap.height), 160)
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
# color : text color
#--------------------------------------------------------------------------
def draw_item(index, color)
self.contents.font.color = color
rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index])
end
#--------------------------------------------------------------------------
# * Disable Item
# index : item number
#--------------------------------------------------------------------------
def disable_item(index)
draw_item(index, disabled_color)
end
end
#==============================================================================
# ** Scene_123
#------------------------------------------------------------------------------
# This class performs Options 123 screen processing.
#==============================================================================
class Scene_123
#--------------------------------------------------------------------------
# * Object Initialization
# menu_index : command cursor's initial position
#--------------------------------------------------------------------------
def initialize(menu_index = 0)
@menu_index = menu_index
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make command window
s1 = " Option 1"
s2 = " Option 2"
s3 = " Option 3"
s4 = " Option 4"
s5 = " Option 5"
s6 = " Option 6"
@command_window = My_Window.new(205, [s1, s2, s3, s4, s5, s6])
@command_window.index = @menu_index
@command_window.opacity = 255
# If number of party members is 0
if $game_party.actors.size == 0
# Disable items, skills, equipment, and status
@command_window.disable_item(0)
@command_window.disable_item(1)
@command_window.disable_item(2)
@command_window.disable_item(3)
end
# If save is forbidden
if $game_system.save_disabled
# Disable save
@command_window.disable_item(4)
end
#Fondo del menu = MAPA
@spriteset = Spriteset_Map.new
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@command_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@command_window.update
# If command window is active: call update_command
if @command_window.active
update_command
return
end
# If status window is active: call update_status
if @status_window.active
update_status
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when command window is active)
#--------------------------------------------------------------------------
def update_command
# 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)
# If command other than save or end game, and party members = 0
if $game_party.actors.size == 0 and @command_window.index < 4
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Branch by command window cursor position
case @command_window.index
when 0 # Option1
$Victory =+ 1
$scene = Scene_Map.new
when 1 # Option 2
$scene = Scene_Map.new
when 2 # Option 3
$scene = Scene_Map.new
when 3 # Option 4
$scene = Scene_Map.new
when 4 # Option 5
$scene = Scene_Map.new
when 5 # Option 6
$scene = Scene_Map.new
return
end
return
end
end
end
But I have a problem. After I use the menu and go back to scene_map, if I open again the menu or do a map transition, the game crash (
no error message, just crash).
I hope that someone can take a look at this and help me (
RPGMaker XP and not using any other scripts).
I get no error when trying it. But why do you have it get the image from the Battler folder?
Can you try this example? `
http://www.mediafire.com/?5puy0djs2o7jada
QuoteBut why do you have it get the image from the Battler folder?
Cause the tutorial I read to put an image used the battler folder. Now I know that this can be changed to other folder.
Sure it can. You can for example look in the Scene_Title to see the code to get the image from the Titles folder. Just look through different scripts and learn from them.
For the script. It was an quite easy fix. You forgot to dispose the map background in @spriteset. Just add @spriteset.dispose below the @command_window.dispose.
In your future scripts be sure to properly dispose everything that your script has created.