This is a cobbled together and probably terrible example of the first thing I ever scripted myself. I didn't follow a tutorial or look up how to do anything, I just messed with things until they worked and it was so long ago, I have honestly forgotten everything I learned. Now I want to relearn so I can finish what I started, and I've hit a wall just trying to get what little is here to work.
As it is, it works in the project I coded it in and in my older test project but not in any new project(namely, the one I want it for). The ini files are basically identical, so it's not the dlls as far as I know. I tried copying all of the extra scripts I'm using to the projects the cms works in and it still works, so it's not a script conflict. I'm not sure what else to try.
I'd really like to finish the menu and use it, but if just this little bit wont work, there's no point.
The specific crash that happens is not immediate. It only crashes if I open the menu, close the menu and then try to open it again. The RGSS player stops working.
So- I am asking if any of the actual scripters out there could look it over and tell me if it's the script itself that's causing the crashes. I plan to rewrite the entire thing anyway, but I'd like to know what is wrong with this one so I don't make the same mistakes.
I'm not going to lie about how utterly new I am to this, so feel free to point and laugh if it's something anyone with half a brain would have noticed. ><
Attachment; .zip file of icons needed to actually test it
#==============================================================================
# One Hero CMS
# Very simple menu
# Cobbled together by; Dyre
#==============================================================================
class Window_Base < Window
def draw_actor_battler(actor, x, y)
face = RPG::Cache.battler(actor.name, actor.character_hue)
fw = face.width
fh = face.height
src_rect = Rect.new(0, 0, fw, fh)
self.contents.blt(20, -2, face, src_rect)
end
end
class Window_MenuStatus < Window_Selectable
def initialize
super(240, 122, 120, 280)
self.contents = Bitmap.new(110, 182)
refresh
end
def refresh
self.contents.clear
self.contents.font.size = 14
self.contents.font.name = $defaultfonttype
@item_max = 0
x = 180
y = 60
actor = $game_party.actors[0]
draw_actor_battler(actor, x, y)
draw_actor_name(actor, x, y )
draw_actor_state(actor, x, y)
self.contents.font.color = system_color
draw_actor_hp(actor, x , y)
draw_actor_sp(actor, x , y)
end
end
#----------------
##----Scene_Menu
#----------------
class Scene_Menu
#--------------------------------------------------------------------------
# * 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 = $data_system.words.item
s2 = $data_system.words.skill
s3 = $data_system.words.equip
s4 = "Status"
s5 = "End Game"
@spriteset = Spriteset_Map.new
@command_window = Window_Command.new(87, [s1, s2, s3, s4, s5])
@command_window.opacity = 128
@command_window.x = 157
@command_window.y = 135
@command_window.index = @menu_index
# If number of party members is 0
if $game_party.actors.size == 0
# Disable items, skills, equipment, and status
@command_window.disable_item(1)
@command_window.disable_item(2)
@command_window.disable_item(3)
@command_window.disable_item(4)
end
# Make gold window
@gold_window = Window_Gold.new
@gold_window.height = 60
@gold_window.x = 82
@gold_window.y = 65
@gold_window.opacity= 128
# Make status window
@status_window = Window_MenuStatus.new
@status_window.width = 145
@status_window.height = 216
@status_window.opacity= 128
# Make location window
@window_location = Window_Location.new
@window_location.x = 195
@window_location.y = 65
@window_location.opacity = 128
#mMake playtime window
@playtime_window = Window_PlayTime.new
@playtime_window.x = 420
@playtime_window.y = 65
@playtime_window.opacity = 128
# 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
@window_location.dispose
@command_window.dispose
@playtime_window.dispose
@gold_window.dispose
@status_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@spriteset.update
@window_location.update
@command_window.update
@playtime_window.update
@gold_window.update
@status_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 # item
# Play decision SE
$game_system.se_play($data_system.decision_se)
$scene = Scene_Item.new
when 1 # skill
# Play decision SE
$game_system.se_play($data_system.decision_se)
$scene = Scene_Skill.new
when 2 # equipment
# Play decision SE
$game_system.se_play($data_system.decision_se)
$scene = Scene_Equip.new
when 3 # status
# Play decision SE
$game_system.se_play($data_system.decision_se)
$scene = Scene_Status.new
when 4 # end game
# Play decision SE
$game_system.se_play($data_system.decision_se)
$scene = Scene_End.new
end
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when status window is active)
#--------------------------------------------------------------------------
def update_status
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Make command window active
@command_window.active = true
@status_window.active = false
@status_window.index = -1
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Branch by command window cursor position
case @command_window.index
when 1 # skill
# If this actor's action limit is 2 or more
if $game_party.actors[@status_window.index].restriction >= 2
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to skill screen
$scene = Scene_Skill.new(@status_window.index)
when 2 # equipment
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to equipment screen
$scene = Scene_Equip.new(@status_window.index)
when 3 # status
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Switch to status screen
$scene = Scene_Status.new(@status_window.index)
end
return
end
end
class Window_Command < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
# width : window width
# commands : command text string array
#--------------------------------------------------------------------------
def initialize(width, commands)
# Compute window height from command quantity
super(0, 0, width, commands.size * 32 + 32)
@item_max = commands.size
@commands = commands
self.contents = Bitmap.new(width - 32, @item_max * 32)
self.contents.font.name = $defaultfonttype
self.contents.font.size = $defaultfontsize
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...@item_max
draw_item(i, normal_color)
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
# color : text color
#--------------------------------------------------------------------------
def draw_item(index, color)
rect = Rect.new(16, 32 * index + 5, 24, 24)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
ico_bmp = RPG::Cache.icon(@commands[index])
self.contents.stretch_blt(rect, ico_bmp, Rect.new(0,0,ico_bmp.width, ico_bmp.height))
end
#--------------------------------------------------------------------------
# * Disable Item
# index : item number
#--------------------------------------------------------------------------
def disable_item(index)
draw_item(index, disabled_color)
end
end
#----Window_Gold
class Window_Gold < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(10, 0, 120, 60)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $defaultfonttype
self.contents.font.size = 14
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
cx = contents.text_size($data_system.words.gold).width
self.contents.font.color = normal_color
self.contents.draw_text(26, 0, 60, 32, $game_party.gold.to_s, 1)
self.contents.font.color = system_color
self.contents.blt(0, 0, RPG::Cache.icon("032-item01"), Rect.new(0, 0, 24, 24))
end
end
#---- Window_PlayTime
class Window_PlayTime < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 120, 60)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = "Georgia"
self.contents.font.size = 14
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.blt(-2, 0, RPG::Cache.icon("Playtime"), Rect.new(0, 0, 24, 24))
@total_sec = Graphics.frame_count / Graphics.frame_rate
hour = @total_sec / 60 / 60
min = @total_sec / 60 % 60
sec = @total_sec % 60
text = sprintf("%02d:%02d:%02d", hour, min, sec)
self.contents.font.color = normal_color
self.contents.draw_text(2, 0, 100, 32, text, 1)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
if Graphics.frame_count / Graphics.frame_rate != @total_sec
refresh
end
end
end
#=========================================================================
# ** Window_Location
#------------------------------------------------------------------------------
# This window displays play time on the menu screen.
#==============================================================================
class Window_Location < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 230, 65)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = "Georgia"
self.contents.font.size = 14
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
$location_info = load_data("Data/MapInfos.rxdata")
self.contents.font.color = system_color
self.contents.draw_text(42, -10, 120, 32, "Location:", 1)
self.contents.font.color = normal_color
self.contents.font.name = "Gabriola"
self.contents.font.size = 26
text = $location_info[$game_map.map_id].name
self.contents.draw_text ( 20 , 10, 160, 32, text, 1)
end
end
##end##
####-----------------####
####BEGIN SCENE TEST####
####-----------------####
# ** Scene_Status
#------------------------------------------------------------------------------
# This class performs status screen processing.
#==============================================================================
class Scene_Status
#--------------------------------------------------------------------------
# * Object Initialization
# actor_index : actor index
#--------------------------------------------------------------------------
def initialize(actor_index = 0, equip_index = 0)
@actor_index = actor_index
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Get actor
@actor = $game_party.actors[@actor_index]
# Make status window
@status_window = Window_Status.new(@actor)
@status_window.opacity = 128
@status_window.height = 450
@status_window.width = 250
@status_window.x = 190
@status_window.y = 10
# 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
@status_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
$scene = Scene_Menu.new(3)
return
end
# If R button was pressed
if Input.trigger?(Input::R)
# Play cursor SE
$game_system.se_play($data_system.cursor_se)
# To next actor
@actor_index += 1
@actor_index %= $game_party.actors.size
# Switch to different status screen
$scene = Scene_Status.new(@actor_index)
return
end
# If L button was pressed
if Input.trigger?(Input::L)
# Play cursor SE
$game_system.se_play($data_system.cursor_se)
# To previous actor
@actor_index += $game_party.actors.size - 1
@actor_index %= $game_party.actors.size
# Switch to different status screen
$scene = Scene_Status.new(@actor_index)
return
end
end
end
#==============================================================================
# ** Window_Status
#------------------------------------------------------------------------------
# This window displays full status specs on the status screen.
#==============================================================================
class Window_Status < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
# actor : actor
#--------------------------------------------------------------------------
def initialize(actor)
super(0, 0, 250, 450)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = "Georgia"
self.contents.font.size = 16
@actor = actor
refresh
end
def draw_actor_battler(actor, x, y)
face = RPG::Cache.battler(actor.character_name, actor.character_hue)
fw = 120
fh = 210
src_rect = Rect.new(0, 0, fw, fh)
self.contents.blt(65, 100, face, src_rect)
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
draw_actor_battler(@actor, -5, 0)
draw_actor_name(@actor, 85, 0)
draw_actor_class(@actor, 20, 30)
draw_actor_state(@actor, 8 + 140, 30)
draw_actor_hp(@actor, 30, 55, 172)
draw_actor_sp(@actor, 30, 75, 172)
draw_actor_parameter(@actor, 25, 114, 0)
draw_actor_parameter(@actor, 25, 134, 1)
draw_actor_parameter(@actor, 25, 156, 2)
draw_actor_parameter(@actor, 25, 190, 3)
draw_actor_parameter(@actor, 25, 236, 4)
draw_actor_parameter(@actor, 25, 268, 5)
draw_actor_parameter(@actor, 25, 290, 6)
self.contents.font.name = "Arial"
self.contents.font.size = 12
draw_item_name($data_weapons[@actor.weapon_id], 55, 325)
draw_item_name($data_armors[@actor.armor1_id], -1, 390)
draw_item_name($data_armors[@actor.armor2_id], 130, 355)
draw_item_name($data_armors[@actor.armor3_id], -1, 355)
draw_item_name($data_armors[@actor.armor4_id], 130, 390)
end
def dummy
self.contents.font.color = system_color
self.contents.draw_text(58, 330, 96, 32, $data_system.words.weapon)
self.contents.draw_text(-5, 360, 96, 32, $data_system.words.armor1)
self.contents.draw_text(135, 380, 96, 32, $data_system.words.armor2)
self.contents.draw_text(-5, 360, 96, 32, $data_system.words.armor3)
self.contents.draw_text(135, 380, 96, 32, $data_system.words.armor4)
draw_item_name($data_weapons[@actor.weapon_id], 50, 144)
draw_item_name($data_armors[@actor.armor1_id], -3, 208)
draw_item_name($data_armors[@actor.armor2_id], 120, 272)
draw_item_name($data_armors[@actor.armor3_id], -3, 336)
draw_item_name($data_armors[@actor.armor4_id], 120, 400)
end
end
end
#==============================================================================
# ** Scene_Item
#------------------------------------------------------------------------------
# This class performs item screen processing.
#==============================================================================
class Scene_Item
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make help window, item window
@help_window = Window_Help.new
@help_window.opacity = 128
@help_window.width = 260
@help_window.x = 190
@help_window.y = 30
@item_window = Window_Item.new
@item_window.opacity = 128
@item_window.width = 260
@item_window.height = 290
@item_window.x = 190
@item_window.y = 90
@itemname_window = Window_Base.new (190, 375, 260, 80)
@itemname_window.opacity = 128
# Associate help window
@item_window.help_window = @help_window
# Make target window (set to invisible / inactive)
@target_window = Window_Target.new
@target_window.visible = false
@target_window.active = false
# 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
@help_window.dispose
@item_window.dispose
@itemname_window.dispose
@target_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@help_window.update
@item_window.update
@itemname_window.update
@target_window.update
# If item window is active: call update_item
if @item_window.active
update_item
return
end
# If target window is active: call update_target
if @target_window.active
update_target
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when item window is active)
#--------------------------------------------------------------------------
def update_item
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
$scene = Scene_Menu.new(0)
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Get currently selected data on the item window
@item = @item_window.item
# If not a use item
unless @item.is_a?(RPG::Item)
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# If it can't be used
unless $game_party.item_can_use?(@item.id)
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# If effect scope is an ally
if @item.scope >= 3
# Activate target window
@item_window.active = false
@target_window.x = (@item_window.index + 1) % 2 * 304
@target_window.visible = true
@target_window.active = true
# Set cursor position to effect scope (single / all)
if @item.scope == 4 || @item.scope == 6
@target_window.index = -1
else
@target_window.index = 0
end
# If effect scope is other than an ally
else
# If command event ID is valid
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
end
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when target window is active)
#--------------------------------------------------------------------------
def update_target
# If B button was pressed
if Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# If unable to use because items ran out
unless $game_party.item_can_use?(@item.id)
# Remake item window contents
@item_window.refresh
end
# Erase target window
@item_window.active = true
@target_window.visible = false
@target_window.active = false
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# If items are used up
if $game_party.item_number(@item.id) == 0
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# If target is all
if @target_window.index == -1
# Apply item effects to entire party
used = false
for i in $game_party.actors
used |= i.item_effect(@item)
end
end
# If single target
if @target_window.index >= 0
# Apply item use effects to target actor
target = $game_party.actors[@target_window.index]
used = target.item_effect(@item)
end
# If an item was used
if used
# 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)
# Redraw item window item
@item_window.draw_item(@item_window.index)
end
# Remake target window contents
@target_window.refresh
# If all party members are dead
if $game_party.all_dead?
# Switch to game over screen
$scene = Scene_Gameover.new
return
end
# If common event ID is valid
if @item.common_event_id > 0
# Common event call reservation
$game_temp.common_event_id = @item.common_event_id
# Switch to map screen
$scene = Scene_Map.new
return
end
end
# If item wasn't used
unless used
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
end
return
end
end
end
#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
# This window displays items in possession on the item and battle screens.
#==============================================================================
class Window_Item < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 64, 260, 290)
@column_max = 5
refresh
self.index = 0
# If in battle, move window to center of screen
# and make it semi-transparent
if $game_temp.in_battle
self.y = 64
self.height = 256
self.back_opacity = 128
end
end
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
# Add item
for i in 1...$data_items.size
if $game_party.item_number(i) > 0
@data.push($data_items[i])
end
end
# Also add weapons and items if outside of battle
unless $game_temp.in_battle
for i in 1...$data_weapons.size
if $game_party.weapon_number(i) > 0
@data.push($data_weapons[i])
end
end
for i in 1...$data_armors.size
if $game_party.armor_number(i) > 0
@data.push($data_armors[i])
end
end
end
# If item count is not 0, make a bit map and draw all items
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
case item
when RPG::Item
number = $game_party.item_number(item.id)
when RPG::Weapon
number = $game_party.weapon_number(item.id)
when RPG::Armor
number = $game_party.armor_number(item.id)
end
if item.is_a?(RPG::Item) and
$game_party.item_can_use?(item.id)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = - 3 + index % 5 * (20 + 32)
y = index / 5 * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.font.name = "Georgia"
self.contents.font.size = 12
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x , y + 10, 24, 24, number.to_s, 2)
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
def update_itemname
@itemname_window.set_text(self.item == nil ? "" : self.item.name)
end
end