03-03-2008, 06:20 AM
Character Select Script
by Selwyn
by Selwyn
INTRODUCTION
Selwyn @ HBGames.Org Mon Jun 19, 2006 Wrote:~~requested by Hitomi Kamimura~~
this allows you to make a party by selecting the characters that will be in it.
paste the script in a new section above main
SCREENSHOTS
SCRIPT
The Script
Code:
#==============================================================================
# ? Character Select Script
#------------------------------------------------------------------------------
# created by Selwyn
# selwyn@rmxp.ch
#
# released on the 19th of June 2006
#
# allows to set the initial party.
#
# $scene = Scene_CharSelect.new(IDS_OF_THE_HEROES, MAX_PARTY_SIZE)
#==============================================================================
#==============================================================================
# ? Window_MenuStatus
#==============================================================================
class Window_CharSelect < Window_Selectable
#--------------------------------------------------------------------------
# ? initialize
#--------------------------------------------------------------------------
def initialize(ids)
super(0, 64, 480, 416)
self.contents = Bitmap.new(width - 32, height - 32)
@column_max = 3
@ids = ids
@selected = Array.new(@ids.size, false)
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# ? select
#--------------------------------------------------------------------------
def select(index = @index, bool = true)
@selected[index] = bool
refresh
end
#--------------------------------------------------------------------------
# ? selected?
#--------------------------------------------------------------------------
def selected?
return @selected[@index]
end
#--------------------------------------------------------------------------
# ? actor
#--------------------------------------------------------------------------
def actor
return $game_actors[@ids[@index]]
end
#--------------------------------------------------------------------------
# ? draw_actor_battlegraphic
#--------------------------------------------------------------------------
def draw_actor_battlegraphic(actor, x, y, opacity = 255)
bitmap = RPG::Cache.battler(actor.character_name, actor.character_hue)
w = bitmap.width
h = bitmap.height
src_rect = Rect.new(0, 0, w, h)
self.contents.blt(x - w / 2, y - h / 2, bitmap, src_rect, opacity)
end
#--------------------------------------------------------------------------
# ? refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
@item_max = @ids.size
for i in 0...@item_max
id = @ids[i]
x = i % 3 * 148 + 1
y = i / 3 * 192
actor = $game_actors[id]
opacity = @selected[i] ? 120 : 255
draw_actor_battlegraphic(actor, x + 74, y + 96, opacity)
end
end
#--------------------------------------------------------------------------
# ? update_cursor_rect
#--------------------------------------------------------------------------
def update_cursor_rect
if @index < 0
self.cursor_rect.empty
else
x = @index % 3 * 148 + 1
y = @index / 3 * 192
self.cursor_rect.set(x, y, 149, 192)
end
end
end
#==============================================================================
# ? Window_NameEnter
#==============================================================================
class Window_NameEnter < Window_Selectable
CHARACTER_TABLE =
[
"A","B","C","D","E",
"F","G","H","I","J",
"K","L","M","N","O",
"P","Q","R","S","T",
"U","V","W","X","Y",
"Z"," "," "," "," ",
"a","b","c","d","e",
"f","g","h","i","j",
"k","l","m","n","o",
"p","q","r","s","t",
"u","v","w","x","y",
"z"," "," "," "," ",
]
#--------------------------------------------------------------------------
# ? initialize
#--------------------------------------------------------------------------
def initialize
super(480, 64, 160, 416)
self.contents = Bitmap.new(width - 32, height - 32)
self.index = -1
self.active = false
@column_max = 5
@item_max = CHARACTER_TABLE.size + 2
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# ? character
#--------------------------------------------------------------------------
def character
return CHARACTER_TABLE[@index]
end
#--------------------------------------------------------------------------
# ? refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...@item_max-2
x = i % 5 * 25
y = i / 5 * 25
self.contents.draw_text(x + 1, y, 25, 25, CHARACTER_TABLE[i], 1)
end
self.contents.draw_text(0, 352, 64, 32, "Cancel", 1)
self.contents.draw_text(64, 352, 64, 32, "Valid", 1)
end
#--------------------------------------------------------------------------
# ? update_cursor_rect
#--------------------------------------------------------------------------
def update_cursor_rect
if @index < 0
self.cursor_rect.empty
elsif @index < 60
x = @index % 5 * 25
y = @index / 5 * 25
self.cursor_rect.set(x, y, 25, 25)
elsif @index == 60
self.cursor_rect.set(0, 352, 64, 32)
else
self.cursor_rect.set(64, 352, 64, 32)
end
end
#--------------------------------------------------------------------------
# ? update_help
#--------------------------------------------------------------------------
def update_help
@help_window.set_text("Enter the character's name.")
end
#--------------------------------------------------------------------------
# ? update
#--------------------------------------------------------------------------
def update
super
if Input.trigger?(Input::DOWN)
if @index.between?(55, 57)
$game_system.se_play($data_system.cursor_se)
self.index = 60
elsif @index.between?(58, 59)
$game_system.se_play($data_system.cursor_se)
self.index = 61
end
end
end
end
#==============================================================================
# ? Window_NameValid
#==============================================================================
class Window_NameValid < Window_Base
#--------------------------------------------------------------------------
# ? define instance variable
#--------------------------------------------------------------------------
attr_reader :name
attr_reader :index
#--------------------------------------------------------------------------
# ? initialize
#--------------------------------------------------------------------------
def initialize(actor, max_char = 9)
super(320, 0, 320, 64)
self.contents = Bitmap.new(width - 32, height - 32)
@actor = actor
@name = @actor == nil ? "" : actor.name
@max_char = max_char
name_array = @name.split(//)[0...@max_char]
@name = ""
for i in 0...name_array.size
@name += name_array[i]
end
@default_name = @name
@index = name_array.size
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# ? actor=
#--------------------------------------------------------------------------
def actor=(actor)
@actor = actor
@name = @actor == nil ? "" : actor.name
name_array = @name.split(//)[0...@max_char]
@name = ""
for i in 0...name_array.size
@name += name_array[i]
end
@default_name = @name
@index = name_array.size
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# ? restore_default
#--------------------------------------------------------------------------
def restore_default
@name = @default_name
@index = @name.split(//).size
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
# ? add
#--------------------------------------------------------------------------
def add(character)
if @index < @max_char and character != ""
@name += character
@index += 1
refresh
update_cursor_rect
end
end
#--------------------------------------------------------------------------
# ? back
#--------------------------------------------------------------------------
def back
if @index > 0
name_array = @name.split(//)
@name = ""
for i in 0...name_array.size-1
@name += name_array[i]
end
@index -= 1
refresh
update_cursor_rect
end
end
#--------------------------------------------------------------------------
# ? refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
name_array = @name.split(//)
for i in 0...@max_char
c = name_array[i]
if c == nil
c = "?"
end
x = i * 28
self.contents.draw_text(x, 0, 28, 32, c, 1)
end
end
#--------------------------------------------------------------------------
# ? update_cursor_rect
#--------------------------------------------------------------------------
def update_cursor_rect
x = @index * 28
self.cursor_rect.set(x, 0, 28, 32)
end
#--------------------------------------------------------------------------
# ? update
#--------------------------------------------------------------------------
def update
super
update_cursor_rect
end
end
#==============================================================================
# ? Scene_CharSelect
#==============================================================================
class Scene_CharSelect
#--------------------------------------------------------------------------
# ? initialize
#--------------------------------------------------------------------------
def initialize(ids = [1, 2, 3, 4, 5, 6], party_size = 4)
@ids = ids
@party_size = party_size
end
#--------------------------------------------------------------------------
# ? main
#--------------------------------------------------------------------------
def main
@select_window = Window_CharSelect.new(@ids)
@name_window = Window_NameEnter.new
@help_window = Window_Help.new
@help_window.width = 320
@help_window.contents = Bitmap.new(288, 32)
@name_window.help_window = @help_window
@valid_window = Window_NameValid.new(nil)
@step = 0
@selected_indexes = []
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@select_window.dispose
@name_window.dispose
@help_window.dispose
@valid_window.dispose
end
#--------------------------------------------------------------------------
# ? update
#--------------------------------------------------------------------------
def update
if @select_window.active
case @step
when 0
@help_window.set_text("Choose the main Character.")
when 1
@help_window.set_text("Choose the first Partner")
when 2
@help_window.set_text("Choose the second Partner")
when 3
@help_window.set_text("Choose the third Partner")
end
end
@select_window.update
@name_window.update
@help_window.update
if @select_window.active
update_select
return
end
if @name_window.active
update_name
return
end
end
#--------------------------------------------------------------------------
# ? update_select
#--------------------------------------------------------------------------
def update_select
if Input.trigger?(Input::C)
if @select_window.selected?
$game_system.se_play($data_system.buzzer_se)
return
end
if @select_window.actor == nil
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
@valid_window.actor = @select_window.actor
@select_window.active = false
@name_window.index = 0
@name_window.active = true
return
end
if Input.trigger?(Input::B)
if $game_party.actors.empty? or @step == 0
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.cancel_se)
@step -= 1
id = $game_party.actors[@step].id
$game_party.remove_actor(id)
@select_window.select(@selected_indexes[@step-1], false)
return
end
end
#--------------------------------------------------------------------------
# ? update_name
#--------------------------------------------------------------------------
def update_name
if Input.trigger?(Input::C)
if @name_window.index < 60
$game_system.se_play($data_system.decision_se)
@valid_window.add(@name_window.character)
elsif @name_window.index == 60
$game_system.se_play($data_system.cancel_se)
@valid_window.actor = nil
@select_window.active = true
@name_window.index = -1
@name_window.active = false
else
$game_system.se_play($data_system.decision_se)
@select_window.active = true
@select_window.select
@name_window.index = -1
@name_window.active = false
$game_party.add_actor(@select_window.actor.id)
$game_party.actors[@step].name = @valid_window.name
@selected_indexes.push(@select_window.index)
@step += 1
@valid_window.actor = nil
if @step == @party_size
$scene = Scene_Map.new
end
end
return
end
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@valid_window.back
return
end
end
end
HOW TO USE
first, you need to decide what characters you will display on the select screen, go in the database and write down the id of the characters you want.
(example : 1 arshes, 7 gloria, etc...)
once you have those number, use the call script command in an event, and write them in that way : (I took some other to have 6 characters)
Code:
ids = [1, 7, 5, 6, 4, 2]
so add this after the 'ids = ' thing :
Code:
$scene = Scene_CharSelect.new(ids, 4)
Code:
ids = [1, 7, 5, 6, 4, 2]
$scene = Scene_CharSelect.new(ids, 4)
TERMS AND CONDITIONS
Enjoy, Give Credit.