HUNTERDom Jun 09, 2013 10:14 pm
Super Usuario
Insertar nombre del heroe con teclado
INTRODUCCION:
Excelente script que te permite utilizar el teclado para insertar
el nombre de los personajes anteriormente este Script fue creado
por lasso para el RMVX y pasado al RMVXAce
por su mismo creador lasso.
IMAGEN DE MUESTRA:
CREDITOS:
lasso
SCRIPT:
- Código:
################################################################################
# Inserir nome do herói com o teclado Ace #
################################################################################
#--------------------------------Créditos--------------------------------------#
################################################################################
# Por: Lasso. #
################################################################################
#-----------------------------Características----------------------------------#
################################################################################
# Tem as mesmas funções do "Inserir nome do herói", porém usa o teclado. #
################################################################################
#--------------------------------Intruções-------------------------------------#
################################################################################
# Coloque acima de Main. #
# #
# Vá à 3ª aba dos comandos do evento, cloque "Chamar Script" e chame isso #
# change_name(id, caracteres) #
# sendo id o id do personagem e caracteres o numero de caracteres #
# nao tem limite pro numero de caracteres #
################################################################################
$nome_id = 0
$nome_n = 0
module Keys
@getAsyncKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'i', 'i')
@last_array = Array.new(256, false)
@trigger = Array.new(256, false)
@press = Array.new(256, false)
def self.update
@trigger = Array.new(256, false)
@press = Array.new(256, false)
for i in 0..255
@press[i] = (@getAsyncKeyState.call(i) == 0)? false : true
if @last_array[i] == false and @press[i] == true
@trigger[i] = true
end
end
@last_array = @press
end
def self.trigger?(i)
return @trigger[i]
end
def self.press?(i)
return @press[i]
end
end
module Input
class << self
alias keys_update update
end
def self.update
self.keys_update
Keys.update
end
end
class Window_Name < Window_Base
attr_reader :name
attr_reader :index
attr_reader :max_char
def initialize(actor_id, max_char)
super(0, 0, 544, 128)
@actor = $game_actors[actor_id]
@name = @actor.name
@max_char = max_char
@default_name = @name
@index = @name.size
self.active = false
refresh
update_cursor
end
def restore_default
@name = @default_name
@index = @name.size
refresh
update_cursor
end
def add(character)
if @index < @max_char and character != ''
@name += character
@index += 1
refresh
update_cursor
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
end
end
def item_rect(index)
rect = Rect.new(0, 0, 0, 0)
rect.x = 220 - (@max_char + 1) * 12 + index * 24
rect.y = 36
rect.width = 24
rect.height = line_height
return rect
end
def refresh
self.contents.clear
draw_actor_face(@actor, 0, 0)
name_array = @name.split(//)
for i in 0...@max_char
c = name_array[i]
c = '_' if c == nil
self.contents.draw_text(item_rect(i), c, 1)
end
end
def update_cursor
self.cursor_rect = item_rect(@index)
end
def update
super
update_cursor
end
end
class Scene_NameInput < Scene_MenuBase
CHARACTERS = [[65,'a'],[66,'b'],[67,'c'],[68,'d'],[69,'e'],[70,'f'],[71,'g'],[72,'h'],[73,'i'],[74,'j'],[75,'k'],[76,'l'],[77,'m'],[78,'n'],[79,'o'],[80,'p'],[81,'q'],[82,'r'],[83,'s'],[84,'t'],[85,'u'],[86,'v'],[87,'w'],[88,'x'],[89,'y'],[90,'z'],[48,'0'],[49,'1'],[50,'2'],[51,'3'],[52,'4'],[53,'5'],[54,'6'],[55,'7'],[56,'8'],[57,'9'],[32,' '],[96,'0'],[97,'1'],[98,'2'],[99,'3'],[100,'4'],[101,'5'],[102,'6'],[103,'7'],[104,'8'],[105,'9']]
ENTER = 13
BACKSPACE = 8
LEFT_SHIFT = 160
RIGHT_SHIFT = 161
def start
super
@actor = $game_actors[$nome_id]
@edit_window = Window_Name.new($nome_id, $nome_n)
end
def terminate
super
@edit_window.dispose
end
def update
super
@edit_window.update
if Keys.trigger?(BACKSPACE)
if @edit_window.index > 0
@edit_window.back
end
elsif Keys.trigger?(ENTER)
if @edit_window.name == ''
@edit_window.restore_default
else
@actor.name = @edit_window.name
return_scene
end
end
for i in CHARACTERS
if Keys.trigger?(i[0])
unless @edit_window.index == @edit_window.max_char
case shift?
when true
@edit_window.add(i[1].upcase)
when false
@edit_window.add(i[1])
end
end
end
end
end
def shift?
return (Keys.press?(LEFT_SHIFT) or Keys.press?(RIGHT_SHIFT))
end
end
def change_name(id,characters)
$nome_id = id
$nome_n = characters
SceneManager.call(Scene_NameInput)
end
Nos leemos disfruten el Script y lo recomiendo por que
es muy util para poner los nombres asi no sera necesario
utilizar el Mouse.