Mouse event moving system
]Version: 0.3
Introduction
This script allows events movments with the mouse
Features
Screenshots
Demo
none
Script
Instructions
write:
left button to select, right to move
FAQ
place it above main
Compatibility
I don't know
Credits and Thanks
Near Fantastica: Mouse module
SephirothSpawn : Pathfinding and Mouse module additions
Terms and Conditions
Free but Credits are needed
]Version: 0.3
Introduction
This script allows events movments with the mouse
Features
- Rect Selector
- Full Screen Cursor display
Screenshots

Demo
none
Script
Code:
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Déplacement/selection d'events a la souris
# berka 0.3 Rgss2
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# http://www.rpgmakervx-fr.com
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#===========================================
# Mouse
# par Berka d'apres SephirothSpawn
#===========================================
module Berka
module Curseur_Mod
Bmp_Curs='Graphics/System/Curseur.png'
Scroll_Actif=true
end
module Deplace_Event
Commentaire="bouge" # pour distinguer les events déplacables
Couleur_Cadre_Selection=Color.new(0,255,50,255)
Couleur_Fond_Selection=Color.new(0,255,50,75)
Icone='Graphics/system/icone.ico'
end
end
include Berka::Curseur_Mod
include Berka::Deplace_Event
module Mouse
GetAsyncKeyState=Win32API.new("user32","GetAsyncKeyState",'i','i')
GetKeyState=Win32API.new("user32","GetKeyState",'i','i')
SetCursorPos=Win32API.new('user32','SetCursorPos','nn','n')
GetCursorPo=Win32API.new('user32','GetCursorPos','p','i')
ScreenToClient=Win32API.new('user32','ScreenToClient','lp','i')
GetPrivateProfileStringA=Win32API.new('kernel32','GetPrivateProfileStringA','pppplp','l')
FindWindowA=Win32API.new('user32','FindWindowA','pp','l')
GetClientRect=Win32API.new('user32','GetClientRect','lp','i')
GetWindowRect=Win32API.new('user32','GetWindowRect','lp','i')
game_name="\0"*256
GetPrivateProfileStringA.call('Game','Title','',game_name,255,".\\Game.ini")
game_name.delete!("\0")
@handle=FindWindowA.call('RGSS Player',game_name)
module_function
def click?(button)
return true if @keys.include?(button)
return false
end
def press?(button)
return true if @press.include?(button)
return false
end
def set_pos(x_pos=0,y_pos=0)
width,height=client_size
if (x_pos.between?(0,width)&&y_pos.between?(0,height))
SetCursorPos.call(client_pos[0]+x_pos,client_pos[1]+y_pos)
end
end
def update
@pos=Mouse.pos
@keys,@press=[],[]
@keys.push(1)if GetAsyncKeyState.call(1)&0x01==1
@keys.push(2)if GetAsyncKeyState.call(2)&0x01==1
@keys.push(3)if GetAsyncKeyState.call(4)&0x01==1
@press.push(1)if pressed?(1)
@press.push(2)if pressed?(2)
@press.push(3)if pressed?(4)
end
def pressed?(key)
return true unless GetKeyState.call(key).between?(0,1)
return false
end
def global_pos
pos=[0,0].pack('ll')
GetCursorPo.call(pos)!=0 ? (return pos.unpack('ll')):(return nil)
end
def pos
x,y=screen_to_client(*global_pos)
width,height=client_size
begin
x=0 if x<=0;y=0 if y<=0
x=width if x>=width;y=height if y>=height
return x,y
end
end
def screen_to_client(x,y)
return nil unless x&&y
pos=[x,y].pack('ll')
ScreenToClient.call(@handle,pos)!=0?(return pos.unpack('ll')):(return nil)
end
def client_size
rect=[0,0,0,0].pack('l4')
GetClientRect.call(@handle,rect)
right,bottom=rect.unpack('l4')[2..3]
return right,bottom
end
def client_pos
rect=[0,0,0,0].pack('l4')
GetWindowRect.call(@handle,rect)
left,upper=rect.unpack('l4')[0..1]
return left+4,upper+30
end
def grid
return nil if @pos.nil?
return [(@pos[0]+$game_map.display_x/8)/32,(@pos[1]+$game_map.display_y/8)/32]
end
end
#===========================================
# Sprite_Curseur
# par Berka
#===========================================
class Sprite_Curseur<Sprite_Base
def initialize
super
Win32API.new('user32','ShowCursor','i','i').call(0)
self.z=5000
creer_curseur(Bmp_Curs)
update
end
def creer_curseur(curseur="")
(self.bitmap=Bitmap.new(curseur);return)rescue nil
self.bitmap=Bitmap.new(24,24)
bitmap=Cache.system("Iconset")
rect=Rect.new(2%16*24,2/16*24,24,24)
self.bitmap.blt(0,0,bitmap,rect)
end
def update;super;self.x,self.y=Mouse.pos;end
def dispose;super;end
end
Curseur=Sprite_Curseur.new
#===========================================
# Pathfinding
# par SephirothSpawn
#===========================================
include Input
class Game_Character
alias nf_pf_game_character_initialize initialize
alias nf_pf_game_character_update update
attr_accessor :map
attr_accessor :runpath
def initialize
nf_pf_game_character_initialize
@map,@runpath=nil,false
end
def update
run_path if @runpath
nf_pf_game_character_update
end
def run_path
return if moving?
step=@map[@x,@y]
(@map,@runpath=nil,false;return)if step==1
case rand(2)
when 0
move_right if @map[@x+1,@y]==step-1&&step!=0
move_down if @map[@x,@y+1]==step-1&&step!=0
move_left if @map[@x-1,@y]==step-1&&step!=0
move_up if @map[@x,@y-1]==step-1&&step!=0
when 1
move_up if @map[@x,@y-1]==step-1&&step!=0
move_left if @map[@x-1,@y]==step-1&&step!=0
move_down if @map[@x,@y+1]==step-1&&step!=0
move_right if @map[@x+1,@y]==step-1&&step!=0
end
end
def find_path(x,y)
sx,sy=@x,@y
result=setup_map(sx,sy,x,y)
@runpath,@map=result[0],result[1]
@map[sx,sy]=result[2] if !result[2].nil?
end
def clear_path;@map,@runpath=nil,false;end
def setup_map(sx,sy,ex,ey)
map=Table.new($game_map.width,$game_map.height)
map[ex,ey]=1
old_positions,new_positions=[],[]
old_positions.push([ex,ey])
depth=10
depth.upto(100){|step|
loop do
break if old_positions[0].nil?
x,y=old_positions.shift
return [true,map,step] if x==sx&&y+1==sy
if $game_map.passable?(x,y)&&map[x,y+1]==0
map[x,y+1]=step
new_positions.push([x,y+1])
end
return [true,map,step] if x-1==sx&&y==sy
if $game_map.passable?(x,y)&&map[x-1,y]==0
map[x-1,y]=step
new_positions.push([x-1,y])
end
return [true,map,step] if x+1==sx&&y==sy
if $game_map.passable?(x,y)&&map[x+1,y]==0
map[x+1,y]=step
new_positions.push([x+1,y])
end
return [true,map,step] if x==sx&&y-1==sy
if $game_map.passable?(x,y)&&map[x,y-1]==0
map[x,y-1]=step
new_positions.push([x,y-1])
end
end
old_positions=new_positions
new_positions=[]}
return [false,nil,nil]
end
end
class Game_Map
alias pf_game_map_setup setup
def setup(map_id)
pf_game_map_setup(map_id)
$game_player.clear_path
for event in events.values
event.clear_path
end
end
end
#===========================================
# Rect Select
# par Berka
#===========================================
class Rect_Select<Sprite
def initialize
super
self.x,self.y=Mouse.pos
self.bitmap=Bitmap.new(544,416)
self.visible=false
end
def update(ox=0,oy=0)
self.visible=true
self.bitmap.clear
(Mouse.pos[0]-ox>0)?(self.x=ox;@cib_x=Mouse.pos[0]-self.x):(self.x=Mouse.pos[0];@cib_x=ox-Mouse.pos[0])
(Mouse.pos[1]-oy>0)?(self.y=oy;@cib_y=Mouse.pos[1]-self.y):(self.y=Mouse.pos[1];@cib_y=oy-Mouse.pos[1])
self.bitmap.fill_rect(0,0,@cib_x,@cib_y,Couleur_Cadre_Selection)
self.bitmap.fill_rect(1,1,@cib_x-2,@cib_y-2,Couleur_Fond_Selection)
end
def chk_dessous?(x,y)
x-=$game_map.display_x/8
y-=$game_map.display_y/8
return true if x.between?(self.x,@cib_x)&&y.between?(self.y,@cib_y)
return false
end
end
#===========================================
# Scene_Map: Select
# par Berka
#===========================================
class Scene_Map<Scene_Base
alias :select_update :update
alias :select_start :start
alias :select_terminate :terminate
def start
select_start
@rect=Rect_Select.new
@x,@y,@events=Mouse.pos[0],Mouse.pos[1],[]
@base=[]
end
def update
Mouse.update
select_update
@rect.visible=false
if !Mouse.press?(1);@x,@y=Mouse.pos[0],Mouse.pos[1]
else;@rect.visible=true;@rect.update(@x,@y)
for event in $game_map.events.values
if event.list[0].parameters==Commentaire.to_a
(@events << event) if @rect.chk_dessous?(event.x*32,event.y*32)
end
end
end
if Mouse.click?(1)
for event in $game_map.events.values
if event.list[0].parameters==Commentaire.to_a
@events << event if Mouse.grid==[event.x,event.y]
end
end
elsif Mouse.click?(2)
if !@events.empty?
@events.each{|event|event.find_path(Mouse.grid[0],Mouse.grid[1])
@events.delete(event) if event.runpath}
@events.clear
else;$game_player.find_path(Mouse.grid[0],Mouse.grid[1])
end
elsif Mouse.click?(3)
@events.clear
end
end
def terminate
select_terminate
@rect.dispose
end
end
module Graphics
class<<self
alias :graphics_update :update unless Graphics.methods.include?('graphics_update')
def update
graphics_update
Curseur.update
end
end
end
Code:
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Déplacement/selection d'events a la souris
# berka 0.2 Rgss1
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# http://www.rpgmakervx-fr.com
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#===========================================
# Mouse
# par Berka d'apres SephirothSpawn
#===========================================
module Berka
module Curseur_Mod
Bmp_Curs='Graphics/System/Curseur.png'
Scroll_Actif=true
end
module Deplace_Event
Commentaire="bouge" # pour distinguer les events déplacables
Couleur_Cadre_Selection=Color.new(0,255,50,255)
Couleur_Fond_Selection=Color.new(0,255,50,75)
end
end
module Mouse
GetAsyncKeyState=Win32API.new("user32","GetAsyncKeyState",'i','i')
GetKeyState=Win32API.new("user32","GetKeyState",'i','i')
SetCursorPos=Win32API.new('user32','SetCursorPos','nn','n')
GetCursorPo=Win32API.new('user32','GetCursorPos','p','i')
ScreenToClient=Win32API.new('user32','ScreenToClient','lp','i')
GetPrivateProfileStringA=Win32API.new('kernel32','GetPrivateProfileStringA','pppplp','l')
FindWindowA=Win32API.new('user32','FindWindowA','pp','l')
GetClientRect=Win32API.new('user32','GetClientRect','lp','i')
GetWindowRect=Win32API.new('user32','GetWindowRect','lp','i')
@mouse_menu=0
game_name="\0"*256
GetPrivateProfileStringA.call('Game','Title','',game_name,255,".\\Game.ini")
game_name.delete!("\0")
@handle=FindWindowA.call('RGSS Player',game_name)
module_function
def click?(button)
return true if @keys.include?(button)
return false
end
def press?(button)
return true if @press.include?(button)
return false
end
def set_pos(x_pos=0,y_pos=0)
width,height=client_size
if (x_pos.between?(0,width)&&y_pos.between?(0,height))
SetCursorPos.call(client_pos[0]+x_pos,client_pos[1]+y_pos)
end
end
def update
@pos=Mouse.pos
@keys,@press=[],[]
@keys.push(1)if GetAsyncKeyState.call(1)&0x01==1
@keys.push(2)if GetAsyncKeyState.call(2)&0x01==1
@keys.push(3)if GetAsyncKeyState.call(4)&0x01==1
@press.push(1)if pressed?(1)
@press.push(2)if pressed?(2)
@press.push(3)if pressed?(4)
end
def pressed?(key)
return true unless GetKeyState.call(key).between?(0,1)
return false
end
def global_pos
pos=[0,0].pack('ll')
GetCursorPo.call(pos)!=0 ? (return pos.unpack('ll')):(return nil)
end
def pos
x,y=screen_to_client(*global_pos)
width,height=client_size
begin
x=0 if x<=0;y=0 if y<=0
x=width if x>=width;y=height if y>=height
return x,y
end
end
def screen_to_client(x,y)
return nil unless x&&y
pos=[x,y].pack('ll')
ScreenToClient.call(@handle,pos)!=0?(return pos.unpack('ll')):(return nil)
end
def client_size
rect=[0,0,0,0].pack('l4')
GetClientRect.call(@handle,rect)
right,bottom=rect.unpack('l4')[2..3]
return right,bottom
end
def client_pos
rect=[0,0,0,0].pack('l4')
GetWindowRect.call(@handle,rect)
left,upper=rect.unpack('l4')[0..1]
return left+4,upper+30
end
def grid
return nil if @pos.nil?
return [(@pos[0]+$game_map.display_x/8)/32,(@pos[1]+$game_map.display_y/8)/32]
end
end
#===========================================
# Sprite_Curseur
# par Berka
#===========================================
class Sprite_Curseur < RPG::Sprite
def initialize
super
Win32API.new('user32','ShowCursor','i','i').call(0)
self.z=5000
creer_curseur(Berka::Curseur_Mod::Bmp_Curs)
update
end
def creer_curseur(curseur="")
(self.bitmap=Bitmap.new(curseur);return)rescue nil
self.bitmap=Bitmap.new(24,24)
bitmap=RPG::Cache.icon("001-Weapon01")
rect=Rect.new(0,0,24,24)
self.bitmap.blt(0,0,bitmap,rect)
end
def update;super;self.x,self.y=Mouse.pos;end
def dispose;super;end
end
Curseur=Sprite_Curseur.new
#===========================================
# Pathfinding
# par SephirothSpawn
#===========================================
class Game_Character
alias nf_pf_game_character_initialize initialize
alias nf_pf_game_character_update update
attr_accessor :map
attr_accessor :runpath
def initialize
nf_pf_game_character_initialize
@map,@runpath=nil,false
end
def update
run_path if @runpath
nf_pf_game_character_update
end
def run_path
return if moving?
step=@map[@x,@y]
(@map,@runpath=nil,false;return)if step==1
case rand(2)
when 0
move_right if @map[@x+1,@y]==step-1&&step!=0
move_down if @map[@x,@y+1]==step-1&&step!=0
move_left if @map[@x-1,@y]==step-1&&step!=0
move_up if @map[@x,@y-1]==step-1&&step!=0
when 1
move_up if @map[@x,@y-1]==step-1&&step!=0
move_left if @map[@x-1,@y]==step-1&&step!=0
move_down if @map[@x,@y+1]==step-1&&step!=0
move_right if @map[@x+1,@y]==step-1&&step!=0
end
end
def find_path(x,y)
sx,sy=@x,@y
result=setup_map(sx,sy,x,y)
@runpath,@map=result[0],result[1]
@map[sx,sy]=result[2] if !result[2].nil?
end
def clear_path;@map,@runpath=nil,false;end
def setup_map(sx,sy,ex,ey)
map=Table.new($game_map.width,$game_map.height)
map[ex,ey]=1
old_positions,new_positions=[],[]
old_positions.push([ex,ey])
depth=2
depth.upto(100){|step|
loop do
break if old_positions[0].nil?
x,y=old_positions.shift
return [true,map,step] if x==sx&&y+1==sy
if $game_map.passable?(x,y,2)&&map[x,y+1]==0
map[x,y+1]=step
new_positions.push([x,y+1])
end
return [true,map,step] if x-1==sx&&y==sy
if $game_map.passable?(x,y,4)&&map[x-1,y]==0
map[x-1,y]=step
new_positions.push([x-1,y])
end
return [true,map,step] if x+1==sx&&y==sy
if $game_map.passable?(x,y,6)&&map[x+1,y]==0
map[x+1,y]=step
new_positions.push([x+1,y])
end
return [true,map,step] if x==sx&&y-1==sy
if $game_map.passable?(x,y,8)&&map[x,y-1]==0
map[x,y-1]=step
new_positions.push([x,y-1])
end
end
old_positions=new_positions
new_positions=[]}
return [false,nil,nil]
end
end
class Game_Map
alias pf_game_map_setup setup
def setup(map_id)
pf_game_map_setup(map_id)
$game_player.clear_path
for event in events.values
event.clear_path
end
end
end
#===========================================
# Rect Select
# par Berka
#===========================================
class Rect_Select<Sprite
def initialize
super
self.x,self.y=Mouse.pos
self.z=5000
self.bitmap=Bitmap.new(640,480)
self.visible=false
end
def update(ox=0,oy=0)
self.visible=true
self.bitmap.clear
(Mouse.pos[0]-ox>0)?(self.x=ox;cib_x=Mouse.pos[0]-self.x):(self.x=Mouse.pos[0];cib_x=ox-Mouse.pos[0])
(Mouse.pos[1]-oy>0)?(self.y=oy;cib_y=Mouse.pos[1]-self.y):(self.y=Mouse.pos[1];cib_y=oy-Mouse.pos[1])
self.bitmap.fill_rect(0,0,cib_x,cib_y,Berka::Deplace_Event::Couleur_Cadre_Selection)
self.bitmap.fill_rect(1,1,cib_x-2,cib_y-2,Berka::Deplace_Event::Couleur_Fond_Selection)
end
def chk_dessous?(x,y)
x-=$game_map.display_x/8
y-=$game_map.display_y/8
return true if x.between?(self.x,Mouse.pos[0]-self.x)&&y.between?(self.y,Mouse.pos[1]-self.y)
return false
end
end
#===========================================
# Scene_Map: Select
# par Berka
#===========================================
class Scene_Map
alias :select_main :main
alias :select_update :update
def main
@rect=Rect_Select.new
@x,@y,@events=Mouse.pos[0],Mouse.pos[1],[]
select_main
@spriteset = Spriteset_Map.new
@message_window = Window_Message.new
Graphics.transition
loop do
Graphics.update
Input.update
update
break if $scene != self
end
Graphics.freeze
@spriteset.dispose
@message_window.dispose
@rect.dispose
if $scene.is_a?(Scene_Title)
Graphics.transition
Graphics.freeze
end
end
def update
Mouse.update
select_update
@rect.visible=false
if !Mouse.press?(1);@x,@y=Mouse.pos[0],Mouse.pos[1]
else;@rect.visible=true;@rect.update(@x,@y)
for event in $game_map.events.values
if event.list[0].parameters==Berka::Deplace_Event::Commentaire.to_a
(@events << event) if @rect.chk_dessous?(event.x*32,event.y*32)
end
end
end
if Mouse.click?(1)
for event in $game_map.events.values
if event.list[0].parameters==Berka::Deplace_Event::Commentaire.to_a
@events << event if Mouse.grid==[event.x,event.y]
end
end
elsif Mouse.click?(2)
if !@events.empty?
@events.each{|event|event.find_path(Mouse.grid[0],Mouse.grid[1])
@events.delete(event) if event.runpath}
@events=[]
else;$game_player.find_path(Mouse.grid[0],Mouse.grid[1])
end
elsif Mouse.click?(3)
@events=[]
end
end
end
module Graphics
class<<self
alias :graphics_update :update unless Graphics.methods.include?('graphics_update')
def update
graphics_update
Curseur.update
end
end
end
write:
in each event's commentbox to allow it to movebouge
left button to select, right to move
FAQ
place it above main
Compatibility
I don't know
Credits and Thanks
Near Fantastica: Mouse module
SephirothSpawn : Pathfinding and Mouse module additions
Terms and Conditions
Free but Credits are needed