1
good guys I came to ask help from some of you with a system that has in hutommo_ace.
I walked function the character system moves by the coord in the mouse of the game, get by in my game "Scripts".
only that however not being able to make it work, the configurations are very complex.
Download: http://www.mediafire.com/file/6pqh6tpbm6tq509/hutommo_ace.rar
#==============================================================================
# ◆ Mouse_Position (Input)
#------------------------------------------------------------------------------
# マウスの座標を取得するオブジェクト (Input 内部で使用します。)
#==============================================================================
class Mouse_Position
#--------------------------------------------------------------------------
# ◆ (!※ Sem proibição ※!)
#--------------------------------------------------------------------------
def self.inherited( subclass )
__cannot_inherited( subclass )
end
private_class_method(:inherited)
#--------------------------------------------------------------------------
# ● Variável de instância pública
#--------------------------------------------------------------------------
attr_reader :x # マウス X 座標
attr_reader :y # マウス Y 座標
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
def initialize
@x = -1
@y = -1
@pos = "\x00" * 8
begin
# マウスカーソルの座標を取得
@getmouse = Win32API.new('WFInput','getMouseCursorPos','p','i')
# マウスカーソルをセット
@setmouse = Win32API.new('WFInput','setMouseCursorPos',%w(l l),'i')
# マウスカーソル表示
@show_cursor = Win32API.new('user32', 'ShowCursor', 'l', 'l')
rescue Exception
# 取得失敗
raise( LoadError , "cannot read modules.",caller(0))
end
# 画面外のとき、表示。 画面内のとき、非表示
@showing = true
end
#--------------------------------------------------------------------------
# ● マウスカーソルを表示
#--------------------------------------------------------------------------
def mouse_show
@show_cursor.call(1)
@showing = true
nil
end
#--------------------------------------------------------------------------
# ● マウスカーソルを非表示
#--------------------------------------------------------------------------
def mouse_hide
@show_cursor.call(0)
@showing = false
nil
end
#--------------------------------------------------------------------------
# ● Obter a posição do cursor do mouse
#--------------------------------------------------------------------------
def get_mouse_pos
unless Input.mouse_enabled?
# Quando não estiver usando o mouse
mouse_show
@x = -1
@y = -1
return false
end
unless (@getmouse.call(@pos)).zero?
# Quando há um cursor na tela
@x , @y = @pos.unpack('ll')
mouse_hide
return true
else
# Se não estiver na tela ou inválido
mouse_show
@x = -1
@y = -1
return false
end
end
#--------------------------------------------------------------------------
# ● Definir a posição do cursor do mouse
#--------------------------------------------------------------------------
def set_mouse_pos( x , y )
return false unless Input.mouse_enabled?
get_mouse_pos unless (@setmouse.call( x , y )).zero?
end
end
#==============================================================================
# ◆ Input (再定義) ( Global module )
#------------------------------------------------------------------------------
# 入力の再定義(追加)です。
#==============================================================================
#--------------------------------------------------------------------------
# ● Variável de classe
#--------------------------------------------------------------------------
@@keyboard = "\x00" * 256 # Buffer de chave
@@old_keyboard = @@keyboard.dup # Buffer de chave (entrada anterior)
@@nouse_mouse = "\x00" * 4
@@nouse_mouse2 = "\x00" * 20
# Botão do mouse
@@mouse_input = "\x00" * 20
# Roda
@@wheel = "\x00" * 4
begin
# API para copiar o estado da chave virtual para o buffer especificado
@@keyboard_state = Win32API.new('user32', 'GetKeyboardState', 'p', 'i')
# Aquisição: Teclado GetKeyBoardState (Win32API) Mouse DirectInput8
@@input_state = Win32API.new('WFInput','getInput', %w(p p p),'l')
rescue Exception
# Não foi possível obter
raise( LoadError , "cannot read modules.",caller(0))
end
begin
@@getpad = Win32API.new("winmm","joyGetPosEx", %w(l p), "l")
rescue Exception
# Não foi possível obter
raise( LoadError , "cannot read modules.(winmm.dll)",caller(0))
end
#Estrutura do joypad
@@joyinfo1 = "\x00" * 52
@@joyinfo2 = "\x00" * 52
# O estado do joypad
@@joy1 = []
@@joy2 = []
@@joybtn1 = 0
@@joybtn2 = 0
@@joybtn1p = 0
@@joybtn2p = 0
@@keyrepeat = Hash.new
@@joy1repeat = Hash.new
@@joy2repeat = Hash.new
@@keyrepeat.default = 0
@@joy1repeat.default = 0
@@joy2repeat.default = 0
@@key_repeat_flag = Hash.new
@@joy1_repeat_flag = Hash.new
@@joy2_repeat_flag = Hash.new
# Coordenadas do mouse
@@mouse = Mouse_Position.new
@@mouse_use = false
@@mouse_enabled = false
# A partir deste ponto, definido como uma função de módulo
module_function
end
#--------------------------------------------------------------------------
# ● Julgamento de usabilidade de mouse
#--------------------------------------------------------------------------
def mouse_enabled?
@@mouse_use
end
#--------------------------------------------------------------------------
# ● Julgamento de usabilidade de mouse
#--------------------------------------------------------------------------
def mouse_use=(mouse_use)
@@mouse_use = mouse_use ? true : false
nil
end
#--------------------------------------------------------------------------
# ● Coordenada X do mouse
#--------------------------------------------------------------------------
def mouse_x
@@mouse.x
end
#--------------------------------------------------------------------------
# ● Coordenada Y do mouse
#--------------------------------------------------------------------------
def mouse_y
@@mouse.y
end
#--------------------------------------------------------------------------
# ● Mostrar cursor do mouse
#--------------------------------------------------------------------------
def mouse_show
@@mouse.mouse_show
end
#--------------------------------------------------------------------------
# ● Obter rotação de roda
#--------------------------------------------------------------------------
def wheel_moved?
( self.wheel_move ).zero? ? false : true
end
#--------------------------------------------------------------------------
# ● Obter velocidade de rotação da roda
#--------------------------------------------------------------------------
def wheel_move
(@@wheel.unpack("l")).at(0)
end
#--------------------------------------------------------------------------
# ● Se o botão do mouse foi pressionado
#--------------------------------------------------------------------------
def di_mouse_press?( button )
if rpgvxace?
@@mouse_input[button].unpack("C").at(0) >= 0x92
else
@@mouse_input[button] >= 0x92
end
end
#--------------------------------------------------------------------------
# ● Conjunto de coordenadas do mouse
#--------------------------------------------------------------------------
def set_mouse_pos( x , y )
@@mouse.set_mouse_pos( x , y )
end
#--------------------------------------------------------------------------
# ● Obter status do joypad
#--------------------------------------------------------------------------
def joy_update( player = 0 )
ret = 0
if player.zero?
@@joy1_repeat_flag.clear
@@joybtn1p = @@joybtn1
@@joyinfo1 = [ 52 , 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].pack("I*")
if (ret = @@getpad.call( 0 , @@joyinfo1 )).zero?
@@joy1 = @@joyinfo1.unpack("I*")
btn = joy_cross_value( joy_dir8( 0 , 0))
@@joybtn1 = @@joy1.at(8)
@@joybtn1 |= btn
true
else
false
end
else
@@joy2_repeat_flag.clear
@@joybtn2p = @@joybtn2
@@joyinfo2 = [ 52 , 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].pack("I*")
if (ret = @@getpad.call( 1 , @@joyinfo2 )).zero?
@@joy2 = @@joyinfo2.unpack("I*")
btn = joy_cross_value( joy_dir8( 1 , 0))
@@joybtn2 = @@joy2.at(8)
@@joybtn2 |= btn
true
else
false
end
end
end
#--------------------------------------------------------------------------
# ● Atualização de quadro (teclado / mouse)
# ※ Nota: Existem chaves duplicadas.
#--------------------------------------------------------------------------
def exupdate
@@old_keyboard.replace( @@keyboard ) # 置き換えを強制
@@key_repeat_flag.clear
unless @@mouse.get_mouse_pos
# Rato inválido
if (@@keyboard_state.call( @@keyboard ) ).zero?
@@keyboard.replace( @@old_keyboard )
else
@@keyboard[Mouse::Left , 4 ] = @@nouse_mouse
@@old_keyboard[Mouse::Left , 4 ] = @@nouse_mouse
end
if @@mouse_enabled
@@mouse_enabled = false
@@keyboard[Mouse::Left , 4 ] = @@nouse_mouse
@@old_keyboard[Mouse::Left , 4 ] = @@nouse_mouse
@@wheel[ 0, 4] = @@nouse_mouse
@@mouse_input[0 , 20] = @@nouse_mouse2
end
else
# Mouse é eficaz
unless (@@input_state.call( @@keyboard , @@wheel , @@mouse_input )).zero?
# Não foi possível obter
#
end
@@mouse_enabled = true unless @@mouse_enabled
end
joy_update( 0 )
joy_update( 1 ) if JOYPAD_2P
nil
end
#--------------------------------------------------------------------------
# ● Atualização de quadros
#--------------------------------------------------------------------------
def allupdate
update
end
#--------------------------------------------------------------------------
# ● Se a chave específica do mouse está sendo pressionada (Win32API)
#--------------------------------------------------------------------------
def mouse_press?
return true if vk_press?( Mouse::Left )
return true if vk_press?( Mouse::Right )
return true if vk_press?( Mouse::Middle )
return false
end
#--------------------------------------------------------------------------
# ● Se a tecla específica do joypad está sendo pressionada atualmente
#--------------------------------------------------------------------------
def joy_press?( key , player = 0 )
return false unless JOYPAD[key]
if player.zero?
return (JOYPAD[key] & @@joybtn1).zero? ? false : true
else
return (JOYPAD[key] & @@joybtn2).zero? ? false : true
end
end
#--------------------------------------------------------------------------
# ● Se uma tecla específica do joypad é pressionada novamente
#--------------------------------------------------------------------------
def joy_trigger?( key , player = 0 )
return false unless JOYPAD[key]
if player.zero?
if (JOYPAD[key] & @@joybtn1p).zero?
return (JOYPAD[key] & @@joybtn1).zero? ? false : true
else
return false
end
else
if (JOYPAD[key] & @@joybtn2p).zero?
return (JOYPAD[key] & @@joybtn2).zero? ? false : true
else
return false
end
end
end
#--------------------------------------------------------------------------
# ● Se a tecla específica do joypad está sendo pressionada ou não
#--------------------------------------------------------------------------
def joy_repeat?( key , player = 0 )
return false unless JOYPAD[key]
if player.zero?
if (JOYPAD[key] & @@joybtn1p).zero?
v = (JOYPAD[key] & @@joybtn1).zero? ? false : true
@@joy1repeat[key] = 0
else
v = (JOYPAD[key] & @@joybtn1).zero? ? false : true
if v
unless @@joy1_repeat_flag[key]
@@joy1repeat[key] += 1
@@joy1_repeat_flag[key] = true
end
else
@@joy1repeat[key] = 0
end
v = repeat_true?( @@joy1repeat[key] , v )
end
else
if (JOYPAD[key] & @@joybtn2p).zero?
v = (JOYPAD[key] & @@joybtn2).zero? ? false : true
@@joy2repeat[key] = 0
else
v = (JOYPAD[key] & @@joybtn2).zero? ? false : true
if v
unless @@joy2_repeat_flag[key]
@@joy2repeat[key] += 1
@@joy2_repeat_flag[key] = true
end
else
@@joy2repeat[key] = 0
end
v = repeat_true?( @@joy2repeat[key] , v )
end
end
v
end
#--------------------------------------------------------------------------
# ● Entrada de 4 vias do joypad
#--------------------------------------------------------------------------
def joy_dir4( player = 0 , axis = 0)
x, y = axis.zero? ? get_xy(player) :
(axis == 1 ? get_zr(player) : get_uv(player))
return 0 if x.abs == y.abs
if x.abs > y.abs
if x > 0
return 6
elsif x < 0
return 4
else
return 0 # x = 0 -> y = 0
end
elsif y > 0
return 2
elsif y < 0
return 8
else
return 0 # y = 0 -> x = 0
end
end
#--------------------------------------------------------------------------
# ● Entrada de direção do Joypad 8
#--------------------------------------------------------------------------
def joy_dir8( player = 0 , axis = 0)
x, y = axis.zero? ? get_xy(player) :
(axis == 1 ? get_zr(player) : get_uv(player))
unless x.zero?
arg = ( Math.atan( y.to_f / x.to_f ) * 8 ) / Math::PI
if arg < -3
return x > 0 ? 8 : 2
elsif arg < -1
return x > 0 ? 9 : 1
elsif arg < 1
return x > 0 ? 6 : 4
elsif arg < 3
return x > 0 ? 3 : 7
else
return x > 0 ? 2 : 8
end
else
if y > 0
return 2
elsif y < 0
return 8
else
return 0
end
end
end
#--------------------------------------------------------------------------
# ● POV O estado
#--------------------------------------------------------------------------
def getpov(player = 0)
player.zero? ? @@joy1.at(10) : @@joy2.at(10)
end
#--------------------------------------------------------------------------
# ● POV Entrada de direção do State Joypad 8
#--------------------------------------------------------------------------
def pov2joy8(player = 0)
pos = getpov(player)
if pos <= 2250
8
elsif pos <= 6750
9
elsif pos <= 11250
6
elsif pos <= 15750
3
elsif pos <= 20250
2
elsif pos <= 24750
1
elsif pos <= 29250
4
elsif pos <= 33750
7
elsif pos < 36000
8
else
0
end
end
#--------------------------------------------------------------------------
# ● Se uma tecla específica no teclado está sendo pressionada atualmente
#--------------------------------------------------------------------------
def vk_press?( key )
if rpgvxace?
@@keyboard[ key ].unpack("C").at(0) >= 0x92
else
@@keyboard[ key ] >= 0x92
end
end
#--------------------------------------------------------------------------
# ● Se uma tecla específica no teclado é pressionada recentemente
#--------------------------------------------------------------------------
def vk_trigger?( key )
if rpgvxace?
unless @@old_keyboard[ key ].unpack("C").at(0) >= 0x92
@@keyboard[ key ].unpack("C").at(0) >= 0x92
else
false
end
else
unless @@old_keyboard[ key ] >= 0x92
@@keyboard[ key ] >= 0x92
else
false
end
end
end
#--------------------------------------------------------------------------
# ● Se uma tecla específica no teclado está sendo pressionada ou não
#--------------------------------------------------------------------------
def vk_repeat?( key )
if rpgvxace?
unless @@old_keyboard[ key ].unpack("C").at(0) >= 0x92
v = @@keyboard[ key ].unpack("C").at(0) >= 0x92
@@keyrepeat[key] = 0
else
v = @@keyboard[ key ].unpack("C").at(0) >= 0x92
if v
unless @@key_repeat_flag[key]
@@keyrepeat[key] += 1
@@key_repeat_flag[key] = true
end
else
@@keyrepeat[key] = 0
end
v = repeat_true?( @@keyrepeat[key] , v )
end
else
unless @@old_keyboard[ key ] >= 0x92
v = @@keyboard[ key ] >= 0x92
@@keyrepeat[key] = 0
else
v = @@keyboard[ key ] >= 0x92
if v
unless @@key_repeat_flag[key]
@@keyrepeat[key] += 1
@@key_repeat_flag[key] = true
end
else
@@keyrepeat[key] = 0
end
v = repeat_true?( @@keyrepeat[key] , v )
end
end
v
end
#--------------------------------------------------------------------------
# ● Se há entrada de teclado
#--------------------------------------------------------------------------
def vk_input?
if rpgvxace?
input_num = -1
until (input_num = @@keyboard.index(VK_INPUT_MATCH),(input_num + 1)).nil?
return true if input_num != '0x19' and input_num.unpack("C").at(0) < 0xf0
end
false
else
input_num = -1
until (input_num = @@keyboard.index(VK_INPUT_MATCH),(input_num + 1)).nil?
return true if input_num != 0x19 and input_num < 0xf0
end
false
end
end
#--------------------------------------------------------------------------
# ● Se há entrada de teclado
#--------------------------------------------------------------------------
def vk_input_num
if rpgvxace?
input_num = -1
until (input_num = @@keyboard.index(VK_INPUT_MATCH),(input_num + 1)).nil?
return input_num if input_num != 0x19 and input_num.unpack("C").at(0) < 0xf0
end
0
else
input_num = -1
until (input_num = @@keyboard.index(VK_INPUT_MATCH),(input_num + 1)).nil?
return input_num if input_num != 0x19 and input_num < 0xf0
end
0
end
end
#--------------------------------------------------------------------------
# ● Entrada de teclado de saída
#--------------------------------------------------------------------------
def vk_input_list
result = []
val = -1
i = 0
until ( val = @@keyboard.index(VK_INPUT_MATCH,(val + 1))).nil?
val = rpgvxace? ? val.unpack("C").at(0) : val
if val >= 0xf0
break
elsif val == 0x19
next
elsif val >= 0x10 and val <= 0x12
# Shift Ctrl Alt caso (Input.VK_press?)
result[i] = val
else
unless @@old_keyboard[ val ] >= 0x92
# Qualquer outra entrada válida (Input.VK_trigger?)
result[i] = val
end
end
i += 1
end
result
end
#--------------------------------------------------------------------------
# ● Caps Lock O estado
#--------------------------------------------------------------------------
def caps_lock?
if rpgvxace?
@@keyboard[ VK_CAPS ].unpack("C").at(0) & 0x01 == 0x01
else
@@keyboard[ VK_CAPS ] & 0x01 == 0x01
end
end
#--------------------------------------------------------------------------
# ● Limpar informações de entrada do teclado
#--------------------------------------------------------------------------
def vk_clear
@@keyboard = "\x00" * 256
@@old_keyboard.replace( @@keyboard ) # Substituição de força
nil
end
#--------------------------------------------------------------------------
# ● Entrar determinação da chave
#--------------------------------------------------------------------------
def decision_trigger?
trigger?(DECISION_KEY)
end
#--------------------------------------------------------------------------
# ● Cancelar determinação da entrada principal
#--------------------------------------------------------------------------
def cancel_trigger?
trigger?(CANCEL_KEY)
end
#--------------------------------------------------------------------------
# ● Chave de decisão ou decisão Determinação de entrada de clique do mouse
#--------------------------------------------------------------------------
def decition_with_mouse?
trigger?(DECISION_KEY) or vk_trigger?(DECISION_MOUSE_CLICK)
end
#--------------------------------------------------------------------------
# ● Cancelar chave ou cancelar o julgamento da entrada do clique do mouse
#--------------------------------------------------------------------------
def cancel_with_mouse?
trigger?(CANCEL_KEY) or vk_trigger?(CANCEL_MOUSE_CLICK)
end
#--------------------------------------------------------------------------
# ◆ Obter coordenadas x, y
#--------------------------------------------------------------------------
def get_xy( player = 0 )
if player.zero?
x = @@joy1.at(2) - 32767
y = @@joy1.at(3) - 32767
else
x = @@joy2.at(2) - 32767
y = @@joy2.at(3) - 32767
end
x = 0 if x.abs < MINIMUM_LEVEL
y = 0 if y.abs < MINIMUM_LEVEL
return x, y
end
#--------------------------------------------------------------------------
# ◆ Obter coordenadas z, r
#--------------------------------------------------------------------------
def get_zr( player = 0 )
if player.zero?
z = @@joy1.at(4) - 32767
r = @@joy1.at(5) - 32767
else
z = @@joy2.at(4) - 32767
r = @@joy2.at(5) - 32767
end
z = 0 if z.abs < MINIMUM_LEVEL
r = 0 if r.abs < MINIMUM_LEVEL
return z, r
end
#--------------------------------------------------------------------------
# ◆ u,v座標を取得
#--------------------------------------------------------------------------
def get_uv( player = 0 )
if player.zero?
u = @@joy1.at(6) - 32767
v = @@joy1.at(7) - 32767
else
u = @@joy2.at(6) - 32767
v = @@joy2.at(7) - 32767
end
u = 0 if u.abs < MINIMUM_LEVEL
v = 0 if v.abs < MINIMUM_LEVEL
return u, v
end
#--------------------------------------------------------------------------
# ◆ x,y,z座標を取得
#--------------------------------------------------------------------------
def get_xyz( player = 0 )
if player.zero?
x = @@joy1.at(2) - 32767
y = @@joy1.at(3) - 32767
z = @@joy1.at(4) - 32767
else
x = @@joy2.at(2) - 32767
y = @@joy2.at(3) - 32767
z = @@joy2.at(4) - 32767
end
p z
x = 0 if x.abs < MINIMUM_LEVEL
y = 0 if y.abs < MINIMUM_LEVEL
z = 0 if z.abs < MINIMUM_LEVEL
return x, y, z
end
#--------------------------------------------------------------------------
# ◆ r,u,v座標を取得
#--------------------------------------------------------------------------
def get_ruv( player = 0 )
if player.zero?
r = @@joy1.at(5) - 32767
u = @@joy1.at(6) - 32767
v = @@joy1.at(7) - 32767
else
r = @@joy2.at(5) - 32767
u = @@joy2.at(6) - 32767
v = @@joy2.at(7) - 32767
end
r = 0 if r.abs < MINIMUM_LEVEL
u = 0 if u.abs < MINIMUM_LEVEL
v = 0 if v.abs < MINIMUM_LEVEL
return r, u, v
end
#--------------------------------------------------------------------------
# ◆ ジョイパッドの方向を変換
#--------------------------------------------------------------------------
def joy_cross_value( value )
case value
when 1
return (JOYPAD[DOWN] | JOYPAD[LEFT])
when 2
return JOYPAD[DOWN]
when 3
return (JOYPAD[DOWN] | JOYPAD[RIGHT])
when 4
return JOYPAD[LEFT]
when 6
return JOYPAD[RIGHT]
when 7
return (JOYPAD[UP] | JOYPAD[LEFT])
when 8
return JOYPAD[UP]
when 9
return (JOYPAD[UP] | JOYPAD[RIGHT])
else
return 0
end
only that my game exchanges data with server and for what it gave to understand is that the system it intrepreta as coord of mouse and tranforma in such a direction.
#--------------------------------------------------------------------------
# * Checks the status of the directional buttons, translates the data into
# a specialized 4-direction input format, and returns the number pad
# equivalent (2, 4, 6, 8).
#
# If no directional buttons are being pressed (or the equivalent), returns 0.
#--------------------------------------------------------------------------
def self.dir4
return 2 if self.press?(DOWN)
return 4 if self.press?(LEFT)
return 6 if self.press?(RIGHT)
return 8 if self.press?(UP)
return 2 if self.press?(KEYMAP[:LETTER_S])
return 4 if self.press?(KEYMAP[:LETTER_A])
return 6 if self.press?(KEYMAP[:LETTER_D])
return 8 if self.press?(KEYMAP[:LETTER_W])
return 0
end
so it would be but easy to use this system since the directions are already being sent to the server when the mouse is pressed in such coord. it converts the mouse coord into self.dir4.