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.

Multiple Database/ Database Script Edit

Hello. And to all those who have been tracking all my posts, welcome to the next edition of my script edit thread...
Anyways, I'm using a database script in which you can set different entries and view them later (designed use was a game character database).
I've twisted and mutilated the uses of this as an enemy, character, class, and recipe collection viewer. But, with all those entries in there, it would be very cluttered and messy to keep in just 1 database.
So, here's the scripts. They are divided into 3 parts:
The 2nd part contains the entry headings and part 3 contains teh actual entry text:
#=============================
# ** 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

#====================================
# ** 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

[spoiler="part3]#===============================================================
# ** 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


#===============================================================================

#Creates the window that displays individual information
#===============================================================================


class Window_CharInfo < Window_Base

def initialize(actor)
super(10,10,405,460)
self.contents = Bitmap.new(width - 32, height - 32)
@actor = actor
refresh
end

def refresh
self.contents.clear
#set defaults
@L1 = ""
@L2 = ""
@L3 = ""
@L4 = ""
@L5 = ""
@L6 = ""
@L7 = ""
@L8 = ""
@L9 = ""
@L10 = ""
@L11 = ""
@L12 = ""
@L13 = ""
@L14 = ""
@L15 = ""
@L16 = ""
@L17 = ""
@L18 = ""
#set individual entries
case @actor
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."
end
#print entry
self.contents.draw_text(10,0,380,22,@L1)
self.contents.draw_text(10,23,380,22,@L2)
self.contents.draw_text(10,46,380,22,@L3)
self.contents.draw_text(10,69,380,22,@L4)
self.contents.draw_text(10,92,380,22,@L5)
self.contents.draw_text(10,115,380,22,@L6)
self.contents.draw_text(10,138,380,22,@L7)
self.contents.draw_text(10,161,380,22,@L8)
self.contents.draw_text(10,184,380,22,@L9)
self.contents.draw_text(10,207,380,22,@L10)
self.contents.draw_text(10,230,380,22,@L11)
self.contents.draw_text(10,253,380,22,@L12)
self.contents.draw_text(10,276,380,22,@L13)
self.contents.draw_text(10,299,380,22,@L14)
self.contents.draw_text(10,322,380,22,@L15)
self.contents.draw_text(10,345,380,22,@L16)
self.contents.draw_text(10,368,380,22,@L17)
self.contents.draw_text(10,391,380,22,@L18)
end
end[/spoiler]

NOTE: If you want to try this out, insert the script in order above main, and put 2 pictures (anything) in graphics/pictures/characters (new folder)

Look on page 2 and see that the entries are defined by numbers. To make an entry available, call:
$chardata.push(0) <----Rudaux Entry
$chardata.push(1) <----Hilda Entry

Now call:
$scene = Scene_CharMenu.new
to go to the database.

Now for my request:
I would like to add a box at teh bottom of the first screen that specifies the topic of the entries (ie: characters, monsters, classes) so there is only one type of entry in each database type.
The only hard part, I can imagine is getting the databases to work separately... But I'm pretty sure it's possible.
Heres a link to what I'm looking for:
http://i139.photobucket.com/albums/q295/Esayi/Capture-1.jpg
-I'm not sure what icons or topics I will be using, so leave that customizable.
-Make teh bottom bar left/right scrollable
-Oh and it's not there already, could someone make the box containing the entry headings down/up scrollable?

Thanks again to all who help me with my seemingly impossible and very long requests ^_^XD

EDIT: Ok, I got teh separate databases working fine, so if someone could do teh other part of my request, much thanks will be given ^^
 

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