Xenosaga Information Database - Nakate - 07-26-2007
Xenosaga Information Database
by Nakate
v1.1
Jul 26 2007
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
Cleaned it up a bit, made it easier to impliment, and overall more user-friendly
For a game I'm working on, I decided to make a kind of database accessible from the menu that would let you look through all of the characters you've met so far in the game, showing pictures of them all. So at any point you can check the database and see who all you've met. Due to the flexible nature of the coding, it doesn't actually have to be characters, but just snipits of information you run across. Essentially it's an expanding database with entries that can be added at the game maker's will, whenever the player sees a specific event. However, until I figure out a way around it, it is mandatory that you have a picture to associate with each entry. It is easy enough, however, to just put in a blank image for an entry with no picture (say, for example, a .png entirely set to transparent) It also allows you to use the "shoulder" buttons Q and W to go through the database you've made. Now I'm not the best scripter in the world, and though I know a decent amount of C++, this is the first real work I've done with Ruby. As such, I'm pretty sure it could be written better or improved by someone else :P
The code is divided into three sections that just need to be inserted anywhere above main.
Entry 1
Code:
#===============================================================
# ** Scene_CharMenu
#------------------------------------------------------------------------------
# This class performs database menu screen processing.
#==============================================================================
class Scene_CharMenu
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make database window
@char_window = Window_CharMenu.new
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
@char_window.update
update_char
# Abort loop if screen is changed
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@char_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update_char
# 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(4)
return
end
# If C button was pressed
if Input.trigger?(Input::C)
@char = @char_window.item
@pos = @char_window.pos
# If empty database
if @char == nil
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
#play decision SE
$game_system.se_play($data_system.decision_se)
#call entry screen
$scene = Scene_Character.new(@char, @pos)
end
end
end
#==============================================================================
# ** Scene_Character
#------------------------------------------------------------------------------
# This class performs database entry screen processing.
#==============================================================================
class Scene_Character
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(char_index, pos_index)
@char_index = char_index
@pos_index = pos_index
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make entry windows
@status_window = Window_Character.new(@char_index)
@info_window = Window_CharInfo.new(@char_index)
# 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
@info_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_CharMenu.new
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 entry
@pos_index += 1
@pos_index %= ($chardata.size)
# Switch to different entry screen
$scene = Scene_Character.new($chardata[@pos_index], @pos_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 entry
@pos_index -= 1
@pos_index %= ($chardata.size)
# Switch to different entry screen
$scene = Scene_Character.new($chardata[@pos_index], @pos_index)
return
end
end
end
#==========================================================================
# CLASS Scene_Title Additional Code
#==========================================================================
class Scene_Title < Scene_Title
#initialize character database
$chardata = []
end
#==========================================================================
# CLASS Scene_Save Additional Code
#==========================================================================
class Scene_Save < Scene_File
alias chardb_original_write_save_data write_save_data
def write_save_data(file)
chardb_original_write_save_data(file)
Marshal.dump($chardata, file)
end
end
#==========================================================================
# CLASS Scene_Load Additional Code
#==========================================================================
class Scene_Load < Scene_File
alias chardb_original_read_save_data read_save_data
def read_save_data(file)
chardb_original_read_save_data(file)
$chardata = Marshal.load(file)
end
end
Entry 2
Code:
#===============================================================
# ** Window_CharMenu
#------------------------------------------------------------------------------
# This window displays the database of all encountered entries.
#==============================================================================
class Window_CharMenu < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 640, 480)
@column_max = 2
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
# If item count is not 0, make a bit map and draw all items
@item_max = $chardata.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 = $chardata[index]
self.contents.font.color = normal_color
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 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.draw_text(x + 4, y, 212, 32, get_name(item), 0)
end
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item
return $chardata[self.index]
end
#--------------------------------------------------------------------------
# * Get Pos
#--------------------------------------------------------------------------
def pos
return self.index
end
#--------------------------------------------------------------------------
# * Get Name
# index : character number
#--------------------------------------------------------------------------
def get_name(index)
case index
when 0
return "Rudaux"
when 1
return "Hilda"
end
end
end
Entry 3
Code:
#===============================================================
# ** Window_Status
#------------------------------------------------------------------------------
# This window displays full status specs on the status screen.
#==============================================================================
class Window_Character < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
# actor : actor
#--------------------------------------------------------------------------
def initialize(actor)
super(0, 0, 640, 480)
self.contents = Bitmap.new(width - 32, height - 32)
@actor = actor
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
draw_actor_battler(@actor,400,0)
end
def draw_actor_battler(actor, x, y)
bitmap = RPG::Cache.picture("characters/#{actor}")
self.contents.blt(x, y, bitmap, Rect.new(0, 0, bitmap.width, bitmap.height))
end
end
So, for example, you want to change the "Save" option in the menu (since I just disable it, anyway) to call the database. Change this in Scene_Menu:
Code:
when 4 #the save option
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Call database menu
$scene = Scene_CharMenu.new
Now, to explain how this works. The menu calls entries based on number. You make a database yourself (which I'll get to), with each element given a number. The menu uses this number to display the entry. It also displays an image, named after this number. The image must be in Graphics/Pictures/characters/
So, for example, if I want to add an entry, I look in the second code section Window_CharMenu, at the bottom and add a title:
Code:
case index
when 0
return "Rudaux"
when 1
return "Hilda"
when 2 #<----- new entry
return "The great war."
end
Now go to the third section, Window_Character, and add the actual entry:
Code:
when 0
#general length guideline----------------------|
@L1 = "Rudaux"
@L2 = "Age: 19"
@L3 = "Zodiac: Capricorn"
@L4 = "Height: 181cm"
@L5 = "Weight: 93.6kg"
when 1
@L1 = "Hilda"
@L2 = "Age: 29"
@L3 = "And she did stuff, yeah, yeah."
when 2 #<----- new entry
@L1 = "Ages ago there was a great war."
@L2 = "Lots of people died. It was sad."
end
Notice you don't have to meet a certain number of lines. There is a general length guideline at the top so you don't make it too wide, and each entry can support up to 18 lines. The last thing to do now is make the character directory in Pictures, and add 2.png (or jpg, it doesn't really matter) Once again, that's Graphics/Pictures/characters/2.png
Now that it's in the database and happily waiting to be discovered, we have to give the entry to the player, so he can access it from the menu. In an event, call a script. Put in the script:
Code:
$chardata.push(0)
$chardata.push(2)
Updated to v1.1
Cleaned it up a bit, made it easier to impliment, and overall more user-friendly
For a game I'm working on, I decided to make a kind of database accessible from the menu that would let you look through all of the characters you've met so far in the game, showing pictures of them all. So at any point you can check the database and see who all you've met. Due to the flexible nature of the coding, it doesn't actually have to be characters, but just snipits of information you run across. Essentially it's an expanding database with entries that can be added at the game maker's will, whenever the player sees a specific event. However, until I figure out a way around it, it is mandatory that you have a picture to associate with each entry. It is easy enough, however, to just put in a blank image for an entry with no picture (say, for example, a .png entirely set to transparent) It also allows you to use the "shoulder" buttons Q and W to go through the database you've made. Now I'm not the best scripter in the world, and though I know a decent amount of C++, this is the first real work I've done with Ruby. As such, I'm pretty sure it could be written better or improved by someone else :P
The code is divided into three sections that just need to be inserted anywhere above main.
entry 1
entry 2
entry 3
From there, the database menu can be called with:
Code:
$scene = Scene_CharMenu.new
So, for example, you want to change the "Save" option in the menu (since I just disable it, anyway) to call the database. Change this in Scene_Menu:
Code:
when 4 #the save option
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Call database menu
$scene = Scene_CharMenu.new
Now, to explain how this works. The menu calls entries based on number. You make a database yourself (which I'll get to), with each element given a number. The menu uses this number to display the entry. It also displays an image, named after this number. The image must be in Graphics/Pictures/characters/
So, for example, if I want to add an entry, I look in the second code section Window_CharMenu, at the bottom and add a title:
Code:
case index
when 0
return "Rudaux"
when 1
return "Hilda"
when 2 #<----- new entry
return "The great war."
end
Now go to the third section, Window_Character, and add the actual entry:
Code:
when 0
#general length guideline----------------------|
@L1 = "Rudaux"
@L2 = "Age: 19"
@L3 = "Zodiac: Capricorn"
@L4 = "Height: 181cm"
@L5 = "Weight: 93.6kg"
when 1
@L1 = "Hilda"
@L2 = "Age: 29"
@L3 = "And she did stuff, yeah, yeah."
when 2 #<----- new entry
@L1 = "Ages ago there was a great war."
@L2 = "Lots of people died. It was sad."
end
Notice you don't have to meet a certain number of lines. There is a general length guideline at the top so you don't make it too wide, and each entry can support up to 18 lines. The last thing to do now is make the character directory in Pictures, and add 2.png (or jpg, it doesn't really matter) Once again, that's Graphics/Pictures/characters/2.png
Now that it's in the database and happily waiting to be discovered, we have to give the entry to the player, so he can access it from the menu. In an event, call a script. Put in the script:
Code:
$chardata.push(0)
$chardata.push(2)
Now, you see, you can access element 0 "Rudaux" and 2 "The great war" from the database menu.
Screenshots below show a database with many more entries. In my game, I used it as a character database, logging everyone I've met, but since it lets you add any entry at any time, and lets you add any information inside, this can be used as any kind of expanding information database for the player.