마우스로 이동을 하는 스크립트입니다.
3개로 나누어져 있으니 각각 나누어 메인 위에다 찔러 넣어 주시면 됩니다.
첫번째꺼는 전체키입니다.
#==============================================================================
# ** Keyboard Input Module
#==============================================================================
# Near Fantastica
# Version 5
# 29.11.05
#==============================================================================
# The Keyboard Input Module is designed to function as the default Input module
# dose. It is better then other methods keyboard input because as a key is
# tested it is not removed form the list. so you can test the same key multiple
# times the same loop.
#==============================================================================
module Keyboard
#--------------------------------------------------------------------------
@keys = []
@pressed = []
Mouse_Left = 1
Mouse_Right = 2
Back= 8
Tab = 9
Enter = 13
Shift = 16
Ctrl = 17
Alt = 18
Esc = 27
Space = 32
Numberkeys = {}
Numberkeys[0] = 48
Numberkeys[1] = 49
Numberkeys[2] = 50
Numberkeys[3] = 51
Numberkeys[4] = 52
Numberkeys[5] = 53
Numberkeys[6] = 54
Numberkeys[7] = 55
Numberkeys[8] = 56
Numberkeys[9] = 57
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
State = Win32API.new("user32","GetKeyState",['i'],'i')
Key = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
#--------------------------------------------------------------------------
def Keyboard.getstate(key)
return true unless State.call(key).between?(0, 1)
return false
end
#--------------------------------------------------------------------------
def Keyboard.testkey(key)
Key.call(key) & 0x01 == 1
end
#--------------------------------------------------------------------------
def Keyboard.update
@keys = []
@keys.push(Keyboard::Mouse_Left) if Keyboard.testkey(Keyboard::Mouse_Left)
@keys.push(Keyboard::Mouse_Right) if Keyboard.testkey(Keyboard::Mouse_Right)
@keys.push(Keyboard::Back) if Keyboard.testkey(Keyboard::Back)
@keys.push(Keyboard::Tab) if Keyboard.testkey(Keyboard::Tab)
@keys.push(Keyboard::Enter) if Keyboard.testkey(Keyboard::Enter)
@keys.push(Keyboard::Shift) if Keyboard.testkey(Keyboard::Shift)
@keys.push(Keyboard::Ctrl) if Keyboard.testkey(Keyboard::Ctrl)
@keys.push(Keyboard::Alt) if Keyboard.testkey(Keyboard::Alt)
@keys.push(Keyboard::Esc) if Keyboard.testkey(Keyboard::Esc)
@keys.push(Keyboard::Space) if Keyboard.testkey(Keyboard::Space)
for key in Keyboard::Numberkeys.values
@keys.push(key) if Keyboard.testkey(key)
end
for key in Keyboard::Numberpad.values
@keys.push(key) if Keyboard.testkey(key)
end
for key in Keyboard::Letters.values
@keys.push(key) if Keyboard.testkey(key)
end
for key in Keyboard::Fkeys.values
@keys.push(key) if Keyboard.testkey(key)
end
@keys.push(Keyboard::Collon) if Keyboard.testkey(Keyboard::Collon)
@keys.push(Keyboard::Equal) if Keyboard.testkey(Keyboard::Equal)
@keys.push(Keyboard::Comma) if Keyboard.testkey(Keyboard::Comma)
@keys.push(Keyboard::Underscore) if Keyboard.testkey(Keyboard::Underscore)
@keys.push(Keyboard::Dot) if Keyboard.testkey(Keyboard::Dot)
@keys.push(Keyboard::Backslash) if Keyboard.testkey(Keyboard::Backslash)
@keys.push(Keyboard::Lb) if Keyboard.testkey(Keyboard::Lb)
@keys.push(Keyboard::Rb) if Keyboard.testkey(Keyboard::Rb)
@keys.push(Keyboard::Quote) if Keyboard.testkey(Keyboard::Quote)
@pressed = []
@pressed.push(Keyboard::Mouse_Left) if Keyboard.getstate(Keyboard::Mouse_Left)
@pressed.push(Keyboard::Mouse_Right) if Keyboard.getstate(Keyboard::Mouse_Right)
@pressed.push(Keyboard::Back) if Keyboard.getstate(Keyboard::Back)
@pressed.push(Keyboard::Tab) if Keyboard.getstate(Keyboard::Tab)
@pressed.push(Keyboard::Enter) if Keyboard.getstate(Keyboard::Enter)
@pressed.push(Keyboard::Shift) if Keyboard.getstate(Keyboard::Shift)
@pressed.push(Keyboard::Ctrl) if Keyboard.getstate(Keyboard::Ctrl)
@pressed.push(Keyboard::Alt) if Keyboard.getstate(Keyboard::Alt)
@pressed.push(Keyboard::Esc) if Keyboard.getstate(Keyboard::Esc)
@pressed.push(Keyboard::Space) if Keyboard.getstate(Keyboard::Space)
for key in Keyboard::Numberkeys.values
@pressed.push(key) if Keyboard.getstate(key)
end
for key in Keyboard::Numberpad.values
@pressed.push(key) if Keyboard.getstate(key)
end
for key in Keyboard::Letters.values
@pressed.push(key) if Keyboard.getstate(key)
end
for key in Keyboard::Fkeys.values
@pressed.push(key) if Keyboard.getstate(key)
end
@pressed.push(Keyboard::Collon) if Keyboard.getstate(Keyboard::Collon)
@pressed.push(Keyboard::Equal) if Keyboard.getstate(Keyboard::Equal)
@pressed.push(Keyboard::Comma) if Keyboard.getstate(Keyboard::Comma)
@pressed.push(Keyboard::Underscore) if Keyboard.getstate(Keyboard::Underscore)
@pressed.push(Keyboard::Dot) if Keyboard.getstate(Keyboard::Dot)
@pressed.push(Keyboard::Backslash) if Keyboard.getstate(Keyboard::Backslash)
@pressed.push(Keyboard::Lb) if Keyboard.getstate(Keyboard::Lb)
@pressed.push(Keyboard::Rb) if Keyboard.getstate(Keyboard::Rb)
@pressed.push(Keyboard::Quote) if Keyboard.getstate(Keyboard::Quote)
end
#--------------------------------------------------------------------------
def Keyboard.trigger?(key)
return true if @keys.include?(key)
return false
end
#--------------------------------------------------------------------------
def Keyboard.pressed?(key)
return true if @pressed.include?(key)
return false
end
end
두번째
#======================================
# ■ Mouse Input
#======================================
# By: Near Fantastica
# Date: 06.07.05
# Version: 1
#======================================
module Mouse
@position
GSM = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i')
Cursor_Pos= Win32API.new('user32', 'GetCursorPos', 'p', 'i')
Scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
Client_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
Readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
Findwindow = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
#--------------------------------------------------------------------------
def Mouse.grid
return nil if @pos == nil
x = @pos[0] / 16
y = @pos[1] / 16
x = x * 16
y = y * 16
return [x, y]
end
#--------------------------------------------------------------------------
def Mouse.position
return @pos == nil ? [0, 0] : @pos
end
#--------------------------------------------------------------------------
def Mouse.global_pos
pos = [0, 0].pack('ll')
if Cursor_Pos.call(pos) != 0
return pos.unpack('ll')
else
return nil
end
end
#--------------------------------------------------------------------------
def Mouse.pos
x, y = Mouse.screen_to_client(*Mouse.global_pos)
width, height = Mouse.client_size
begin
if (x >= 0 and y >= 0 and x < width and y < height)
return x, y
else
return nil
end
rescue
return nil
end
end
#--------------------------------------------------------------------------
def Mouse.update
@pos = Mouse.pos
end
#--------------------------------------------------------------------------
def Mouse.screen_to_client(x, y)
return nil unless x and y
pos = [x, y].pack('ll')
if Scr2cli.call(Mouse.hwnd, pos) != 0
return pos.unpack('ll')
else
return nil
end
end
#--------------------------------------------------------------------------
def Mouse.hwnd
game_name = " " * 256
Readini.call('Game','Title','',game_name,255,".\Game.ini")
game_name.delete!(" ")
return Findwindow.call('RGSS Player',game_name)
end
#--------------------------------------------------------------------------
def Mouse.client_size
rect = [0, 0, 0, 0].pack('l4')
Client_rect.call(Mouse.hwnd, rect)
right, bottom = rect.unpack('l4')[2..3]
return right, bottom
end
end
3번째
#==============================================================================
# ** Sprite_Cursor
#------------------------------------------------------------------------------
# This sprite displays the cursor. It's used in the Spriteset_Map class.
#==============================================================================
class Sprite_Cursor < Sprite
attr_accessor :x
attr_accessor :y
attr_accessor :icon
attr_accessor :lock
#--------------------------------------------------------------------------
# * Object Initialization
# viewport : viewport
# picture : picture (Game_Picture)
#--------------------------------------------------------------------------
def initialize(viewport)
super(viewport)
update
@icon = $game_system.cursor
@old_icon = $game_system.cursor
@lock = false
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
if self.bitmap != nil
self.bitmap.dispose
end
super
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def set_icon(new)
if not @lock
@icon = new
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# If picture file name is different from current one
if self.bitmap == nil
self.bitmap = RPG::Cache.picture($game_system.cursor)
end
if @icon != @old_icon
if @icon == nil
self.bitmap = RPG::Cache.picture($game_system.cursor)
@old_icon = nil
else
self.bitmap = RPG::Cache.picture(@icon)
@old_icon = @icon
end
end
# If file name is empty
# Set sprite to visible
self.visible = true
# Set transfer starting point
# Set sprite coordinates
pos = Mouse.pos
if pos == nil
if self.x == nil
self.x = 0
end
if self.y == nil
self.y = 0
end
else
self.x = 0
self.ox = pos[0] * -1 + (self.bitmap.width / 2)
self.y = 0
self.oy = pos[1] * -1 + (self.bitmap.height / 2)
end
end
end
#==============================================================================
# ** Scene_ActionMap
#------------------------------------------------------------------------------
# This class performs map screen processing and allows the use of the
# mouse to make activations of events.
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
alias :event_system_main :main
def main
@update_interface = -1
event_system_main
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias :event_system_update :update
def update
# Update the Keyboard Module
Keyboard.update
# Run old map update
event_system_update
#Update the mouse
mouse_interface_update
# Left Click Actions
if Keyboard.pressed?(Keyboard::Mouse_Left) and @update_interface <= 0
mouse_left_click
elsif @update_interface > 0
@update_interface -= 1
end
end
#--------------------------------------------------------------------------
# * Do actions that are related to the left click
#--------------------------------------------------------------------------
def mouse_left_click
# If Mouse POS not nil
pos = Mouse.pos
if pos != nil and not $game_temp.message_window_showing
x = pos[0]
y = pos[1]
# Set the X and Y to the correct X/Y coordinates
x2 = x / 32
y2 = y / 32
if $game_map.display_x != 0
x2 += ($game_map.display_x / 4) / 16
end
if $game_map.display_y != 0
y2 += ($game_map.display_y / 4) / 16
end
event_run = false
# Get events that count as active (most front one)
active_event = @spriteset.get_affected_event(@x_mouse, @y_mouse)
if active_event > 0
event = $game_map.events[active_event]
range = get_object_range($game_player, event)
run_it = part_of_event_system(event)
# Check to see if it's a run event or not
run_it = part_of_event_system(event)
# Run it if it is
if run_it != false and event.trigger == 0
range = get_object_range($game_player, event)
if run_it >= range
event.refresh
event.start
$game_map.need_refresh
@update_interface = 10
event_run = true
end
end #End the run check
else
eventlist = $game_map.events.values
for event in eventlist
if x2 == event.x and y2 == event.y and event.character_name == ""
# Check to see if it's a run event or not
run_it = part_of_event_system(event)
# Run it if it is
if run_it != false and event.trigger == 0
range = get_object_range($game_player, event)
if run_it >= range
event.refresh
event.start
$game_map.need_refresh
@update_interface = 10
event_run = true
end
end #End the run check
end # End the X/Y check
end
end #End if/else
end # End POS != nil statement
if not event_run and not $game_player.moving? and not $game_temp.message_window_showing
$game_player.move_toward_point(x2, y2)
end
end
#--------------------------------------------------------------------------
# * Update Mouse position and cursor
#--------------------------------------------------------------------------
def mouse_interface_update
pos = Mouse.pos
if pos != nil and (pos[0] != @x_mouse or pos[1] != @y_mouse)
@x_mouse = pos[0]
@y_mouse = pos[1]
# Get the event that is under the mouse (most front one)
hover = @spriteset.get_affected_event(@x_mouse, @y_mouse)
if hover > 0
event = $game_map.events[hover]
# Run it if it is
if event.list != nil
for item in event.list
if item.code == 108 and item.parameters[0].include?("CURSOR=")
id = item.parameters[0].split('=')
@spriteset.cursor.set_icon(id[1])
set_icon = true
end
end
end
else
x = pos[0] / 32
y = pos[1] / 32
if $game_map.display_x != 0
x += ($game_map.display_x / 4) / 16
end
if $game_map.display_y != 0
y += ($game_map.display_y / 4) / 16
end
set_icon = false
for event in $game_map.events.values
if event.x == x and event.y == y and event.character_name == ""
if event.list != nil
for item in event.list
if item.code == 108 and item.parameters[0].include?("CURSOR=")
id = item.parameters[0].split('=')
@spriteset.cursor.set_icon(id[1])
set_icon = true
end
end
end
end
end
if not set_icon and @spriteset.cursor.icon != nil
@spriteset.cursor.set_icon(nil)
end
end
end
end
#--------------------------------------------------------------------------
# * Get Range from Point1 to Point2
#--------------------------------------------------------------------------
def get_object_range(point1, point2)
range_x = (point1.x.abs) - (point2.x.abs)
range_y = (point1.y.abs) - (point2.y.abs)
range_x = range_x.abs
range_y = range_y.abs
range_x = range_x * range_x
range_y = range_y * range_y
range = Math.sqrt(range_x + range_y)
range = range.round
return range
end
#--------------------------------------------------------------------------
# * Part of Combat System
#--------------------------------------------------------------------------
def part_of_event_system(event)
if event.is_a?(Game_Event)
if event.list != nil
for item in event.list
if item.code == 108 and item.parameters[0].include?("RUN=")
id = item.parameters[0].split('=')
return (id[1].to_i)
end
end
end
end
return false
end
end
#End Scene_Map
#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
# This class handles the player. Its functions include event starting
# determinants and map scrolling. Refer to "$game_player" for the one
# instance of this class.
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# * Invariables
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# * Move toward Player
#--------------------------------------------------------------------------
def move_toward_point(x, y)
# Get difference in player coordinates
sx = @x - x
sy = @y - y
# If coordinates are equal
if sx == 0 and sy == 0
return
end
# Get absolute value of difference
abs_sx = sx.abs
abs_sy = sy.abs
# If horizontal and vertical distances are equal
if abs_sx == abs_sy
# Increase one of them randomly by 1
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# If horizontal distance is longer
if abs_sx > abs_sy
# Move towards point, prioritize left and right directions
sx > 0 ? move_left : move_right
if not moving? and sy != 0
sy > 0 ? move_up : move_down
end
# If vertical distance is longer
else
# Move towards point, prioritize up and down directions
sy > 0 ? move_up : move_down
if not moving? and sx != 0
sx > 0 ? move_left : move_right
end
end
end
end #End Game_Player
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
# This class brings together map screen sprites, tilemaps, etc.
# It's used within the Scene_Map class.
#==============================================================================
class Spriteset_Map
attr_accessor :cursor
attr_reader :character_sprites
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias :event_system_normal_init :initialize
def initialize
event_system_normal_init
if $scene.is_a?(Scene_Map)
@cursor = Sprite_Cursor.new(@viewport3)
end
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
alias :event_system_normal_dispose :dispose
def dispose
if @cursor != nil
@cursor.dispose
end
event_system_normal_dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias :event_system_normal_update :update
def update
event_system_normal_update
if @cursor != nil
@cursor.update
end
end
#--------------------------------------------------------------------------
# * Get Event under a Click Point
#--------------------------------------------------------------------------
def get_affected_event(true_x, true_y)
data = []
for sprite in @character_sprites
x = true_x - sprite.x
y = true_y - sprite.y
if sprite.tile_id == 0
if x.abs < (sprite.cw / 2) and y.abs < sprite.ch and y < 0
bx = (sprite.cw / 2) + x
by = sprite.ch + y
sx = sprite.character.pattern * sprite.cw
sy = (sprite.character.direction - 2) / 2 * sprite.ch
if sprite.bitmap.get_pixel((bx+sx),(by+sy)).alpha > 0.0
data.push(sprite.character)
end
end
else
if x.abs < 16 and y.abs < 32 and y < 0
data.push(sprite.character)
end
end
end
if data.size > 1
event = data[0]
for i in 0...data.size
if data[i].y > event.y
event = data[i]
end
end
return event.id
elsif data.size > 0
return data[0].id
else
return -1
end
end
# End the Spriteset_Map
end
#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
# This sprite is used to display the character.It observes the Game_Character
# class and automatically changes sprite conditions.
#==============================================================================
class Sprite_Character < RPG::Sprite
attr_reader :cw
attr_reader :ch
attr_reader :tile_id
end
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# This class handles data surrounding the system. Backround music, etc.
# is managed here as well. Refer to "$game_system" for the instance of
# this class.
#==============================================================================
class Game_System
attr_accessor :cursor
attr_accessor :move_toward_mouse
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias :event_system_normal_init :initialize
def initialize
event_system_normal_init
@move_toward_mouse = true
@cursor = ""
end
end
그러고 난 후,
자신의 샤양에 맞게
RGSS100J.dll 이나 RGSS102E.dll 또는 RGSS102J.dll을 넣으셔서
게임에 지장 없도록 하십시오.
<사용법>
게임 NPC에 주석으로 RUN=?를 합니다. ?는 캐릭터를 클릭하는 사정거리입니다.
EX)RUN=2로하면 2칸 떨어진곳에서 NPC를 클릭해도 됩니다. 그러면 대화도 나오고 좋습니다.
스크립트 출처 : rmxp