Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Scrolling Map with the Mousewheel
berka
post Dec 15 2008, 12:26 PM
Post #1


Level 8
Group Icon

Group: Revolutionary
Posts: 111
Type: Scripter
RM Skill: Advanced




Scrolling map with mousewheel
Version: 0.1


Introduction

Allow the map scrolling with the mousewheel

Screenshots
none...

Demo
none

Script
[Show/Hide] mousewheel rmvx
CODE
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#          Scrolling de la map, avec la molette de la souris
#  berka                    0.1                    Rgss2
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#              http://www.rpgmakervx-fr.com
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# adaptation du script ruby de ËœaŠó         un grand merci !
#
# molette pour les ordonnées
# Ctrl+molette pour les abcisses
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
module Berka
  module Souris
    ID_Int=1  #id de l'interrupteur a activer pour autoriser le scrolling
    Vitesse=8 #vitesse du scrolling de la map
  end
end
include Berka::Souris
class Souris
  Get_Message=Win32API.new('User32','GetMessage','plll','l')
  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')
  Point=Struct.new(:x,:y)
  Message=Struct.new(:message,:wparam,:lparam,:pt)
  Param=Struct.new(:x,:y,:scroll)
  Scroll=0x0000020A
  def handle
    game_name="\0"*256
    GetPrivateProfileStringA.call('Game','Title','',game_name,255,".\\Game.ini")
    game_name.delete!("\0")
    return handle=FindWindowA.call('RGSS Player',game_name)
  end
  def unpack_dword(buffer,offset=0)
    ret=buffer[offset+0]&0x000000ff
    ret|=(buffer[offset+1]<<(8*1))&0x0000ff00
    ret|=(buffer[offset+2]<<(8*2))&0x00ff0000
    ret|=(buffer[offset+3]<<(8*3))&0xff000000
    return ret
  end
  def unpack_msg(buffer)
    msg=Message.new;msg.pt=Point.new
    msg.message=unpack_dword(buffer,4*1)
    msg.wparam=unpack_dword(buffer,4*2)
    msg.lparam=unpack_dword(buffer,4*3)
    msg.pt.x=unpack_dword(buffer,4*5)
    msg.pt.y=unpack_dword(buffer,4*6)
    return msg
  end
  def wmcallback(msg)
    return unless msg.message==Scroll
    param=Param.new
    param.x=word2signed_short(loword(msg.lparam))
    param.y=word2signed_short(hiword(msg.lparam))
    param.scroll=word2signed_short(hiword(msg.wparam))
    return [param.x,param.y,param.scroll]
  end
  def hiword(dword);return ((dword&0xffff0000)>>16)&0x0000ffff;end
  def loword(dword);return dword&0x0000ffff;end
  def word2signed_short(value)
    return value if (value&0x8000)==0
    return -1*((~value&0x7fff)+1)
  end
  def click?(button);@keys.include?(button)?(return true):(return false);end  
  def press?(button);@press.include?(button)?(return true):(return false);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 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,@keys,@press=pos,[],[]
    @keys<<1 if GetAsyncKeyState.call(1)&0x01==1
    @keys<<2 if GetAsyncKeyState.call(2)&0x01==1
    @keys<<3 if GetAsyncKeyState.call(4)&0x01==1
    @press<<1 if pressed?(1)
    @press<<2 if pressed?(2)
    @press<<3 if pressed?(4)
  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 dans_player?
    return true if global_pos[0].between?(client_pos[0],client_pos[0]+client_size[0])&&
    global_pos[1].between?(client_pos[1],client_pos[1]+client_size[1])
    return false
  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
  def scroll
    msg="\0"*32;Get_Message.call(msg,0,0,0);r=wmcallback(unpack_msg(msg))
    return r if !r.nil?
  end
end
$souris=Souris.new
module Input
  class<<self
    alias :update_souris :update unless Input.methods.include?("update_souris")
    def update
      update_souris
      $souris.update
    end
  end
end

class Scene_Map<Scene_Base
  alias :souris_update :update
  def update
    souris_update
    update_scroll if $souris.dans_player?&&$game_switches[ID_Int]
  end
  def update_scroll
    s=$souris.scroll;return if s.nil?
    s[2]<0 ? (Input.press?(Input::CTRL) ? d=6 : d=2) : (Input.press?(Input::CTRL) ? d=4 : d=8)
    $game_map.start_scroll(d,1,Vitesse)
  end
end

[Show/Hide] mousewheel rmxp
CODE
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#          Scrolling de la map, avec la molette de la souris
#  berka                    0.1                    Rgss1
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#              http://www.rpgmakervx-fr.com
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# adaptation du script ruby de ˜aŠó         un grand merci !
#
# molette pour les ordonnées
# Ctrl+molette pour les abcisses
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
module Berka
  module Souris
    ID_Int=1  #id de l'interrupteur a activer pour autoriser le scrolling
    Vitesse=8 #vitesse du scrolling de la map
  end
end

class Souris
  Get_Message=Win32API.new('User32','GetMessage','plll','l') # reception d'un message
  GetAsyncKeyState=Win32API.new("user32","GetAsyncKeyState",'i','i') # test d'une touche
  GetKeyState=Win32API.new("user32","GetKeyState",'i','i') # etat d'une touche
  SetCursorPos=Win32API.new('user32','SetCursorPos','nn','n') # positionnement du curseur
  GetCursorPo=Win32API.new('user32','GetCursorPos','p','i') # position du curseur
  ScreenToClient=Win32API.new('user32','ScreenToClient','lp','i') # coordonnées du handle
  GetPrivateProfileStringA=Win32API.new('kernel32','GetPrivateProfileStringA','pppplp','l') # lecture fichier
  FindWindowA=Win32API.new('user32','FindWindowA','pp','l') # recuperation handle d'une fenetre
  GetClientRect=Win32API.new('user32','GetClientRect','lp','i') # recuperations dimensions ecran
  GetWindowRect=Win32API.new('user32','GetWindowRect','lp','i') #recuperation dimensions fenetre (handle)
  Point=Struct.new(:x,:y) # création d'une structure de symboles: coord molette
  Message=Struct.new(:message,:wparam,:lparam,:pt) # struct de symboles: message renvoyé par la molette
  Param=Struct.new(:x,:y,:scroll) # parametres de la molette
  Scroll=0x0000020A # pointeur de la molette
  def handle # recuperation du handle du rgss player
    game_name="\0"*256
    GetPrivateProfileStringA.call('Game','Title','',game_name,255,".\\Game.ini")
    game_name.delete!("\0")
    return handle=FindWindowA.call('RGSS Player',game_name)
  end
  def unpack_dword(buffer,offset=0) # décompactage d'integer 32bits
    ret=buffer[offset+0]&0x000000ff
    ret|=(buffer[offset+1] << (8*1))&0x0000ff00
    ret|=(buffer[offset+2] << (8*2))&0x00ff0000
    ret|=(buffer[offset+3] << (8*3))&0xff000000
    return ret
  end
  def unpack_msg(buffer) # décompactage du message de la molette
    msg=Message.new;msg.pt=Point.new
    msg.message=unpack_dword(buffer,4*1)
    msg.wparam=unpack_dword(buffer,4*2)
    msg.lparam=unpack_dword(buffer,4*3)
    msg.pt.x=unpack_dword(buffer,4*5)
    msg.pt.y=unpack_dword(buffer,4*6)
    return msg
  end
  def wmcallback(msg)
    return unless msg.message==Scroll
    param=Param.new
    param.x=word2signed_short(loword(msg.lparam))
    param.y=word2signed_short(hiword(msg.lparam))
    param.scroll=word2signed_short(hiword(msg.wparam))
    return [param.x,param.y,param.scroll]
  end
  def hiword(dword);return ((dword&0xffff0000)>>16)&0x0000ffff;end #
  def loword(dword);return dword&0x0000ffff;end
  def word2signed_short(value)
    return value if (value&0x8000)==0
    return -1*((~value&0x7fff)+1)
  end
  def click?(button);@keys.include?(button)?(return true):(return false);end  #si clic
  def press?(button);@press.include?(button)?(return true):(return false);end # si appui
  def pressed?(key);return true unless GetKeyState.call(key).between?(0,1);return false;end # test appui
  def global_pos;pos=[0,0].pack('ll');GetCursorPo.call(pos)!=0 ? (return pos.unpack('ll')):(return nil);end # pos a l'ecran
  def set_pos(x_pos=0,y_pos=0) # positionnement
    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 # maj des entrees
    @pos,@keys,@press=pos,[],[]
    @keys << 1 if GetAsyncKeyState.call(1)&0x01==1
    @keys << 2 if GetAsyncKeyState.call(2)&0x01==1
    @keys << 3 if GetAsyncKeyState.call(4)&0x01==1
    @press << 1 if pressed?(1)
    @press << 2 if pressed?(2)
    @press << 3 if pressed?(4)
  end  
  def pos # recuperation position dans player
    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 dans_player? # teste si curseur est dans player
    return true if global_pos[0].between?(client_pos[0],client_pos[0]+client_size[0])&&
    global_pos[1].between?(client_pos[1],client_pos[1]+client_size[1])
    return false
  end
  def screen_to_client(x,y) #pos player dans ecran
    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 # dimensions player
    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 # position player
    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 # convertit position en position carreaux
    return nil if @pos.nil?
    return [(@pos[0]+$game_map.display_x/8)/32,(@pos[1]+$game_map.display_y/8)/32]
  end
  def scroll # retourne l'etat de la molette
    msg="\0"*32;Get_Message.call(msg,0,0,0);r=wmcallback(unpack_msg(msg))
    return r if !r.nil?
  end
end
$souris=Souris.new # lancement de la classe souris
module Input
  class << self
    alias :update_souris :update unless Input.methods.include?("update_souris")
    def update
      update_souris
      $souris.update # maj souris
    end
  end
end

class Scene_Map
  alias :souris_update :update
  def update
    souris_update
    update_scroll if $souris.dans_player?&&$game_switches[Berka::Souris::ID_Int]
  end
  def update_scroll
    s=$souris.scroll;return if s.nil?
    s[2]<0 ? (Input.press?(Input::CTRL) ? d=6 : d=2) : (Input.press?(Input::CTRL) ? d=4 : d=8)
    $game_map.start_scroll(d,1,Berka::Souris::Vitesse) # lance le scroll dans la direction d
  end
end


Instructions
place this script above main
Active the switch[1] to run the scroll system

FAQ
mousewheel: y
ctrl+mousewheel: x

Compatibility
I don't really know

Credits and Thanks
˜aŠó in: mousewheel reader

Terms and Conditions
free but credits are required

This post has been edited by berka: Dec 16 2008, 11:40 AM


__________________________
Go to the top of the page
 
+Quote Post
   
SuperMega
post Dec 15 2008, 04:13 PM
Post #2


Public memberTitle(String n)
Group Icon

Group: Revolutionary
Posts: 683
Type: Developer
RM Skill: Skilled




This seems to work very nicely, thank you. Simple, yet so useful!


__________________________
Translated Scripts:
Diagonal Movement (Eight Direction) and Smooth Jumping
Attack Party, Heal Enemies
Display Party Status On Map (DQ Style)
Display Maps Under Maps
Save Screen Customization
Subtitled Menus

If you want to suggest a translation for something, PM me, and I'll take a look. I AM TRYING TO GIVE AWAY LOCKERZ.com INVITES, SO PLEASE LET ME KNOW IF YOU WANT ONE.
Currently Working on 2 RPG Maker VX Projects. They are very unique, and have a different kind of style then the usual RPGs. So don't think of them as just another RPG. Did that sound rude? :D Not sure if I want them to go public yet, but we'll see how it goes.
Need a script translated? Come talk to me, and I'll see what I can do.
Go to the top of the page
 
+Quote Post
   
dandanthedan
post Dec 16 2008, 12:09 AM
Post #3


Death Striker
Group Icon

Group: Revolutionary
Posts: 299
Type: Developer
RM Skill: Skilled




wow! nice one! i think im going to use this...happy.gif


__________________________
[Show/Hide] My Current Project


Box by Me


[Show/Hide] click me!



recruiting: writer(for the dialogues), mapper and eventer...
visit this thread to join: Grendis Recruitment Thread
"You can tame a lion, but you can never make it vegetables"
Go to the top of the page
 
+Quote Post
   
Bobbery
post Dec 16 2008, 01:14 AM
Post #4



Group Icon

Group: Member
Posts: 3
Type: Event Designer
RM Skill: Advanced




This is a decent script, I may use this in my game.
Go to the top of the page
 
+Quote Post
   
berka
post Dec 16 2008, 11:40 AM
Post #5


Level 8
Group Icon

Group: Revolutionary
Posts: 111
Type: Scripter
RM Skill: Advanced




thanks


xp version added !


__________________________
Go to the top of the page
 
+Quote Post
   
Rob3455
post Dec 16 2008, 01:55 PM
Post #6


Level 2
Group Icon

Group: Member
Posts: 24
Type: Musician
RM Skill: Masterful




I'd like to use this, but I don't know how to work with scripts. sad.gif

Can anyone help a brother out?
Go to the top of the page
 
+Quote Post
   
berka
post Dec 17 2008, 01:54 AM
Post #7


Level 8
Group Icon

Group: Revolutionary
Posts: 111
Type: Scripter
RM Skill: Advanced




open the scripts editor... (F11)
you scroll down and find "main"
and you pastle this script above it !


__________________________
Go to the top of the page
 
+Quote Post
   
onidsouza
post Jan 26 2009, 04:32 PM
Post #8


image master of doom
Group Icon

Group: Revolutionary
Posts: 603
Type: None
RM Skill: Undisclosed




Cool! Very Nice! i didn't read the hole script (it's in french) but there is a way that user can scroll the map to all the 4 directions (Up, Down, Left Right) using the scroll button and more two buttons? will be Great!!! once i read the script if can i will try make the 4 directional scrolling
Nice Script!


__________________________
Gabba Gabba Hey! enjoy your life ^^
lol (by keet's brother)
some lol
more lol
even MORE lol
Serious Discussion
why all my lol's have Teh Parakeet involved?

me ^^

bacon

Spamming is always better with bacon
Go to the top of the page
 
+Quote Post
   
883377779999
post Sep 16 2011, 10:48 AM
Post #9


Level 1
Group Icon

Group: Member
Posts: 14
Type: Writer
RM Skill: Intermediate




Wow, thank you very much.

Only wish that i had found this earlier >_> before making that loose replica of earth's world map of mine

http://i904.photobucket.com/albums/ac247/i...e/Untitled1.jpg
THANKS anyway cuz this will be useful on event locating : )

This post has been edited by 883377779999: Sep 16 2011, 10:48 AM


__________________________
"Being a hero only means saving the world. There is nothing that says I can't enjoy myself during the trip."

- by The Hero
Go to the top of the page
 
+Quote Post
   
berka
post Sep 16 2011, 01:04 PM
Post #10


Level 8
Group Icon

Group: Revolutionary
Posts: 111
Type: Scripter
RM Skill: Advanced




Thank you for using my script!
But on your screenshot .... what happened with France? The Bretagne is gone! happy.gif

Regards,

Berka

This post has been edited by berka: Sep 18 2011, 01:16 PM


__________________________
Go to the top of the page
 
+Quote Post
   
883377779999
post Sep 16 2011, 01:59 PM
Post #11


Level 1
Group Icon

Group: Member
Posts: 14
Type: Writer
RM Skill: Intermediate




QUOTE (berka @ Sep 16 2011, 02:04 PM) *
Thank you for using my script!
But on your screenshot .... as happened with France? The Bretagne is gone! happy.gif

Regards,

Berka



LOL i said loosely didnt I

Had to destroy something for convenience's sake and ...other issues lol


__________________________
"Being a hero only means saving the world. There is nothing that says I can't enjoy myself during the trip."

- by The Hero
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 24th May 2013 - 11:42 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker