Introduction
There ya go, folks - my first released script... you may have noticed I'm not into releasing scripts from my game at all, but this one is an exeption because I've searched for a similar script long ago... well, in the end, I made it myself :P
Well, since you're able to get this script, too, you have to endure my painfully short introduction text XD
Purpose
Allows you to enter the heroes name by keyboard. Supported keys are a-z/A-Z, Shift, Space and Backspace to input the character's name, as well as two different modes (8-Character and 16-Character, automatica)
lly triggered) and two possible actor characterset sizes (triggerable via the @size variable inside Window_NameEdit).
Screenshots
http://img53.imageshack.us/img53/9718/nameinputxo6.th.jpg[/IMG]
8-Character Version
Script
Instructions
Insert the Keyboard Input Script above all other scripts (if you don't already have it; if you experience problems with the name input script, please try the version I posted above), insert the Name Input Script above main, below Scene_Name and Window_NameEdit. Both of them aren't needed anymore, Window_NameInput becomes redundant.
To call it, just use the default Enter Hero Name event command.
They're several ways to modify it... obviously, there are two versions of Window_NameEdit: a 8-character one and a 16-character one. It adjusts it's size automatically, depending on how many characters you choose to have in the event command. No bugs with this version using more than 8 characters, BTW.
Also, there's a variable called @size inside main definition of Window_NameEdit. This variable determines the y-level of the character sprite. If you use RTP-sized or similar characters, use 0, for everything bigger like RO's, HalfKaizers or such, use 1.
You can of course change the text inside Window_NameHint. Check line 106 of the Name Input Script for the draw_text command.
Bugs
None known
FAQs
Several, read the thread for Q&A...
Credits & Thanks
BlueScope (myself) for creating this... as you might've already guessed :D,
Cybersam for writing a fitting Keyboard Input Module,
Trickster for helping me out with the shortening of the input processing.
There ya go, folks - my first released script... you may have noticed I'm not into releasing scripts from my game at all, but this one is an exeption because I've searched for a similar script long ago... well, in the end, I made it myself :P
Well, since you're able to get this script, too, you have to endure my painfully short introduction text XD
Purpose
Allows you to enter the heroes name by keyboard. Supported keys are a-z/A-Z, Shift, Space and Backspace to input the character's name, as well as two different modes (8-Character and 16-Character, automatica)
lly triggered) and two possible actor characterset sizes (triggerable via the @size variable inside Window_NameEdit).
Screenshots
http://img53.imageshack.us/img53/9718/nameinputxo6.th.jpg[/IMG]
8-Character Version
Script
Code:
#==============================================================================
# Keyboard Input Module
#----------------------------------------------------------------------------
# Script by Cybersam
#==============================================================================
module Input
@keys = []
@pressed = []
Mouse_Left = 1
Mouse_Right = 2
Mouse_Middle = 4
Back= 8
Tab = 9
Enter = 13
Shift = 16
Ctrl = 17
Alt = 18
Esc = 27
Space = 32
Numberkeys = {}
Numberkeys[0] = 48 # => 0
Numberkeys[1] = 49 # => 1
Numberkeys[2] = 50 # => 2
Numberkeys[3] = 51 # => 3
Numberkeys[4] = 52 # => 4
Numberkeys[5] = 53 # => 5
Numberkeys[6] = 54 # => 6
Numberkeys[7] = 55 # => 7
Numberkeys[8] = 56 # => 8
Numberkeys[9] = 57 # => 9
Numberpad = {}
Numberpad[0] = 45
Numberpad[1] = 35
Numberpad[2] = 40
Numberpad[3] = 34
Numberpad[4] = 37
Numberpad[5] = 12
Numberpad[6] = 39
Numberpad[7] = 36
Numberpad[8] = 38
Numberpad[9] = 33
Letters = {}
Letters["A"] = 65
Letters["B"] = 66
Letters["C"] = 67
Letters["D"] = 68
Letters["E"] = 69
Letters["F"] = 70
Letters["G"] = 71
Letters["H"] = 72
Letters["I"] = 73
Letters["J"] = 74
Letters["K"] = 75
Letters["L"] = 76
Letters["M"] = 77
Letters["N"] = 78
Letters["O"] = 79
Letters["P"] = 80
Letters["Q"] = 81
Letters["R"] = 82
Letters["S"] = 83
Letters["T"] = 84
Letters["U"] = 85
Letters["V"] = 86
Letters["W"] = 87
Letters["X"] = 88
Letters["Y"] = 89
Letters["Z"] = 90
Fkeys = {}
Fkeys[1] = 112
Fkeys[2] = 113
Fkeys[3] = 114
Fkeys[4] = 115
Fkeys[5] = 116
Fkeys[6] = 117
Fkeys[7] = 118
Fkeys[8] = 119
Fkeys[9] = 120
Fkeys[10] = 121
Fkeys[11] = 122
Fkeys[12] = 123
Collon = 186 # => \ |
Equal = 187 # => = +
Comma = 188 # => , <
Underscore = 189 # => - _
Dot = 190 # => . >
Backslash = 191 # => / ?
Lb = 219
Rb = 221
Quote = 222 # => '"
#-------------------------------------------------------------------------------
USED_KEYS = [Mouse_Left, Mouse_Right, Mouse_Middle]
#-------------------------------------------------------------------------------
module_function
#--------------------------------------------------------------------------
def triggered?(key)
Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(key) & 0x01 == 1
end
#--------------------------------------------------------------------------
def check(key)
Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(key) & 0x01 == 1
end
#--------------------------------------------------------------------------
def pressed?(key)
return true unless Win32API.new("user32","GetKeyState",['i'],'i').call(key).between?(0, 1)
return false
end
#--------------------------------------------------------------------------
def mouse_update
@used_i = []
for i in USED_KEYS
x = check(i)
if x == true
@used_i.push(i)
end
end
end
#--------------------------------------------------------------------------
def self.C
self.trigger?(C)
end
#--------------------------------------------------------------------------
def self.B
self.trigger?(B)
end
#--------------------------------------------------------------------------
def self.A
self.trigger?(A)
end
#--------------------------------------------------------------------------
def self.Down
self.trigger?(DOWN)
end
#--------------------------------------------------------------------------
def self.Up
self.trigger?(UP)
end
#--------------------------------------------------------------------------
def self.Right
self.trigger?(RIGHT)
end
#--------------------------------------------------------------------------
def self.Left
self.trigger?(LEFT)
end
#--------------------------------------------------------------------------
def self.Anykey
if A or B or C or Down or Up or Right or Left
return true
else
return false
end
end
#--------------------------------------------------------------------------
end
Code:
#==============================================================================
# Name Input Script v1.4
#--------------------------------------------------------------------------
# Script by BlueScope
#==============================================================================
class Window_NameEdit < Window_Base
#--------------------------------------------------------------------------
attr_reader :name
attr_reader :index
#--------------------------------------------------------------------------
def initialize(actor, max_char)
super(0, 128, 640, 160)
self.contents = Bitmap.new(width - 32, height - 32)
@actor = actor
@name = actor.name
@max_char = max_char
if @max_char < 9
self.x = 128
self.width = 384
end
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
@size = 0 # 0 for small sprites, 1 for bigger sprites
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
def restore_default
@name = @default_name
@index = @name.split(//).size
refresh
update_cursor_rect
end
#--------------------------------------------------------------------------
def add(character)
if @index < @max_char and character != ""
@name += character
@index += 1
refresh
update_cursor_rect
end
end
#--------------------------------------------------------------------------
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
#--------------------------------------------------------------------------
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 = 320 - 16 * 14 + i * 28
self.contents.draw_text(x, 49, 28, 32, c, 1)
end
draw_actor_graphic(@actor, 56, @size == 0 ? 92 : 112)
end
#--------------------------------------------------------------------------
def update_cursor_rect
if @index < @max_char-1
self.cursor_rect.set((@max_char > 8 ? -128 : -16) + @max_char * 14 + @index * 28, 48, 28, 32)
else
self.cursor_rect.set((@max_char > 8 ? -128 : -16) + @max_char * 14 + (@max_char-1) * 28, 48, 28, 32)
end
end
#--------------------------------------------------------------------------
def update
super
update_cursor_rect
end
#--------------------------------------------------------------------------
end
class Window_NameHint < Window_Base
#--------------------------------------------------------------------------
def initialize
super(128, 288, 384, 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.opacity = 0
refresh
end
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, self.width-40, 32, "Please enter Hero Name using the Keyboard", 1)
end
#--------------------------------------------------------------------------
end
class Scene_Name
#--------------------------------------------------------------------------
def main
@actor = $game_actors[$game_temp.name_actor_id]
@edit_window = Window_NameEdit.new(@actor, $game_temp.name_max_char)
@hint_window = Window_NameHint.new
@dummy_window = Window_Base.new(128, 288, 384, 64)
if $game_temp.name_max_char > 8
@dummy_window.x = 0
@dummy_window.width = 640
end
Graphics.transition
loop do
Graphics.update
update
if $scene != self
break
end
end
Graphics.freeze
@edit_window.dispose
@hint_window.dispose
@dummy_window.dispose
end
#--------------------------------------------------------------------------
def change_name
@actor.name = @edit_window.name
$game_system.se_play($data_system.decision_se)
$scene = Scene_Map.new
if @edit_window.index == $game_temp.name_max_char
$game_system.se_play($data_system.buzzer_se)
return
end
end
#--------------------------------------------------------------------------
def input_processing
if @edit_window.index == $game_temp.name_max_char
$game_system.se_play($data_system.buzzer_se)
else
$game_system.se_play($data_system.cursor_se)
end
end
#--------------------------------------------------------------------------
def update
@edit_window.update
if Input.triggered?(27) # [ESCAPE]
$game_system.se_play($data_system.decision_se)
@edit_window.restore_default
return
end
if Input.triggered?(8) # [BACKSPACE]
if @edit_window.index == 0
return
end
$game_system.se_play($data_system.cancel_se)
@edit_window.back
return
end
if Input.triggered?(13) # [ENTER]
if @edit_window.name == ""
@edit_window.restore_default
return
end
change_name
end
if Input.triggered?(32) # [SPACE]
input_processing
@edit_window.add(" ")
end
for letter in 'A'..'Z'
if Input.triggered?(letter[0])
if Input.pressed?(16)
input_processing
@edit_window.add(letter.upcase)
else
input_processing
@edit_window.add(letter.downcase)
end
end
end
end
#--------------------------------------------------------------------------
end
Instructions
Insert the Keyboard Input Script above all other scripts (if you don't already have it; if you experience problems with the name input script, please try the version I posted above), insert the Name Input Script above main, below Scene_Name and Window_NameEdit. Both of them aren't needed anymore, Window_NameInput becomes redundant.
To call it, just use the default Enter Hero Name event command.
They're several ways to modify it... obviously, there are two versions of Window_NameEdit: a 8-character one and a 16-character one. It adjusts it's size automatically, depending on how many characters you choose to have in the event command. No bugs with this version using more than 8 characters, BTW.
Also, there's a variable called @size inside main definition of Window_NameEdit. This variable determines the y-level of the character sprite. If you use RTP-sized or similar characters, use 0, for everything bigger like RO's, HalfKaizers or such, use 1.
You can of course change the text inside Window_NameHint. Check line 106 of the Name Input Script for the draw_text command.
Bugs
None known
FAQs
Several, read the thread for Q&A...
Credits & Thanks
BlueScope (myself) for creating this... as you might've already guessed :D,
Cybersam for writing a fitting Keyboard Input Module,
Trickster for helping me out with the shortening of the input processing.