[Hướng Dẫn] Hướng dẫn Tạo Cheats bằng Event [A] & Nhập tên và số từ bàn phím [VXA]
[size=x-large]PHẦN I: TẠO CHEATS BẰNG EVENT [A][/size]
*Chú thích : kí hiệu [A] để chỉ toàn bộ 3 phần mềm XP, VX và VXA
+ B1: Vào DataBase thêm 1 Actor mới, để trống mọi chỗ có thể để trống
+ B2: Tạo 1 event bất kì
Chọn "Name Input Processing" <Tab thứ 3, Scene Control, Dòng thứ 3>
Chọn Actor mới vừa tạo để đổi tên
Đặt "max characters" là giá trị lớn nhất <là 16 hay sao ấy> -> OK
Chọn "Conditional Branch" <Tab 1, Flow Control, Dòng 1>, qua tab 2, chọn "Actor", ở ô "Actor" chọn actor vừa tạo ở B1
Chọn "Name", đây là chỗ ta cài tên cheat, <VD: ở ô "Name" em đặt là "Tui ngheo"> -> OK
+ B3: Đặt những thứ sẽ được khi cheat vào phần "Nếu điều kiện đúng" của điều kiện trên, <VD: +50.000G>
+ B4: Sau khi cheat xong, ta cài tên actor về lại ban đầu <ban đầu là trống trơn ak!>
bằng lệnh "Change Actor Name" < Tab 1, Actor, Dòng 10>

Nên cho dòng này xuốg cuối event
B5: Bấm nút [REP+]
Ưu điểm: khỏi cần Scripts
Nhược điểm: Giới hạn 16 kí tự
Q: Có thể nhập tiếng việt?
A: Có nhưng chỉ có cách nhập theo kiểu truyền thống, chưa thể nhập từ bàn phím
Bỏ vào Window_NameInput \class Window_NameInput < Window_Selectable và nhớ set font Arial nữa!
Đối với ai muốn nhập tiếng việt thì chỉ có thể cùng cách này, ngược lại xem bên dưới
[size=x-large]PHẦN II: NHẬP TÊN VÀ SỐ TỪ BÀN PHÍM [VXA][/size]
*Chú thích : kí hiệu [VXA] để chỉ phần mềm VXA
1: Nhập Tên:
Chèn trên Main, dưới Materials, theo thứ tự CORE trước, SCRIPT sau:
CORE:
SCRIPT:
2: Nhập số:
Gọi bảng nhập số bằng Script call sau: keypad_input
Sử dụng [KEYPAD_VAR] để nhập số cho Var tương ứng và [MAX_NUM] để chọn số lượng chữ số, thông thường thì max là 8 số thôi, ko nên để nhìu quá!
Gọi script sau để đổi biến [KEYPAD_VAR] : Keypad::KEYPAD_VAR = x (với x là Var tương ứng)
Gọi script sau để đổi biến [MAX_NUM] : Keypad::MAX_NUM = x (với x là số tương ứng từ 1 => 8)
* Nhược điểm: Ko thể dùng Script Chuột
Đã Test!
Nhớ bấm REP+ rồi thực hành liền đi!! =]
*Chú thích : kí hiệu [A] để chỉ toàn bộ 3 phần mềm XP, VX và VXA
+ B1: Vào DataBase thêm 1 Actor mới, để trống mọi chỗ có thể để trống
+ B2: Tạo 1 event bất kì
Chọn "Name Input Processing" <Tab thứ 3, Scene Control, Dòng thứ 3>
Chọn Actor mới vừa tạo để đổi tên
Đặt "max characters" là giá trị lớn nhất <là 16 hay sao ấy> -> OK
Chọn "Conditional Branch" <Tab 1, Flow Control, Dòng 1>, qua tab 2, chọn "Actor", ở ô "Actor" chọn actor vừa tạo ở B1
Chọn "Name", đây là chỗ ta cài tên cheat, <VD: ở ô "Name" em đặt là "Tui ngheo"> -> OK
+ B3: Đặt những thứ sẽ được khi cheat vào phần "Nếu điều kiện đúng" của điều kiện trên, <VD: +50.000G>
+ B4: Sau khi cheat xong, ta cài tên actor về lại ban đầu <ban đầu là trống trơn ak!>
bằng lệnh "Change Actor Name" < Tab 1, Actor, Dòng 10>

Nên cho dòng này xuốg cuối event
B5: Bấm nút [REP+]
Ưu điểm: khỏi cần Scripts
Nhược điểm: Giới hạn 16 kí tự
Q: Có thể nhập tiếng việt?
A: Có nhưng chỉ có cách nhập theo kiểu truyền thống, chưa thể nhập từ bàn phím
LATIN1 = [ 'A','B','C','D','E', 'a','b','c','d','e',
'F','G','H','I','J', 'f','g','h','i','j',
'K','L','M','N','O', 'k','l','m','n','o',
'P','Q','R','S','T', 'p','q','r','s','t',
'U','V','W','X','Y', 'u','v','w','x','y',
'Z','','^','_', 'z','{','}','|','~',
'0','1','2','3','4', '!','#','$','%','&',
'5','6','7','8','9', '(',')','*','+','-',
'/','=','@','<','>', ':',';',' ','>>2','OK']
LATIN2 = [ 'Á','À','Ả','Ã','Ạ', 'Ú','Ù','Ủ','Ũ','Ụ',
'Ắ','Ằ','Ẳ','Ẵ','Ặ', 'Ứ','Ừ','Ử','Ữ','Ự',
'Ấ','Ầ','Ẩ','Ẫ','Ậ', 'Ý','Ỳ','Ỷ','Ỹ','Ỵ',
'É','È','Ẻ','Ẽ','Ẹ', 'Ă','Â','Đ','Ê','Ô',
'Ế','Ề','Ể','Ễ','Ệ', 'Ơ','Ư','№','™','Ω',
'Í','Ì','Ỉ','Ĩ','Ị', '℮','⅓','⅔','⅛','⅜',
'Ó','Ò','Ỏ','Õ','Ọ', '⅝','⅞','←','↑','→',
'Ố','Ồ','Ỗ','Ỗ','Ộ', '↔','↕','↨','↓','∂',
'Ớ','Ờ','Ở','Ỡ','Ợ', '∆','∏','∑','>>3','OK']
LATIN3 = [ 'á','à','ả','ã','ạ', 'ú','ù','ủ','ũ','ụ',
'ắ','ằ','ẳ','ẵ','ặ', 'ứ','ừ','ử','ữ','ự',
'ấ','ầ','ẩ','ẫ','ậ', 'ý','ỳ','ỷ','ỹ','ỵ',
'é','è','ẻ','ẽ','ẹ', 'ă','â','đ','ê','ô',
'ế','ề','ể','ễ','ệ', 'ơ','ư','⌂','▪','▲',
'í','ì','ỉ','ĩ','ị', '►','▼','◄','◊','●',
'ó','ò','ỏ','õ','ọ', '◦','☺','☼','♫','♪',
'ố','ồ','ỗ','ỗ','ộ', '♀','♂','♠','♣','♥',
'ớ','ờ','ở','ỡ','ợ', '♦','۞','۩','>>4','OK']
LATIN4 = [ '∙','√','∞','∩','≈', '٭','¤','¥','§','¨',
'≠','≡','┌','┐','├', '©','®','ª','¯','±',
'┬','┼','└','┘','┤', 'µ','¶','¹','²','³',
'┴','═','║','╔','╗', '´','`','º','¿','×',
'╦','╩','╬','╚','╝', 'Ø','Þ','ß','÷','Ħ',
'╣','╠','▀','▄','█', 'Ə','ƒ','Θ','Φ','έ',
'▌','▐','░','▒','▓', 'α','β','γ','δ','ε',
'■','□','▫','▬','◙', 'ζ','η','θ','λ','ξ',
'地','風','水','火','光', '暗','阱','拼','1<<','OK']
'F','G','H','I','J', 'f','g','h','i','j',
'K','L','M','N','O', 'k','l','m','n','o',
'P','Q','R','S','T', 'p','q','r','s','t',
'U','V','W','X','Y', 'u','v','w','x','y',
'Z','','^','_', 'z','{','}','|','~',
'0','1','2','3','4', '!','#','$','%','&',
'5','6','7','8','9', '(',')','*','+','-',
'/','=','@','<','>', ':',';',' ','>>2','OK']
LATIN2 = [ 'Á','À','Ả','Ã','Ạ', 'Ú','Ù','Ủ','Ũ','Ụ',
'Ắ','Ằ','Ẳ','Ẵ','Ặ', 'Ứ','Ừ','Ử','Ữ','Ự',
'Ấ','Ầ','Ẩ','Ẫ','Ậ', 'Ý','Ỳ','Ỷ','Ỹ','Ỵ',
'É','È','Ẻ','Ẽ','Ẹ', 'Ă','Â','Đ','Ê','Ô',
'Ế','Ề','Ể','Ễ','Ệ', 'Ơ','Ư','№','™','Ω',
'Í','Ì','Ỉ','Ĩ','Ị', '℮','⅓','⅔','⅛','⅜',
'Ó','Ò','Ỏ','Õ','Ọ', '⅝','⅞','←','↑','→',
'Ố','Ồ','Ỗ','Ỗ','Ộ', '↔','↕','↨','↓','∂',
'Ớ','Ờ','Ở','Ỡ','Ợ', '∆','∏','∑','>>3','OK']
LATIN3 = [ 'á','à','ả','ã','ạ', 'ú','ù','ủ','ũ','ụ',
'ắ','ằ','ẳ','ẵ','ặ', 'ứ','ừ','ử','ữ','ự',
'ấ','ầ','ẩ','ẫ','ậ', 'ý','ỳ','ỷ','ỹ','ỵ',
'é','è','ẻ','ẽ','ẹ', 'ă','â','đ','ê','ô',
'ế','ề','ể','ễ','ệ', 'ơ','ư','⌂','▪','▲',
'í','ì','ỉ','ĩ','ị', '►','▼','◄','◊','●',
'ó','ò','ỏ','õ','ọ', '◦','☺','☼','♫','♪',
'ố','ồ','ỗ','ỗ','ộ', '♀','♂','♠','♣','♥',
'ớ','ờ','ở','ỡ','ợ', '♦','۞','۩','>>4','OK']
LATIN4 = [ '∙','√','∞','∩','≈', '٭','¤','¥','§','¨',
'≠','≡','┌','┐','├', '©','®','ª','¯','±',
'┬','┼','└','┘','┤', 'µ','¶','¹','²','³',
'┴','═','║','╔','╗', '´','`','º','¿','×',
'╦','╩','╬','╚','╝', 'Ø','Þ','ß','÷','Ħ',
'╣','╠','▀','▄','█', 'Ə','ƒ','Θ','Φ','έ',
'▌','▐','░','▒','▓', 'α','β','γ','δ','ε',
'■','□','▫','▬','◙', 'ζ','η','θ','λ','ξ',
'地','風','水','火','光', '暗','阱','拼','1<<','OK']
Bỏ vào Window_NameInput \class Window_NameInput < Window_Selectable và nhớ set font Arial nữa!
Đối với ai muốn nhập tiếng việt thì chỉ có thể cùng cách này, ngược lại xem bên dưới
[size=x-large]PHẦN II: NHẬP TÊN VÀ SỐ TỪ BÀN PHÍM [VXA][/size]
*Chú thích : kí hiệu [VXA] để chỉ phần mềm VXA
1: Nhập Tên:
Chèn trên Main, dưới Materials, theo thứ tự CORE trước, SCRIPT sau:
CORE:
###--------------------------------------------------------------------------###
# CP Keyboard Input script #
# Version 1.0a #
# #
# Credits: #
# Original code by: Neon Black #
# Modified by: #
# #
# This work is licensed under the Creative Commons Attribution-NonCommercial #
# 3.0 Unported License. To view a copy of this license, visit #
# http://creativecommons.org/licenses/by-nc/3.0/. #
# Permissions beyond the scope of this license are available at #
# http://cphouseset.wordpress.com/liscense-and-terms-of-use/. #
# #
# Contact: #
# NeonBlack - neonblack23@live.com (e-mail) or "neonblack23" on skype #
###--------------------------------------------------------------------------###
###--------------------------------------------------------------------------###
# Revision information: #
# V1.0a - 11.15.2012 #
# Input module bug fix #
# V1.0 - 8.11.2012 #
# Split the console and keyboard module #
# V0.1 - 7.9.2012 #
# Wrote and debugged main script #
###--------------------------------------------------------------------------###
###--------------------------------------------------------------------------###
# Instructions: #
# Place this script in the "Materials" section of the scripts above main. #
# This script adds keyboard usage to your scripts with the use of the new #
# "Keyboard" module. You can do this using both the "Input" module and the #
# "Keyboard" module the same way, ie. Keyboard.trigger?(:kA) or #
# Input.trigger?(:kA) will both have the same effect. To specify keyboard #
# input on any given key, this script uses the letter "k" followed by the #
# name of the key in all caps. For example, a letter would be ":kA" or #
# ":kK" or some other similar form, numbers would be ":k1", ":k2", etc., and #
# named keys would be ":kENTER" or some other key name. #
# To see all the available keys, search for the "Ascii" module. #
###--------------------------------------------------------------------------###
###--------------------------------------------------------------------------###
# The following lines are the actual core code of the script. While you are #
# certainly invited to look, modifying it may result in undesirable results. #
# Modify at your own risk! #
###--------------------------------------------------------------------------###
$imported = {} if $imported == nil
$imported["CP_KEYBOARD"] = 1.0
module V ## Checks a virtual key.
def self.K(key)
return Ascii::SYM[key]
end
end
module Ascii ## Only the keys I bothered to name. Some have 2 names.
SYM = { :k0 => 48, :k1 => 49, :k2 => 50, :k3 => 51, :k4 => 52, :k5 => 53,
:k6 => 54, :k7 => 55, :k8 => 56, :k9 => 57,
:kA => 65, :kB => 66, :kC => 67, :kD => 68, :kE => 69, :kF => 70,
:kG => 71, :kH => 72, :kI => 73, :kJ => 74, :kK => 75, :kL => 76,
:kM => 77, :kN => 78, :kO => 79, :kP => 80, :kQ => 81, :kR => 82,
:kS => 83, :kT => 84, :kU => 85, :kV => 86, :kW => 87, :kX => 88,
:kY => 89, :kZ => 90,
:kENTER => 13, :kRETURN => 13, :kBACKSPACE => 8, :kSPACE => 32,
:kESCAPE => 27, :kESC => 27, :kSHIFT => 16, :kTAB => 9,
:kALT => 18, :kCTRL => 17, :kDELETE => 46, :kDEL => 46,
:kINSERT => 45, :kINS => 45, :kPAGEUP => 33, :kPUP => 33,
:kPAGEDOWN => 34, :kPDOWN => 34, :kHOME => 36, :kEND => 35,
:kLALT => 164, :kLCTRL => 162, :kRALT => 165, :kRCTRL => 163,
:kLSHIFT => 160, :kRSHIFT => 161,
:kLEFT => 37, :kRIGHT => 39, :kUP => 38, :kDOWN => 40,
:kCOLON => 186, :kAPOSTROPHE => 222, :kQUOTE => 222,
:kCOMMA => 188, :kPERIOD => 190, :kSLASH => 191,
:kBACKSLASH => 220, :kLEFTBRACE => 219, :kRIGHTBRACE => 221,
:kMINUS => 189, :kUNDERSCORE => 189, :kPLUS => 187,
:kEQUAL => 187, :kEQUALS => 187, :kTILDE => 192,
:kF1 => 112, :kF2 => 113, :kF3 => 114, :kF4 => 115, :kF5 => 116,
:kF6 => 117, :kF7 => 118, :kF8 => 119, :kF9 => 120, :kF10 => 121,
:kF11 => 122, :kF12 => 123,
}
end
module Keyboard ## The DLL file, function, import, and export.
@key_state = Win32API.new("user32","GetKeyState", 'i', 'i')
@key_paste = Win32API.new("user32","GetClipboardData", 'i', 'i')
@trigger = Array.new(256, false) ## All 3 of the related arrays for checks.
@press = Array.new(256, false)
@repeat = Array.new(256, 0)
@checked = false ## Sets the check state.
def self.update ## Resets the check state each frame.
@checked = false
end
def self.get_key_state ## Sets the key states.
@checked = true
256.times do |vk| ## All virtual keys are checked.
check = @key_state.call(vk) ## Use the DLL to check the key state.
unless check == 1 or check == 0 ## -128 and -127 would be held down keys.
unless @press[vk]
@press[vk] = true ## Start pressing.
@trigger[vk] = true ## Set the trigger.
else
@trigger[vk] = false ## Depress trigger on later frames.
end
@repeat[vk] += 1 ## And change the repeat.
else
@press[vk] = false ## Disable all checks on the key.
@trigger[vk] = false
@repeat[vk] = 0
end
end
end
def self.press?(sym) ## Checks if a key <sym> is pressed down.
return get_symb(sym, :press)
end
def self.trigger?(sym) ## Checks trigger as above.
return get_symb(sym, :trigger)
end
def self.repeat?(sym) ## Checks repeat as above.
return get_symb(sym, :repeat)
end
def self.get_symb(sym, type) ## Check if the <sym> key is <type>.
res = sym.is_a?(Symbol) ? V.K(sym) : sym ## Gets the key's numeric.
return false if res.nil? ## Returns if key is not accepted.
get_key_state unless @checked ## Sets key states.
case type ## Checks the key by numeric.
when :press; return ch_press?(res)
when :trigger; return ch_trigger?(res)
when :repeat; return ch_repeat?(res)
end
return false
end
## The three proper checks. Need a numeric value for a key to check.
def self.ch_press?(sym) ## Held down.
return @press[sym]
end
def self.ch_trigger?(sym) ## Pressed this frame.
return @trigger[sym]
end
def self.ch_repeat?(sym) ## Alternates every few frames.
return true if @repeat[sym] == 1
return true if (@repeat[sym] >= 24 && (@repeat[sym] % 6) == 0)
return false
end
def self.shifted? ## Checks the state of both shift keys.
return true if press?(16)
return true if caps_on?
return false
end
def self.caps_on? ## Checks the state of capslock.
return true if @key_state.call(20) == 1
return false
end
def self.bittype(text) ## The keys accepted by typing.
for i in 48..57 ## Numbers.
if repeat?(i)
text += add_char(i)
end
end
for i in 65..90 ## Letters.
if repeat?(i)
text += add_char(i)
end
end
for i in 186..192 ## Symbols.
if repeat?(i)
text += add_char(i)
end
end
for i in 219..222 ## More symbols.
if repeat?(i)
text += add_char(i)
end
end
text += " " if repeat?(32) ## Space.
if repeat?(8) ## Backspace.
text.chop!
end
return text
end
def self.add_char(key) ## Adds typed characters.
caps = press?(16)
case key
when 48..57
return (key - 48).to_s unless caps
return '!' if key == 49
return '@' if key == 50
return '#' if key == 51
return '$' if key == 52
return '%' if key == 53
return '^' if key == 54
return '&' if key == 55
return '*' if key == 56
return '(' if key == 57
return ')' if key == 48
when 65..90
string = "abcdefghijklmnopqrstuvwxyz"
string.swapcase! if caps
string.swapcase! if caps_on?
return string[key - 65]
when 186; return !caps ? ';' : ':'
when 187; return !caps ? '=' : '+'
when 188; return !caps ? ',' : '<'
when 189; return !caps ? '-' : '_'
when 190; return !caps ? '.' : '>'
when 191; return !caps ? '/' : '?'
when 192; return !caps ? '`' : '~'
when 219; return !caps ? '[' : '{'
when 220; return !caps ? '\\' : '|'
when 221; return !caps ? ']' : '}'
when 222; return !caps ? '\'' : '"'
end
end
def self.press_any_key ## The keys accepted by "any key"
for i in 48..57
return true if trigger?(i)
end
for i in 65..90
return true if trigger?(i)
end
for i in 186..192
return true if trigger?(i)
end
for i in 219..222
return true if trigger?(i)
end
[13, 22, 27, 192, 32].each {|i| return true if trigger?(i)}
return false
end
end
module Input
class << self
alias cp_keyboard_update update unless $@
alias cp_keyboard_press? press? unless $@
alias cp_keyboard_trigger? trigger? unless $@
alias cp_keyboard_repeat? repeat? unless $@
end
def self.update
Keyboard.update
cp_keyboard_update
end
def self.press?(*sym)
if $imported["CP_INPUT"]
cp_keyboard_press?(*sym)
else
sym.any? do |key|
(Keyboard.press?(key) || cp_keyboard_press?(key))
end
end
end
def self.trigger?(*sym)
if $imported["CP_INPUT"]
cp_keyboard_trigger?(*sym)
else
sym.any? do |key|
(Keyboard.trigger?(key) || cp_keyboard_trigger?(key))
end
end
end
def self.repeat?(*sym)
if $imported["CP_INPUT"]
cp_keyboard_repeat?(*sym)
else
sym.any? do |key|
(Keyboard.repeat?(key) || cp_keyboard_repeat?(key))
end
end
end
end
###--------------------------------------------------------------------------###
# End of script. #
###--------------------------------------------------------------------------###
SCRIPT:
=begin
EST - NAME INPUT USING KEYBOARD
v.1.0
Requires:
Neon Black Keyboard Input 1.0a
http://forums.rpgmakerweb.com/index.php?/topic/3456-developer-console/#entry37268
enter the link to his keyboard module script there.
or
http://pastebin.com/raw.php?i=rD4rQtKP
for direct link to his pastebin.
version history
v.1.0 - 2013.02.15 - finish the script
Introduction:
Have you ever feel it's not comfortable to input name by choosing which symbol
then press enter. letter by letter. so time consuming.
this script change that!. instead of choosing symbol and press enter.
you type letter directly from keyboard.
press esc / backspace to erase a character
press enter when you're done. maybe will put confirmation window later.
btw the name input window still there. i just hide it from view and change
some behavior. :D.
Usage
Plug and Play
Compatibility
it should compatible with most script.
If you using Tsukihime Simple Text Input.
put this script ABOVE that script. so the script will also use KEYBOARD :D.
since the script is using name input window too.
=end
module ESTRIOLE
module KEYBOARD_PRESS
KEYBOARDPRESS = {
:k0 => 48, :k1 => 49, :k2 => 50, :k3 => 51, :k4 => 52, :k5 => 53,
:k6 => 54, :k7 => 55, :k8 => 56, :k9 => 57,
:kA => 65, :kB => 66, :kC => 67, :kD => 68, :kE => 69, :kF => 70,
:kG => 71, :kH => 72, :kI => 73, :kJ => 74, :kK => 75, :kL => 76,
:kM => 77, :kN => 78, :kO => 79, :kP => 80, :kQ => 81, :kR => 82,
:kS => 83, :kT => 84, :kU => 85, :kV => 86, :kW => 87, :kX => 88,
:kY => 89, :kZ => 90,
:kCOLON => 186, :kQUOTE => 222,
:kCOMMA => 188, :kPERIOD => 190, :kSLASH => 191,
:kBACKSLASH => 220, :kLEFTBRACE => 219, :kRIGHTBRACE => 221,
:kMINUS => 189, :kEQUAL => 187, :kTILDE => 192,
}
end
end
class Window_NameInput < Window_Selectable
include ESTRIOLE::KEYBOARD_PRESS
alias est_keyboard_name_input_init initialize
def initialize(edit_window)
est_keyboard_name_input_init(edit_window)
self.visible = false
end
def process_handling
return unless open? && active
process_back if Input.repeat?(:kESC) or Input.repeat?(:kBACKSPACE)
check_keyboard_input
end
alias cursor_page_change cursor_pagedown
def check_keyboard_input
KEYBOARDPRESS.each {|key|
@edit_window.add(Keyboard.add_char(Ascii::SYM[key[0]])) if Input.trigger?(key[0])
Sound.play_ok if Input.trigger?(key[0])
}
check_spaces
check_enter
end
def check_spaces
if Input.trigger?(:kSPACE)
@edit_window.add(" ")
Sound.play_ok
end
end
def check_enter
on_name_ok if Input.trigger?(:kENTER)
end
def cursor_pageup;end
def cursor_pagedown;end
end
2: Nhập số:
#------------------------------------------------------------------------------#
# Galv's Keypad Input
#------------------------------------------------------------------------------#
# For: RPGMAKER VX ACE
# Version 1.1
#------------------------------------------------------------------------------#
# 2012-10-15 - Version 1.1 - Allows for a larger max number to show in the box
# 2012-10-5 - Version 1.0 - release
#------------------------------------------------------------------------------#
# The keypad is just a fancy version of the 'Number Input' event command.
# When "OK" is pressed, it outputs the entered number to the chosen variable.
# When "X" is pressed, it outputs -1 to the chosen variable (for eventing).
#
# From then on, it's up to your eventing skills what to do with the number.
# Call the keypad with the script call:
#------------------------------------------------------------------------------#
# keypad_input
#------------------------------------------------------------------------------#
$imported = {} if $imported.nil?
$imported["Keypad"] = true
module Keypad
#------------------------------------------------------------------------------#
# SCRIPT SETUP OPTIONS
#------------------------------------------------------------------------------#
KEYPAD_VAR = 1 # Variable that the keypad stores number in.
MAX_NUM = 6 # Amount of numbers you can enter in the keypad.
OK_SE = ["Heal7", 80, 150] # OK sound effect. ["SE Name", volume, pitch]
#------------------------------------------------------------------------------#
# SCRIPT SETUP OPTIONS
#------------------------------------------------------------------------------#
end
class Scene_Keypad < Scene_MenuBase
def start
super
@number = ""
@edit_window = Window_Numpad.new(@number, @max_char)
@input_window = Window_NumInput.new(@edit_window)
@input_window.set_handler(:confirm, method(:on_input_ok))
@input_window.set_handler(:leave, method(:on_input_x))
@input_window.activate
end
def on_input_ok
$game_variables[Keypad::KEYPAD_VAR] = @edit_window.numeral.to_i
SceneManager.return
end
def on_input_x
$game_variables[Keypad::KEYPAD_VAR] = -1
SceneManager.return
end
end
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# * New Window - Numpad Number Output
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
class Window_Numpad < Window_Base
attr_reader :numeral # number amount
attr_reader :index # cursor position
attr_reader :max_char # maximum number of numbers
def initialize(number, max_char)
x = ((Graphics.width - 185) / 2) - (extend_size * 0.5)
y = (Graphics.height - (fitting_height(4) + fitting_height(9) + 8)) / 2
super(x, y, 185 + extend_size, fitting_height(1))
@max_char = Keypad::MAX_NUM
@numeral = number.to_s[0, @max_char]
@index = @numeral.size
refresh
end
def extend_size
if Keypad::MAX_NUM > 10
20 * (Keypad::MAX_NUM - 10)
else
0
end
end
def add(ch)
return false if @index >= @max_char
@numeral += ch
@index += 1
refresh
return true
end
def back
return on_name_x if @index == 0
@index -= 1
@numeral = @numeral[0, @index]
refresh
return true
end
def on_name_x
$game_variables[Keypad::KEYPAD_VAR] = -1
SceneManager.return
end
def char_width
text_size("0").width + 5
end
def left
numeral_center = (contents_width) / 2
numeral_width = (@max_char) * char_width
return [numeral_center - numeral_width / 2, contents_width - numeral_width].min
end
def item_rect(index)
Rect.new(left + index * char_width, -3, char_width, line_height)
end
def draw_char(index)
contents.font.size = 28
rect = item_rect(index)
rect.x -= 1
rect.width += 4
change_color(normal_color)
draw_text(rect, @numeral[index] || "")
end
def refresh
contents.clear
@numeral.size.times {|i| draw_char(i) }
end
end
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# * New Window - Numpad Input
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
class Window_NumInput < Window_Selectable
NUMPAD = [ '1','2','3','4','5', '6','7','8','9','OK', '0', 'X']
def initialize(edit_window)
super((Graphics.width - 185) / 2, edit_window.y + edit_window.height + 8,
185, fitting_height(9))
@edit_window = edit_window
@index = 0
refresh
update_cursor
end
def character
if @index == 10
NUMPAD[@index]
elsif @index < 9
NUMPAD[@index]
else
""
end
end
def is_x?
@index == 11
end
def is_ok?
@index == 9
end
def item_rect(index)
contents.font.size = 32
rect = Rect.new
rect.x = index % 3 * 32 + index % 3 / 1 * 16
rect.y = index / 3 * line_height * 2
rect.width = 62
rect.height = 62
rect
end
def refresh
contents.clear
change_color(normal_color)
12.times {|i| draw_text(item_rect(i), NUMPAD[i], 1) }
end
def update_cursor
cursor_rect.set(item_rect(@index))
end
def cursor_movable?
active
end
def cursor_down(wrap)
if @index < 9 or wrap
@index = (index + 3) % 12
end
end
def cursor_up(wrap)
if @index > 2 or wrap
@index = (index - 3) % 12
end
end
def cursor_right(wrap)
if @index % 12 < 11
@index += 1
elsif wrap
@index -= 11
end
end
def cursor_left(wrap)
if @index % 12 > 0
@index -= 1
elsif wrap
@index += 11
end
end
def process_cursor_move
super
update_cursor
end
def process_handling
return unless open? && active
process_back if Input.repeat?(:B)
process_ok if Input.trigger?(:C)
end
def process_back
Sound.play_cancel if @edit_window.back
end
def process_ok
if !character.empty?
on_name_add
elsif is_x?
Sound.play_cancel
call_handler(:leave)
elsif is_ok?
RPG::SE.new(Keypad::OK_SE[0], Keypad::OK_SE[1], Keypad::OK_SE[2]).play
call_handler(:confirm)
end
end
def on_name_add
if @edit_window.add(character)
Sound.play_ok
else
Sound.play_buzzer
end
end
end
class Game_Interpreter
def keypad_input
SceneManager.call(Scene_Keypad)
wait(1)
end
end
Gọi bảng nhập số bằng Script call sau: keypad_input
Sử dụng [KEYPAD_VAR] để nhập số cho Var tương ứng và [MAX_NUM] để chọn số lượng chữ số, thông thường thì max là 8 số thôi, ko nên để nhìu quá!
Gọi script sau để đổi biến [KEYPAD_VAR] : Keypad::KEYPAD_VAR = x (với x là Var tương ứng)
Gọi script sau để đổi biến [MAX_NUM] : Keypad::MAX_NUM = x (với x là số tương ứng từ 1 => 8)
* Nhược điểm: Ko thể dùng Script Chuột
Đã Test!
Nhớ bấm REP+ rồi thực hành liền đi!! =]
Comments
Danh sách LATIN thiếu 1 ký tự rất quan trọng!
:laclac:
THAM GIA GROUP CỦA TTC TRÊN FACEBOOK
Lần sau em sẽ tắt mặt cườipác sơn coi lại dùm em đã hết lỗi đó chưa ạ?
Hô hô hô, sao chưa hết nhỉ?
À, cái từ [A] sẽ được đưa vào từ điển TTC
:tuki:
THAM GIA GROUP CỦA TTC TRÊN FACEBOOK
Ngon mà ko Rep+ là thế nào?
Gõ tiếng Việt bằng hệ thống này thế nào?