Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
phionabrie

Help needed for Mouse script

Recommended Posts

For the game I am working on, I want the player to be able to use either the keyboard or the mouse (or both).  I have found a few different mouse scripts, but they don't seem to quite work the way I want them to.  The features I want are:
 
Mouse Left = Enter/Spacebar/C
Mouse Right = Esc/X
Mouse Left on map = go to spot clicked/begin event clicked
And I want the mouse to go invisible while using the keyboard but come back when I move it
 
The scripts I have:
 

Mouse Input 7.0 by Near Fantastica and SephirothSpawn

Part 1

 

module StartGame
   $game_mouse = true
  
end


Part 2

 

#==============================================================================
# ** Modules.Mouse Input (7.0)              By Near Fantastica & SephirothSpawn
#==============================================================================
module Mouse
  #--------------------------------------------------------------------------
  # * Mouse to Input Triggers
  #
  #   key => Input::KeyCONSTANT (key: 0 - Left, 1 - Middle, 2 - Right)
  #--------------------------------------------------------------------------
  Mouse_to_Input_Triggers = {0 => Input::C, 1 => Input::B, 2 => Input::A}
  #--------------------------------------------------------------------------
  # * API Declaration
  #--------------------------------------------------------------------------
  GAKS          = Win32API.new('user32',    'GetAsyncKeyState', 'i',     'i')
  GSM           = Win32API.new('user32',    'GetSystemMetrics', 'i',     'i')
  Cursor_Pos    = Win32API.new('user32',    'GetCursorPos',     'p',     'i')
  $ShowCursor   = Win32API.new('user32',    'ShowCursor',       'i',     'l')
  Scr2cli       = Win32API.new('user32',    'ScreenToClient',   %w(l p), 'i')
  Client_rect   = Win32API.new('user32',    'GetClientRect',    %w(l p), 'i')
  Findwindow    = Win32API.new('user32',    'FindWindowA',      %w(p p), 'l')
  Readini       = Win32API.new('kernel32',  'GetPrivateProfileStringA',
                               %w(p p p p l p), 'l')
                              
  # if graphical effects turned on, show fancy cursor
  $ShowCursor.call($game_mouse ? 0 : 1)
 
  @triggers     =   [[0, 1], [0, 2], [0, 4]]
  @old_pos      =   0
  @pos_i        =   0
   
  #--------------------------------------------------------------------------
  # * Mouse Grid Position
  #--------------------------------------------------------------------------
  def self.grid   
    # Return Nil if Position is Nil
    return nil if @pos.nil?
   
    # Get X & Y Locations 
    x = (@pos[0] + $game_map.display_x / 4) / 32
    y = (@pos[1] + $game_map.display_y / 4) / 32
   
    # Vehicle Stuff
    $mouse_x = x
    $mouse_y = y
   
    # Return X & Y
    return [x, y]
   
  end
  #--------------------------------------------------------------------------
  # * Mouse Position
  #--------------------------------------------------------------------------
  def self.position
    return @pos == nil ? [0, 0] : @pos
  end
  #--------------------------------------------------------------------------
  # * Mouse Global Position
  #--------------------------------------------------------------------------
  def self.global_pos
    # Packs 0 Position
    pos = [0, 0].pack('ll')
    # Returns Unpacked Cursor Position Call
    return Cursor_Pos.call(pos) == 0 ? nil : pos.unpack('ll')
  end
 
  #--------------------------------------------------------------------------
  # * Screen to Client
  #--------------------------------------------------------------------------
  def self.screen_to_client(x=0, y=0)
    pos = [x, y].pack('ll')
    return Scr2cli.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
  end 
   
  #--------------------------------------------------------------------------
  # * Mouse Position
  #--------------------------------------------------------------------------
  def self.pos
    global_pos = [0, 0].pack('ll')   
    gx, gy = Cursor_Pos.call(global_pos) == 0 ? nil : global_pos.unpack('ll')
    local_pos = [gx, gy].pack('ll')
    x, y = Scr2cli.call(self.hwnd, local_pos) == 0 ? nil : local_pos.unpack('ll')
   
    # Begins Test
    begin
      # Return X & Y or Nil Depending on Mouse Position
      if (x >= 0 && y >= 0 && x <= 640 && y <= 480)
        return x, y
      else
        return -20, -20
      end
    rescue
      return 0, 0 #nil
    end
   
  end 
   
  #--------------------------------------------------------------------------
  # * Update Mouse Position
  #--------------------------------------------------------------------------
  def self.update
   
    # Update Position
    old_pos = @pos
    @pos = self.pos
   
    # agf = hide system mouse
    if !$mouse_sprite.visible && old_pos != @pos
      $mouse_sprite.visible = true
    end
   
    # when mouse leaves game window, show system mouse
    if old_pos != [-20, -20] && @pos == [-20, -20]
      $ShowCursor.call(1)
    # when mouse is in game window, show custom mouse if it's turned on
    elsif old_pos == [-20, -20] && @pos != [-20, -20]
      $ShowCursor.call($game_mouse ? 0 : 1)
    end
    # Update Triggers
    for i in @triggers
      # Gets Async State
      n = GAKS.call(i[1])
      # If 0 or 1
      if [0, 1].include?(n)
        i[0] = (i[0] > 0 ? i[0] * -1 : 0)
      else
        i[0] = (i[0] > 0 ? i[0] + 1 : 1)
      end
    end
   
  end
  #--------------------------------------------------------------------------
  # * Trigger?
  #     id : 0:Left, 1:Right, 2:Center
  #--------------------------------------------------------------------------
  def self.trigger?(id = 0)
   
    #only user trigger if in range of screen
    pos = self.pos
    if pos != [-20,-20]
   
    case id
      when 0  # Left
        return @triggers[id][0] == 1
      when 1  # Right (only when menu enabled)
        if @triggers[1][0] == 1 && !$game_system.menu_disabled
          return @triggers[id][0] == 1     
        end
      when 2  # Center
        return @triggers[id][0] == 1
    end   
   
    end
   
  end
  #--------------------------------------------------------------------------
  # * Repeat?
  #     id : 0:Left, 1:Right, 2:Center
  #--------------------------------------------------------------------------
  def self.repeat?(id = 0)
    if @triggers[id][0] <= 0
      return false
    else
      return @triggers[id][0] % 5 == 1 && @triggers[id][0] % 5 != 2
    end
  end
  #--------------------------------------------------------------------------
  # * Screen to Client
  #--------------------------------------------------------------------------
  def self.screen_to_client(x=0, y=0)
    # Pack X & Y
    pos = [x, y].pack('ll')
    # Return Unpacked Position or Nil
    return Scr2cli.call(self.hwnd, pos) == 0 ? nil : pos.unpack('ll')
  end
  #--------------------------------------------------------------------------
  # * Hwnd - window handle
  #--------------------------------------------------------------------------
  def self.hwnd
    if @hwnd.nil?
      # Finds Game Name from ini file
      game_name = "\0" * 256
      Readini.call('Game', 'Title', '', game_name, 255, ".\\Game.ini")
      game_name.delete!("\0")
      # Finds Window
      @hwnd = Findwindow.call('RGSS Player', game_name)
    end
    return @hwnd
  end
  #--------------------------------------------------------------------------
  # * Client Size
  #--------------------------------------------------------------------------
  def self.client_size
    # Packs Empty Rect
    rect = [0, 0, 0, 0].pack('l4')
    # Gets Game Window Rect
    Client_rect.call(self.hwnd, rect)
    # Unpacks Right & Bottom
    right, bottom = rect.unpack('l4')[2..3]
    # Returns Right & Bottom
    return right, bottom
  end
end
#==============================================================================
# ** Input
#==============================================================================
class << Input
  #------------------------------------------------------------------------
  # * Alias Listings
  #------------------------------------------------------------------------
  unless self.method_defined?(:seph_mouse_input_update)
    alias_method :seph_mouse_input_update,   :update
    alias_method :seph_mouse_input_trigger?, :trigger?
    alias_method :seph_mouse_input_repeat?,  :repeat?
  end
  #------------------------------------------------------------------------
  # * Frame Update
  #------------------------------------------------------------------------
  def update
    # Update Mouse
    Mouse.update
    # Original Update
    seph_mouse_input_update
  end
  #--------------------------------------------------------------------------
  # * Trigger? Test
  #--------------------------------------------------------------------------
  def trigger?(constant)
    # Return true if original test is true
    return true if seph_mouse_input_trigger?(constant)
    # If Mouse Position isn't Nil
    unless Mouse.pos.nil?
      # If Mouse Trigger to Input Trigger Has Constant
      if Mouse::Mouse_to_Input_Triggers.has_value?(constant)
        # Return True if Mouse Triggered
        mouse_trigger = Mouse::Mouse_to_Input_Triggers.index(constant)
        return true if Mouse.trigger?(mouse_trigger)     
      end
    end
    # Return False
    return false
  end
  #--------------------------------------------------------------------------
  # * Repeat? Test
  #--------------------------------------------------------------------------
  def repeat?(constant)
    # Return true if original test is true
    return true if seph_mouse_input_repeat?(constant)
    # If Mouse Position isn't Nil
    unless Mouse.pos.nil?
      # If Mouse Trigger to Input Trigger Has Constant
      if Mouse::Mouse_to_Input_Triggers.has_value?(constant)
        # Return True if Mouse Triggered
        mouse_trigger = Mouse::Mouse_to_Input_Triggers.index(constant)    
        return true if Mouse.repeat?(mouse_trigger)
      end
    end
    # Return False
    return false
  end
end

#==============================================================================
#  ¦ Path Finding
#==============================================================================
# Near Fantastica
# Version 1
# 29.11.05
#==============================================================================
  class Game_Character
    #--------------------------------------------------------------------------
    alias nf_pf_game_character_initialize initialize
    alias nf_pf_game_character_update update
    #--------------------------------------------------------------------------
    attr_accessor :map
    attr_accessor :runpath
    attr_accessor :ovrdest
    #--------------------------------------------------------------------------
    def initialize
      nf_pf_game_character_initialize
      @map = nil
      @runpath = false
      @ovrdest = false
    end
    #--------------------------------------------------------------------------
    def update
      run_path if @runpath == true
      nf_pf_game_character_update
    end
    #--------------------------------------------------------------------------
    def run_path
      return if moving?
      step = @map[@x,@y]
      if step == 1
        @map = nil
        @runpath = false
        return
      end
     
      dir = rand(2)
      case dir
      when 0
        move_right if @map[@x+1,@y] == step - 1 and step != 0
        move_down if @map[@x,@y+1] == step - 1 and step != 0
        move_left if @map[@x-1,@y] == step -1 and step != 0
        move_up if @map[@x,@y-1] == step - 1 and step != 0
      when 1
        move_up if @map[@x,@y-1] == step - 1 and step != 0
        move_left if @map[@x-1,@y] == step -1 and step != 0
        move_down if @map[@x,@y+1] == step - 1 and step != 0
        move_right if @map[@x+1,@y] == step - 1 and step != 0
      end
    end
    #--------------------------------------------------------------------------
    def find_path(x,y, force = true)
      sx, sy = @x, @y
      result = setup_map(sx,sy,x,y)     
      @runpath = result[0]
      @map = result[1]
      @map[sx,sy] = result[2] if result[2] != nil
      $game_player.ignore_movement = @runpath ? force : false
    end
    #--------------------------------------------------------------------------
    def clear_path
      @map = nil
      @runpath = false
      @ovrdest = false
      $game_player.ignore_movement = false
    end
    #--------------------------------------------------------------------------
    def setup_map(sx,sy,ex,ey)
      map = Table.new($game_map.width, $game_map.height)
      # Shaz - adding this comment to the second line of the event commands
      #     Mouse[0,1]
      # will cause the player to go to the tile BELOW the event, turn up,
      # and interact with the event ([0,1] is x+0, y+1)
      tx = ex
      ty = ey
      event = $game_map.event_at(ex, ey)
      if !event.nil? && !event.list.nil? && !event.erased &&
        event.list.size > 1 && event.list[1].code == 108
        text = event.list[1].parameters.to_s
        text.gsub!(/[Mm][Oo][uu][ss][Ee]\[([-,0-9]+),([-,0-9]+)\]/) do
          tx = ex + $1.to_i
          ty = ey + $2.to_i
          map[ex, ey] = 999
          @ovrdest = true
        end
      end
     
      update_counter = 0
      map[tx,ty] = 1
      old_positions = []
      new_positions = []
      old_positions.push([tx, ty])
      depth = 2
      $path_allow = false
      depth.upto(100){|step|
        loop do
          break if old_positions[0] == nil
          x,y = old_positions.shift
          return [true, map, step-1] if x == sx and y == sy
          if map[x,y + 1] == 0 and $game_player.passable?(x, y, 2, step, tx, ty)
            map[x,y + 1] = step
            new_positions.push([x,y + 1])
          end
          if map[x - 1,y] == 0 and $game_player.passable?(x, y, 4, step, tx, ty)
            map[x - 1,y] = step
            new_positions.push([x - 1,y])
          end
          if map[x + 1,y] == 0 and $game_player.passable?(x, y, 6, step, tx, ty)
            map[x + 1,y] = step
            new_positions.push([x + 1,y])
          end
          if map[x,y - 1] == 0 and $game_player.passable?(x, y, 8, step, tx, ty)
            map[x,y - 1] = step
            new_positions.push([x,y - 1])
          end
         
          # If we've checked quite a few tiles, allow graphics and input
          # to update - to avoid the 'script hanging' error
          update_counter += 1
          if update_counter > 100
            Graphics.update
            update_counter = 0
          end
        end
       
        old_positions = new_positions
        new_positions = []
      }
     
      @ovrdest = false
      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
    end
  end
 
  class Game_Player
    #--------------------------------------------------------------------------
    alias pf_game_player_update update
    #--------------------------------------------------------------------------
    def update
      $game_player.clear_path if Input.dir4 != 0
      pf_game_player_update
    end
  end
 
  class Interpreter
    #--------------------------------------------------------------------------
    def event
      return $game_map.events[@event_id]
    end
  end


Part 3

 

#==============================================================================
# ** MouseCursor
#==============================================================================
module MouseCursor
    Default_Cursor = 'arrow1'
    Event_Cursor   = 'arrow3'
    Actor_Cursor   = 'arrow2'
    Enemy_Cursor   = 'arrow4'
    Item_Cursor    = true
    Skill_Cursor   = true
    Dummy = Bitmap.new(32, 32)
end
#==============================================================================
# ** Sprite_Mouse
#==============================================================================
class Sprite_Mouse < Sprite
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super
    self.z = 10100
    self.ox = 4
    update
  end
  #--------------------------------------------------------------------------
  # ** Frame Update
  #--------------------------------------------------------------------------
  def update
    super
   
    # Update Visibility
    self.visible = $scene != nil
   
    # If Visible
    if self.visible
     
      # If Non-nil Mouse Position
      if Mouse.position != nil
       
        # Gets Mouse Position
        mx, my = *Mouse.position
       
        # Update POsition
        self.x = mx unless mx.nil?
        self.y = my unless my.nil?     
       
      end
     
      # If Scene changes or Mouse is Triggered
      if @scene != $scene.class || Mouse.trigger?
       
        # Update Scene Instance
        @scene = $scene.class
       
        # Update Bitmap
        set_bitmap(MouseCursor::Default_Cursor)
      end
     
    end
   
  end
  #--------------------------------------------------------------------------
  # ** Set Bitmap
  #--------------------------------------------------------------------------
  def set_bitmap(cursor, xNPCname = nil)
   
    # show fancy cursor only if custom mouse on
    if $game_mouse
            
      # If Cursor Info matches
      if (@_cursor == cursor) && (@_NPCname == xNPCname)
        return
      end
     
      # Reset Cursor Info
      @_cursor      = cursor
      @_NPCname     = xNPCname
     
      # Gets Dummy
      dummy = MouseCursor::Dummy
     
      # Gets Item Cursor Bitmap
      item_cursor = cursor.nil? ? MouseCursor::Default_Cursor : cursor
     
      # Start Cursor Bitmap
      bitmap = RPG::Cache.icon(item_cursor) if item_cursor != ''
      # Show NPC name
      if @_NPCname != nil
        # Get name width
        w = dummy.text_size(@_NPCname).width
        h = dummy.font.size
        b = RPG::Cache.icon(item_cursor)
        # Create New Bitmap
        bitmap = Bitmap.new((bitmap.nil? ? w : 40 + w), [b.height, h + 2].max)
        bitmap.font.size = dummy.font.size
        bitmap.blt(0, 0, b, b.rect)
        # Draw NPC Name
        x = item_cursor == '' ? 0 : 32
        bitmap.font.color = Color.new(0, 0, 0, 255) # black
        bitmap.draw_text(b.width + 9, 0, w, h, @_NPCname) # 0
        bitmap.draw_text(b.width + 11, 0, w, h, @_NPCname) # 0
        bitmap.draw_text(b.width + 10, -1, w, h, @_NPCname) # -1
        bitmap.draw_text(b.width + 10, 1, w, h, @_NPCname) # 1
        bitmap.font.color = Color.new(255, 255, 255, 255) # white
        bitmap.draw_text(b.width + 10, 0, w, h, @_NPCname)
      end   
      # Set Bitmap
      self.bitmap = bitmap
     
    elsif self.bitmap
      @_cursor = nil
      self.bitmap = nil
     
    end
   
  end
  #--------------------------------------------------------------------------
  # ** Frame Update : Update Event Cursors
  #--------------------------------------------------------------------------
  def update_event_cursors
   
    # If Nil Grid Position
    if Mouse.grid.nil?
      # Set Default Cursor
      set_bitmap(MouseCursor::Default_Cursor)
      return
    end
   
    # Gets Mouse Position
    x, y = *Mouse.grid
   
    # Gets Mouse Position
    mx, my = *Mouse.position   
   
    # Gets Mouse Event
    event = $game_map.event_at(x, y)
   
    # If Non-Nil Event or not over map HUD
    unless event.nil?
      # If Not Erased or Nil List
      if event.list != nil && event.erased == false && event.list[0].code == 108
        # Get the cursor to show
        icon = event.list[0].parameters
        icon = icon.to_s
        if !((icon == "arrow1") ||
           (icon == "arrow2") ||
           (icon == "arrow3") ||
           (icon == "arrow4"))
           icon = MouseCursor::Default_Cursor
        end       
        xNPCname = nil
        if event.list.size > 1 && event.list[1].code == 108
          text = event.list[1].parameters.to_s
          text.gsub!(/[Nn][Aa][Mm][Ee] (.*)/) do
            xNPCname = $1.to_s
          end
        end
        set_bitmap(icon, xNPCname)   
        return
      end
      return
    end
   
    # Set Default Cursor
    set_bitmap(MouseCursor::Default_Cursor)
   
  end
end
#==============================================================================
# ** Input
#==============================================================================
class << Input
  #------------------------------------------------------------------------
  # * Alias Listings
  #------------------------------------------------------------------------
  unless self.method_defined?(:sephlamchop_mousesys_input_update)
    alias_method :sephlamchop_mousesys_input_update,   :update
  end
  #------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    $mouse_sprite.update if $mouse_sprite.visible
    # Original Update
    sephlamchop_mousesys_input_update
  end
end


Part 4

 

WORLD_MAP_ID = 1
#==============================================================================
# ** Game_Map
#==============================================================================
class Game_Map
  #--------------------------------------------------------------------------
  # * Event At
  #--------------------------------------------------------------------------
  def event_at(x, y)
    for event in @events.values
        return event if event.x == x && event.y == y
    end
    return nil
  end
 
  #--------------------------------------------------------------------------
  # * Events At (returns multiple events at the same position in an array)
  #--------------------------------------------------------------------------
  def events_at(x, y)
    eventarray = []
    for event in @events.values
      eventarray.push event if event.x == x && event.y == y
    end
    return eventarray if eventarray.size > 0
    return nil
  end
end
#==============================================================================
# ** Game_Event
#==============================================================================
class Game_Event
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :erased                  # trigger
  attr_accessor :mouse_autostart         # mouse autostart boolean
  attr_accessor :mouse_cursor_icon       # mouse cursor icon
  attr_accessor :mouse_cursor_desc       # mouse cursor desc
  attr_reader   :name                    # name of event
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :sephlamchop_mousesys_gmevt_refresh, :refresh
  #--------------------------------------------------------------------------
  # * Start Event
  #--------------------------------------------------------------------------
  def start
    # If list of event commands is not empty
    if @list && @list.size > 1
      @starting = true
    end
  end 
  #--------------------------------------------------------------------------
  # * Refresh
  #-------------------------------------------------------------------------- 
  def refresh
    # Original Refresh
    sephlamchop_mousesys_gmevt_refresh
    # Click triggers event for action button, player or event touch
    @mouse_autostart   = [0, 1, 2].include?(@trigger)
    @mouse_cursor_icon = MouseCursor::Event_Cursor
    @mouse_cursor_desc = nil
    # Return if Erased or Nil List
    #return if @erased || @list.nil?
   
  end
end
#==============================================================================
# ** Game_Character
#==============================================================================
class Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :ignore_movement          # ignore movement when finding path AGF MOUSE
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :sephlamchop_mousesys_gmchrinitialize, :initialize
  def initialize
    sephlamchop_mousesys_gmchrinitialize
    @ignore_movement = false;
  end
 
  def passable?(x, y, d, step = 999, tx = nil, ty = nil)
   
    # Get new coordinates
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
   
    # If coordinates are outside of map
    unless $game_map.valid?(new_x, new_y)
      return false
    end
   
    # If through is ON
    if @through
      return true
    end
   
    # Able to leave current tile in desired direction?
    # SHAZ: for counter, must be old, counter, new, in a straight line
    unless $game_map.passable?(x, y, d, self) || (step == 2 && $game_map.event_at(x, y)) ||
      (step == 3 && $game_map.counter?(x, y) && tx != nil && ty != nil &&
      new_x - x == x - tx && new_y - y == y - ty)
      return false
    end
   
    # Able to enter adjoining tile in current direction?
    unless $game_map.passable?(new_x, new_y, 10 - d) ||
      (step == 2 && $game_map.counter?(new_x, new_y))
      return false
    end
    # SHAZ - ignore events sitting on a counter next to the destination
    if step != 2 || !$game_map.counter?(new_x, new_y)         
      # Loop all events
      for event in $game_map.events.values
        # If event coordinates are consistent with move destination
        if event.x == new_x and event.y == new_y
          @state = true
          # If through is OFF
          unless event.through
            # If self is event
            if self != $game_player
              return false
            end
            # With self as the player and partner graphic as character
            if event.character_name != ""
              return false
            end
          end
        end
      end
    end
   
    # If on world map, don't allow to go through events.  Otherwise,
    # the event will be triggered while the PC is walking
    if $game_map.map_id == WORLD_MAP_ID && @state == false
      return false
    end     
    # If player coordinates are consistent with move destination
    if $game_player.x == new_x && $game_player.y == new_y && self != $game_player
      # If through is OFF
      unless $game_player.through
        # If your own graphic is the character
        if @character_name != ""
          return false
        end
      end
    end
    return true
   
  end
end
#==============================================================================
# ** Game_Player
#==============================================================================
class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :sephlamchop_mousesys_gmplyr_update, :update
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Unless Interpreter Running, Forcing a Route or Message Showing
    unless $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing
          
      # Find Path If Mouse Triggered
      if Mouse.trigger?(0) && Mouse.grid != nil
        # Check if mouse is over HUD on map
        screen_x,screen_y = Mouse.pos
       
        # Gets Mouse X & Y
        mx, my = *Mouse.grid
       
        # Turn Character in direction
        newd_x = (@x - mx).abs
        newd_y = (@y - my).abs
       
        if @x > mx
            turn_left if newd_x >= newd_y
        elsif @x < mx
            turn_right if newd_x >= newd_y
        end 
           
        if @y > my
            turn_up if newd_x < newd_y
        elsif @y < my
            turn_down if newd_x < newd_y
        end
        # Run Pathfinding
        find_path(mx, my, false)
       
        # Gets Event
        @eventarray = @runpath ? $game_map.events_at(mx, my) : nil
        # If Event At Grid Location
        unless @eventarray.nil?
          @eventarray.each do |event|
            # If Event Autostart
            if !event.mouse_autostart
              @eventarray.delete(event)
            end
          end
          @eventarray = nil if @eventarray.size == 0
        end
       
      end
    end
   
    if @move_route_forcing
      clear_path
      @eventarray = nil
    end
   
    # Original Update
    sephlamchop_mousesys_gmplyr_update
    # If Non-nil Event Autostarter
    if @eventarray != nil && !moving? &&
      (!@ovrdest || @map.nil? || @map[@x,@y] == 1)
      # Gets Event
      @eventarray.each do |event|
     
        # If Event Within Range
        if event and (@x == event.x or @y == event.y)
          # SHAZ - trigger event when:
          # - Action button and standing on or beside, or with a counter between
          # - player/event touch and standing as close as possible (on, if possible)
          distance = Math.hypot(@x - event.x, @y - event.y)
          dir = @x < event.x ? 6 : @x > event.x ? 4 : @y < event.y ? 2 : @y > event.y ? 8 : 0
          if (event.trigger == 0 and (distance < 2 or (distance == 2 and
            $game_map.counter?((@x+event.x)/2, (@y+event.y)/2)))) or
            ([1,2].include?(event.trigger) and ((distance == 0 and
            $game_player.passable?(@x, @y, dir)) or (distance == 1 and
            !$game_player.passable?(@x, @y, dir))))
            # Turn toward Event
            if @x == event.x
              turn_up if @y > event.y
              turn_down if @y < event.y
            else
              turn_left if @x > event.x
              turn_right if @x < event.x
            end
            # Start Event
            clear_path
            event.start
            @eventarray.delete(event)
            @eventarray = nil if @eventarray.size == 0
          end
        end
     
      end     
    end
  end
 
  def passable?(x1, y1, d, step = 999, tx = nil, ty = nil)
    super
  end
 
end
#==============================================================================
# ** Mouse Selectable Windows
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 2.1
#==============================================================================
#==============================================================================
# ** Window_Base
#==============================================================================
class Window_Base
  #--------------------------------------------------------------------------
  # * Frame Update : Mouse Cursor - Item
  #--------------------------------------------------------------------------
  def update_mouse_cursors_item(item, cursor, show)
    # Return if not Active
    return unless self.active
    # Return if nil Position
    return if Mouse.position.nil?
    # Gets Mouse Position
    mx, my = Mouse.position
    # Gets Cursor Position
    cr = self.cursor_rect
    cx, cy = cr.x + self.x + 16, cr.y + self.y + 16
    cw, ch = cr.width, cr.height
    # If Not on Item
    if mx.between?(self.x, self.x + self.width) == false ||
       my.between?(self.y, self.y + self.height) == false || item.nil? ||
       @item_max == 0 || mx.between?(cx, cx + cw) == false ||
       my.between?(cy, cy + ch) == false
      # Clear Mouse Index
      @mouse_index = nil
      # Set Mouse to Default Cursor
      $mouse_sprite.set_bitmap(MouseCursor::Default_Cursor)
      return
    end
    # If Index is different than mouse index and window active
    if @mouse_index != @index
      # Reset Index
      @mouse_index = @index
      # set to item icon if cursor is true
      cursor = item.icon_name if cursor
      # Set Bitmap
      $mouse_sprite.set_bitmap(cursor)
    end
  end
 
end
class Window_Selectable
  #--------------------------------------------------------------------------
  # * Default Settings
  #--------------------------------------------------------------------------
  Default_Mouse_Selectable = true
  Default_Window_Padding   = 16
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :mouse_selectable
  attr_accessor :window_padding
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_mouseselectable_wndslct_init,   :initialize
  alias_method :seph_mouseselectable_wndslct_update, :update
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height)
    # Original Initialization
    seph_mouseselectable_wndslct_init(x, y, width, height)
    # Set Mouse Selectable Flag
    @mouse_selectable = Default_Mouse_Selectable
    @window_padding   = Default_Window_Padding
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
   
    # agf = hide mouse
    if $mouse_sprite.visible == true
   
    # If Mouse Selectable, Active, at Least 1 Item and Non-negitive index
    if self.mouse_selectable && self.active && @item_max > 0 && @index >= 0
      # Gets Mouse Position
      mouse_x, mouse_y = *Mouse.position
     
      # If Mouse Within Window      
      if mouse_x.between? (self.x, self.x + self.width) &&
         mouse_y.between? (self.y, self.y + self.height)
        # Calculates Mouse X and Y Position Within Window
        mouse_x -= self.x; mouse_y -= self.y
        # Subtracts Window Padding
        mouse_x -= @window_padding; mouse_y -= @window_padding
        # Subtracts Mouse Oh
        mouse_y -= self.mouse_oh
        # Gets Cursor Width
        cursor_width = (self.width / @column_max - 32)
        # Passes Through Item Max
        for i in 0...@item_max
          # Calculates Index Position
          x = i % @column_max * (cursor_width + 32)
          y = i / @column_max * self.oh - self.oy
          # If Mouse Between Rect
          if mouse_x.between?(x, x + cursor_width) &&
             mouse_y.between?(y, y + self.oh)
            # Set Index
            prev_index = @index
            @index = i
            if prev_index != @index
              $game_system.se_play($data_system.cursor_se)
            end
            break
          end
        end
      end
    end
   
    end
   
    # Original Update
    seph_mouseselectable_wndslct_update
  end
  #--------------------------------------------------------------------------
  # * Oh
  #--------------------------------------------------------------------------
  def oh
    return 32
  end
  #--------------------------------------------------------------------------
  # * Mouse Oh
  #--------------------------------------------------------------------------
  def mouse_oh
    return 0
  end 
 
end
#==============================================================================
# ** Window_MenuStatus
#==============================================================================
class Window_MenuStatus < Window_Selectable
  #--------------------------------------------------------------------------
  # * Oh
  #--------------------------------------------------------------------------
  def oh
    return 60
  end
end
#==============================================================================
# ** Window_Target
#==============================================================================
class Window_Target < Window_Selectable
  #--------------------------------------------------------------------------
  # * Oh
  #--------------------------------------------------------------------------
  def oh
    return 105
  end
end
#==============================================================================
# ** Window_BattleReserve
#==============================================================================
class Window_BattleReserve < Window_Selectable
  #--------------------------------------------------------------------------
  # * Oh
  #--------------------------------------------------------------------------
  def oh
    return 105
  end
end
#==============================================================================
# ** Window_EquipRight
#==============================================================================
class Window_EquipRight < Window_Selectable
  #--------------------------------------------------------------------------
  # * Oh
  #--------------------------------------------------------------------------
  def oh
    return 50
  end
 
  #--------------------------------------------------------------------------
  # * Mouse Oh
  #--------------------------------------------------------------------------
  def mouse_oh
    return 140
  end 
 
end
#==============================================================================
# ** Window_Message
#==============================================================================
class Window_Message < Window_Selectable
  #--------------------------------------------------------------------------
  # * Mouse Oh
  #--------------------------------------------------------------------------
  def mouse_oh
    return $game_temp.choice_start * 32
  end
end
#==============================================================================
# ** Window_Party
#==============================================================================
class Window_Party < Window_Selectable
  #--------------------------------------------------------------------------
  # * Oh
  #--------------------------------------------------------------------------
  def oh
    return 52
  end
end

#==============================================================================
# ** Window_Menu
#==============================================================================
class Window_Menu < Window_Selectable
  #--------------------------------------------------------------------------
  # * Oh
  #--------------------------------------------------------------------------
  def oh
    return 35
  end
end
#==============================================================================
# ** Window_ActorCommand
#==============================================================================
class Window_ActorCommand < Window_Selectable
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
    if $mouse_sprite.visible
     
      # if Mouse sleectable, active, at least 1 item and non-negative index
      if self.mouse_selectable && self.active && @item_max > 0 && @index >= 0
        # Get / check mouse position
        mouse_x, mouse_y = *Mouse.position
       
        if mouse_x.between?(self.x, self.x + self.width) &&
          mouse_y.between?(self.y, self.y + self.height)
         
          # Calculates mouse position within window
          mouse_x -= self.x
          mouse_y -= self.y
         
          # Subtracts widnow padding and overhead
          mouse_x -= @window_padding
          mouse_y -= @window_padding - self.mouse_oh
         
          # Look through all items
          for i in 0...@item_max
            ix,iy = @positions
            if mouse_x.between?(ix, ix + 32) && mouse_y.between?(iy, iy + self.oh)
              if i != @index
                $game_system.se_play($data_system.cursor_se)
              end
              @index = i
              break
            end
          end
        end
      end
    end
   
    super
  end
 
  #--------------------------------------------------------------------------
  # * Oh
  #--------------------------------------------------------------------------
  def oh
    return 32 
  end
end

#==============================================================================
# ** Window_NameInput
#==============================================================================
class Window_NameInput < Window_Base
  #--------------------------------------------------------------------------
  # * Default Settings
  #--------------------------------------------------------------------------
  Default_Mouse_Selectable = true
  Default_Window_Padding = 16
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :mouse_selectable
  attr_accessor :window_padding
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :shaz_mouseselectable_wndslct_init,   :initialize
  alias_method :shaz_mouseselectable_wndslct_update, :update
  #--------------------------------------------------------------------------
  # â— Initialize the Name Input window
  #--------------------------------------------------------------------------
  def initialize
    # Original Initialization
    shaz_mouseselectable_wndslct_init
    # Set Mouse Selectable Flag
    @mouse_selectable = Default_Mouse_Selectable
    @window_padding = Default_Window_Padding
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
   
    # if mouse selectable, visible, active, and non-negative index
    if $mouse_sprite.visible && self.mouse_selectable && self.active &&
      @index >= 0
     
      # Get mouse position
      mouse_x, mouse_y = *Mouse.position
     
      # If mouse within window
      if mouse_x.between? (self.x, self.x + self.width) &&
        mouse_y.between? (self.y, self.y + self.height)
       
        # Calculates mouse X and Y positions within window
        mouse_x -= self.x; mouse_y -= self.y
       
        # Subtracts window padding
        mouse_x -= @window_padding; mouse_y -= @window_padding
       
        # Subtracts mouse oh
        mouse_y -= self.mouse_oh
       
        # Gets cursor width
        cursor_width = 28
       
        # If not Submit button, pass through all items
        if mouse_x.between?(428, 428+48) && mouse_y.between?(9*32, 9*32+32)
          $game_system.se_play($data_system.cursor_se) if @index != 180
          @index = 180
        else
          for i in 0..90 
           
            # Calculate index position
            x = 140 + i / 5 / 9 * 180 + i % 5 * 32
            y = i / 5 % 9 * 32
           
            # If mouse between rect
            if mouse_x.between?(x, x + cursor_width) &&
              mouse_y.between?(y, y + self.oh)
              # set index
              prev_index = @index
              @index = i
              if prev_index != @index
                $game_system.se_play($data_system.cursor_se)
              end
              break
            end
          end
        end
      end
    end
   
    # Original update
    shaz_mouseselectable_wndslct_update
  end
 
  #--------------------------------------------------------------------------
  # * Oh
  #--------------------------------------------------------------------------
 
  def oh
    return 32
  end
 
  #--------------------------------------------------------------------------
  # * Mouse Oh
  #--------------------------------------------------------------------------
 
  def mouse_oh
    return 0
  end
 
end

#==============================================================================
# ** Scene_File
#==============================================================================
class Scene_File
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :sephlamchop_mousesys_scnfl_update, :update
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
   
    # agf = hide mouse
    if $mouse_sprite.visible == true   
   
    # If Mouse Position isn't Nil
    if Mouse.pos != nil
     
      # Gets Mouse Position
      x, y = Mouse.pos
      y = y + 32
     
      # Pass Through Savefile Windows
      for i in 0...@savefile_windows.size
       
        # Gets Window
        w = @savefile_windows
       
        # Don't allow user to select autosave slot in Load Menu
        if @autosave_slot == false
          i = 1 if i == 0
        end
       
        # If Within Window Range
        if x.between?(w.x, w.x + w.width) &&
           y.between?(w.y, w.y + w.height) && w.active
                     
          prev_index = @file_index
          
          # Set File Index
          @file_index = i
         
          # Turns Window On
          w.selected = true
         
          # Play SE
          if prev_index != @file_index
            $game_system.se_play($data_system.cursor_se)
          end         
         
          # Unhighlight remaining windows
          for j in 0...@savefile_windows.size
            if j != i
               @savefile_windows[j].selected = false
            end
          end        
          # Don't select autosave slot in Load Menu
          if @autosave_slot == false
            @savefile_windows[0].selected = false if i == 1
          end
         
          # Break Main Loop
          break           
        end
      end
    end
 
    end
 
    # Original Update
    sephlamchop_mousesys_scnfl_update
  end
end

#==============================================================================
# ** Game_Battler
#==============================================================================
class Game_Battler
  #--------------------------------------------------------------------------
  # * Battler Width
  #--------------------------------------------------------------------------
  def battler_width
    return RPG::Cache.battler(@battler_name, @battler_hue).width
  end
  #--------------------------------------------------------------------------
  # * Battler Height
  #--------------------------------------------------------------------------
  def battler_height
    return RPG::Cache.battler(@battler_name, @battler_hue).height
  end
end
#==============================================================================
# ** Arrow_Enemy
#==============================================================================
class Arrow_Enemy < Arrow_Base
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_mouseselectablewindows_arrenmy_update, :update
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Original Update
    seph_mouseselectablewindows_arrenmy_update
   
    if $mouse_sprite.visible == true
      # Return if Nil Mouse Position
      return if Mouse.position.nil?
      # Gets Mouse Position
      mx, my = *Mouse.position
      # Pass Through Enemies
      $game_troop.enemies.each do |enemy|
        # Skip if Non-Existing Enemy
        next unless enemy.exist?
        # Gets Paddings
        w, h = enemy.battler_width / 2, enemy.battler_height
        # If Within Mouse Padding Range
        if mx.between?(enemy.screen_x - w, enemy.screen_x + w) &&
           my.between?(enemy.screen_y - h, enemy.screen_y + 10)
          # Set Index
          @index = $game_troop.enemies.index(enemy)
          # Set mouse cursor to bitmap
          $mouse_sprite.set_bitmap(MouseCursor::Enemy_Cursor)
          return
          # break
        end
      end
   
      # Set Mouse to Default Cursor
      $mouse_sprite.set_bitmap(MouseCursor::Default_Cursor)
    end
   
  end
end
#==============================================================================
# ** Arrow_Actor
#==============================================================================
class Arrow_Actor < Arrow_Base
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_mouseselectablewindows_arractr_update, :update
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Original Update
    seph_mouseselectablewindows_arractr_update
    # Return if Nil Mouse Position
    return if Mouse.position.nil?
    # Gets Mouse Position
    mx, my = *Mouse.position
    # Pass Through Actors
    $game_party.actors.each do |actor|
      # Gets Paddings
      w, h = actor.battler_width / 2, actor.battler_height
      # If Within Mouse Padding Range
      if mx.between?(actor.screen_x - w, actor.screen_x + w) &&
         my.between?(actor.screen_y - h, actor.screen_y + 10)
        # Set Index
        @index = $game_party.actors.index(actor)
      end
    end
  end
end
#==============================================================================
# ** Scene_Map
#==============================================================================
class Scene_Map
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :sephlamchop_mousesys_scnmap_update, :update
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Unless Message Showing
    unless $game_temp.message_text
      # Update Event Cursors
      $mouse_sprite.update_event_cursors
    end
    # Original Update
    sephlamchop_mousesys_scnmap_update
  end
end
#==============================================================================
# ** Interpreter
#==============================================================================
class Interpreter
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :shaz_mousesys_intrprtr_command_101, :command_101
  #--------------------------------------------------------------------------
  # * Show Text
  #--------------------------------------------------------------------------
  def command_101
    # return mouse sprite to default cursor
    $mouse_sprite.set_bitmap(MouseCursor::Default_Cursor)
    # original command_101
    shaz_mousesys_intrprtr_command_101
  end
end
$mouse_sprite = Sprite_Mouse.new
# game mouse is visible, system mouse is hidden
$mouse_sprite.visible = true


Cool script, but complicated, and it irritates me because it supersedes the keyboard and doesn't hide.  It also ignores my terrain tags for damage/healing floors. 

 
And I have a set of scripts by Blizzard, which if they all worked together might be what I want, but I don't know how to bridge them.

 

Part 1

 

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Custom Game Controls by Blizzard
# Version: 4.1
# Date: 19.4.2007
# Date v1.2: 20.10.2007
# Date v2.0b: 3.4.2008
# Date v2.1b: 25.10.2008
# Date v2.2b: 11.6.2009
# Date v3.0: 20.7.2009
# Date v4.0: 22.6.2012
# Date v4.1: 28.7.2012
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# VERY IMPORTANT NOTE:
#
# DO NOT USE THIS ADD-ON IF YOU ARE USING BLIZZ-ABS!!!
#
#
# Compatiblity:
#
# 99% compatible with SDK 1.x, 90% compatible with SDK 2.x.
#
#
# Note:
#
# Why is this input module better than others? I has far less code and it
# can handle keyboard language layout.
#
#
# Explanation & Configuration:
#
# This Add-on will allow you to specify your own game controls. Just below
# is a list of possible keys, below that is the configuration. The default
# configuration is RMXP's real game control configuration. You can add any
# key specification into a key array and separate them with commas. Example:
#
# RIGHT = [Key['Arrow Right'], Key[','], Key['F'], Key['Ctrl'], Key['3'],
# Key['NumberPad 6'], Key['F3'], Key['\''], Key['\\']]
#
# This example would assign for the RIGHT button the following keys:
# - directional right (right arrow key)
# - comma
# - letter key F
# - Control key (CTRL)
# - Number Key 3 (on top over the letter keys)
# - Numberpad Key 6 (number 6 on the numberpad on the right)
# - Functional Key 3 (F3)
# - apostrophe (')
# - backslash (\)
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

if TONS_OF_ADDONS::CUSTOM_CONTROLS

#==============================================================================
# module Input
#==============================================================================

module Input

#----------------------------------------------------------------------------
# Simple ASCII table
#----------------------------------------------------------------------------
Key = {'A' => 65, 'B' => 66, 'C' => 67, 'D' => 68, 'E' => 69, 'F' => 70,
'G' => 71, 'H' => 72, 'I' => 73, 'J' => 74, 'K' => 75, 'L' => 76,
'M' => 77, 'N' => 78, 'O' => 79, 'P' => 80, 'Q' => 81, 'R' => 82,
'S' => 83, 'T' => 84, 'U' => 85, 'V' => 86, 'W' => 87, 'X' => 88,
'Y' => 89, 'Z' => 90,
'0' => 48, '1' => 49, '2' => 50, '3' => 51, '4' => 52, '5' => 53,
'6' => 54, '7' => 55, '8' => 56, '9' => 57,
'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,
'F1' => 112, 'F2' => 113, 'F3' => 114, 'F4' => 115, 'F5' => 116,
'F6' => 117, 'F7' => 118, 'F8' => 119, 'F9' => 120, 'F10' => 121,
'F11' => 122, 'F12' => 123,
';' => 186, '=' => 187, ',' => 188, '-' => 189, '.' => 190, '/' => 220,
'\\' => 191, '\'' => 222, '[' => 219, ']' => 221, '`' => 192,
'Backspace' => 8, 'Tab' => 9, 'Enter' => 13, 'Shift' => 16,
'Left Shift' => 160, 'Right Shift' => 161, 'Left Ctrl' => 162,
'Right Ctrl' => 163, 'Left Alt' => 164, 'Right Alt' => 165,
'Ctrl' => 17, 'Alt' => 18, 'Esc' => 27, 'Space' => 32, 'Page Up' => 33,
'Page Down' => 34, 'End' => 35, 'Home' => 36, 'Insert' => 45,
'Delete' => 46, 'Arrow Left' => 37, 'Arrow Up' => 38,
'Arrow Right' => 39, 'Arrow Down' => 40,
'Mouse Left' => 1, 'Mouse Right' => 2, 'Mouse Middle' => 4,
'Mouse 4' => 5, 'Mouse 5' => 6}
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# START Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
UP = [Key['Arrow Up'], Key['W']]
LEFT = [Key['Arrow Left'], Key['A']]
DOWN = [Key['Arrow Down'], Key['S']]
RIGHT = [Key['Arrow Right'], Key['D']]
A = [Key['Shift']]
B = [Key['Esc'], Key['Mouse Right'], Key['NumberPad 0']]
C = [Key['Space'], Key['Enter'], Key['Mouse Left'], Key['C']]
X = [Key['X']]
Y = [Key['Y']]
Z = [Key['Z']]
L = [Key['L'], Key['Page Down']]
R = [Key['R'], Key['Page Up']]
F5 = [Key['F5']]
F6 = [Key['F6']]
F7 = [Key['F7']]
F8 = [Key['F8']]
F9 = [Key['F9']]
SHIFT = [Key['Shift']]
CTRL = [Key['Ctrl']]
ALT = [Key['Alt']]
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# END Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# All keys
KEY_COUNT = 256
ALL_KEYS = (0...KEY_COUNT).to_a
# Win32 API calls
GetKeyboardState = Win32API.new('user32', 'GetKeyboardState', 'P', 'I')
GetKeyboardLayout = Win32API.new('user32', 'GetKeyboardLayout', 'L', 'L')
MapVirtualKeyEx = Win32API.new('user32', 'MapVirtualKeyEx', 'IIL', 'I')
ToUnicodeEx = Win32API.new('user32', 'ToUnicodeEx', 'LLPPILL', 'L')
# some other constants
DOWN_STATE_MASK = 0x80
DEAD_KEY_MASK = 0x80000000
# data
@state = "\0" * KEY_COUNT
@triggered = Array.new(KEY_COUNT, false)
@pressed = Array.new(KEY_COUNT, false)
@released = Array.new(KEY_COUNT, false)
@repeatedKey = -1
@repeatedCount = 0
#----------------------------------------------------------------------------
# update
# Updates input.
#----------------------------------------------------------------------------
def self.update
# prevents usage with Blizz-ABS
if $BlizzABS
# error message
raise 'Blizz-ABS was detected! Please turn off Custom Controls in Tons of Add-ons!'
end
# get current language layout
@language_layout = GetKeyboardLayout.call(0)
# get new keyboard state
GetKeyboardState.call(@state)
# this special code is used because Ruby 1.9.x does not return a char
# when using String#[] but another String
key = 0
@state.each_byte {|byte|
# if pressed state
if (byte & DOWN_STATE_MASK) == DOWN_STATE_MASK
# not released anymore
@released[key] = false
# if not pressed yet
if !@pressed[key]
# pressed and triggered
@pressed[key] = true
@triggered[key] = true
@repeatedKey = key
@repeatedCount = 0
else
# not triggered anymore
@triggered[key] = false
end
# update of repeat counter
if key == @repeatedKey
@repeatedCount < 17 ? @repeatedCount += 1 : @repeatedCount = 15
end
# not released yet
elsif !@released[key]
# if still pressed
if @pressed[key]
# not triggered, pressed or repeated, but released
@triggered[key] = false
@pressed[key] = false
@released[key] = true
if key == @repeatedKey
@repeatedKey = -1
@repeatedCount = 0
end
end
else
# not released anymore
@released[key] = false
end
key += 1}
end
#----------------------------------------------------------------------------
# dir4
# 4 direction check.
#----------------------------------------------------------------------------
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 0
end
#----------------------------------------------------------------------------
# dir8
# 8 direction check.
#----------------------------------------------------------------------------
def self.dir8
down = self.press?(DOWN)
left = self.press?(LEFT)
return 1 if down && left
right = self.press?(RIGHT)
return 3 if down && right
up = self.press?(UP)
return 7 if up && left
return 9 if up && right
return 2 if down
return 4 if left
return 6 if right
return 8 if up
return 0
end
#----------------------------------------------------------------------------
# trigger?
# Test if key was triggered once.
#----------------------------------------------------------------------------
def self.trigger?(keys)
keys = [keys] unless keys.is_a?(Array)
return keys.any? {|key| @triggered[key]}
end
#----------------------------------------------------------------------------
# press?
# Test if key is being pressed.
#----------------------------------------------------------------------------
def self.press?(keys)
keys = [keys] unless keys.is_a?(Array)
return keys.any? {|key| @pressed[key]}
end
#----------------------------------------------------------------------------
# repeat?
# Test if key is being pressed for repeating.
#----------------------------------------------------------------------------
def self.repeat?(keys)
keys = [keys] unless keys.is_a?(Array)
return (@repeatedKey >= 0 && keys.include?(@repeatedKey) &&
(@repeatedCount == 1 || @repeatedCount == 16))
end
#----------------------------------------------------------------------------
# release?
# Test if key was released.
#----------------------------------------------------------------------------
def self.release?(keys)
keys = [keys] unless keys.is_a?(Array)
return keys.any? {|key| @released[key]}
end
#----------------------------------------------------------------------------
# get_character
# vk - virtual key
# Gets the character from keyboard input using the input locale identifier
# (formerly called keyboard layout handles).
#----------------------------------------------------------------------------
def self.get_character(vk)
# get corresponding character from virtual key
c = MapVirtualKeyEx.call(vk, 2, @language_layout)
# stop if character is non-printable and not a dead key
return '' if c < 32 && (c & DEAD_KEY_MASK != DEAD_KEY_MASK)
# get scan code
vsc = MapVirtualKeyEx.call(vk, 0, @language_layout)
# result string is never longer than 4 bytes (Unicode)
result = "\0" * 4
# get input string from Win32 API
length = ToUnicodeEx.call(vk, vsc, @state, result, 4, 0, @language_layout)
return (length == 0 ? '' : result)
end
#----------------------------------------------------------------------------
# get_input_string
# Gets the string that was entered using the keyboard over the input locale
# identifier (formerly called keyboard layout handles).
#----------------------------------------------------------------------------
def self.get_input_string
result = ''
# check every key
ALL_KEYS.each {|key|
# if repeated
if self.repeat?(key)
# get character from keyboard state
c = self.get_character(key)
# add character if there is a character
result += c if c != ''
end}
# empty if result is empty
return '' if result == ''
# convert string from Unicode to UTF-8
return self.unicode_to_utf8(result)
end
#----------------------------------------------------------------------------
# unicode_to_utf8
# string - string in Unicode format
# Converts a string from Unicode format to UTF-8 format as RGSS does not
# support Unicode.
#----------------------------------------------------------------------------
def self.unicode_to_utf8(string)
result = ''
# L* format means a bunch of 4-byte wide-chars
string.unpack('L*').each {|c|
# characters under 0x80 are 1 byte characters
if c < 0x0080
result += c.chr
# other characters under 0x800 are 2 byte characters
elsif c < 0x0800
result += (0xC0 | (c >> 6)).chr
result += (0x80 | (c & 0x3F)).chr
# other characters under 0x10000 are 3 byte characters
elsif c < 0x10000
result += (0xE0 | (c >> 12)).chr
result += (0x80 | ((c >> 6) & 0x3F)).chr
result += (0x80 | (c & 0x3F)).chr
# other characters under 0x200000 are 4 byte characters
elsif c < 0x200000
result += (0xF0 | (c >> 18)).chr
result += (0x80 | ((c >> 12) & 0x3F)).chr
result += (0x80 | ((c >> 6) & 0x3F)).chr
result += (0x80 | (c & 0x3F)).chr
# other characters under 0x4000000 are 5 byte characters
elsif c < 0x4000000
result += (0xF8 | (c >> 24)).chr
result += (0x80 | ((c >> 18) & 0x3F)).chr
result += (0x80 | ((c >> 12) & 0x3F)).chr
result += (0x80 | ((c >> 6) & 0x3F)).chr
result += (0x80 | (c & 0x3F)).chr
# other characters under 0x80000000 are 6 byte characters
elsif c < 0x80000000
result += (0xFC | (c >> 30)).chr
result += (0x80 | ((c >> 24) & 0x3F)).chr
result += (0x80 | ((c >> 18) & 0x3F)).chr
result += (0x80 | ((c >> 12) & 0x3F)).chr
result += (0x80 | ((c >> 6) & 0x3F)).chr
result += (0x80 | (c & 0x3F)).chr
end}
return result
end

end

end

 

Part 2

 

 

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Mouse Controller by Blizzard
# Version: 2.0b
# Type: Custom Input System
# Date: 9.10.2009
# Date v2.0b: 22.7.2010
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#  
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# # 
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# # 
# #  You are free:
# # 
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# # 
# #  Under the following conditions:
# # 
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# # 
# #  Noncommercial. You may not use this work for commercial purposes.
# # 
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# # 
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# # 
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# # 
# #  - Nothing in this license impairs or restricts the author's moral rights.
# # 
# #----------------------------------------------------------------------------
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# Compatibility:
#
#   90% compatible with SDK v1.x. 80% compatible with SDK v2.x. May cause
#   incompatibility issues with other custom input Systems. Works with "Custom
#   Game Controls" from Tons of Add-ons and Blizz-ABS's custom controls.
#   This script is not meant to be used as a standalone but rather in
#   combination with special menus that are properly adapted to support a mouse
#   controller system.
#  
#  
# Features:
#
#   - fully automated mouse control in game
#   - can be enhanced with "Custom Game Controls" from Tons of Add-ons
#   - can be enhanced with "Blizz-ABS Controls"
#   - can be enhanced with "RMX-OS"
#
# new in 2.0b:
#
#   - added option to hide Windows' cursor
#   - added possibility to hide and show the ingame cursor during the game
#   - added possibility to change the cursor icon
#   - added several new options
#   - optimized
#
#
# Instructions:
#
# - Explanation:
#
#   This script can work as a stand-alone for window option selections. To be
#   able to use the mouse buttons, you need a custom Input module. The
#   supported systems are "Custom Game Controls" from Tons of Add-ons,
#   Blizz-ABS Custom Controls and RMX-OS Custom Controls. This script will
#   automatically detect and apply the custom input modules' configuration
#   which is optional.
#  
# - Configuration:
#
#   MOUSE_ICON          - the default filename of the icon located in the
#                         Graphics/Pictures folder
#   APPLY_BORDERS       - defines whether the ingame cursor can go beyond the
#                         game window borders
#   WINDOW_WIDTH        - defines the window width, required only when using
#                         APPLY_BORDER
#   WINDOW_HEIGHT       - defines the window height, required only when using
#                         APPLY_BORDER
#   HIDE_WINDOWS_CURSOR - hides the Windows Cursor on the window by default
#   AUTO_CONFIGURE      - when using "Custom Game Controls" from Tons of
#                         Add-ons, Blizz-ABS or RMX-OS, this option will
#                         automatically add the left mouse button as
#                         confirmation button
#  
# - Script Calls:
#  
#   You can use a few script calls to manipulate the cursor. Keep in mind that
#   these changes are not being saved with the save file.
#  
#   To hide the ingame Mouse Cursor, use following call.
#  
#     $mouse.hide
#  
#   To show the ingame Mouse Cursor, use following call.
#  
#     $mouse.show
#  
#   To change the cursor image, use following call. Make sure your image is
#  
#     $mouse.set_cursor('IMAGE_NAME')
#  
#  
# Additional Information:
#  
#   Even though there is an API call to determine the size of the window, API
#   calls are CPU expensive so the values for the window size need to be
#   configured manually in this script.
#  
#
# If you find any bugs, please report them here:
# http://forum.chaos-project.com
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

$mouse_controller = 2.0

#===============================================================================
# Mouse
#===============================================================================

class Mouse
 
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# START Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  MOUSE_ICON = 'arrow1'
  AUTO_CONFIGURE = false
  APPLY_BORDERS = true
  WINDOW_WIDTH = 640
  WINDOW_HEIGHT = 480
  HIDE_WINDOWS_CURSOR = true
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# END Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 
  if HIDE_WINDOWS_CURSOR
    Win32API.new('user32', 'ShowCursor', 'i', 'i').call(0)
  end
 
  SCREEN_TO_CLIENT = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
  READ_INI = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
  FIND_WINDOW = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
  CURSOR_POSITION = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
 
  def initialize
    @cursor = Sprite.new
    @cursor.z = 1000000
    self.set_cursor(MOUSE_ICON)
    update
  end
 
  def update
    @cursor.x, @cursor.y = self.position
  end
 
  def x
    return @cursor.x
  end
 
  def y
    return @cursor.y
  end
 
  def position
    x, y = self.get_client_position
    if APPLY_BORDERS
      if x < 0
        x = 0
      elsif x >= WINDOW_WIDTH
        x = WINDOW_WIDTH - 1
      end
      if y < 0
        y = 0
      elsif y >= WINDOW_HEIGHT
        y = WINDOW_HEIGHT - 1
      end
    end
    return x, y
  end
 
  def get_client_position
    pos = [0, 0].pack('ll')
    CURSOR_POSITION.call(pos)
    SCREEN_TO_CLIENT.call(WINDOW, pos)
    return pos.unpack('ll')
  end
 
  def set_cursor(image)
    @cursor.bitmap = RPG::Cache.picture(image)
  end
 
  def show
    @cursor.visible = true
  end
 
  def hide
    @cursor.visible = false
  end
 
  def self.find_window
    game_name = "\0" * 256
    READ_INI.call('Game', 'Title', '', game_name, 255, '.\\Game.ini')
    game_name.delete!("\0")
    return FIND_WINDOW.call('RGSS Player', game_name)
  end
 
  WINDOW = self.find_window
 
end

$mouse = Mouse.new

#==============================================================================
# module Input
#==============================================================================

module Input
 
  class << Input
    alias update_mousecontroller_later update
  end
 
  def self.update
    $mouse.update
    update_mousecontroller_later
  end
 
  if Mouse::AUTO_CONFIGURE
    if $BlizzABS
      C.push(Input::Key['Mouse Left']) if !C.include?(Input::Key['Mouse Left'])
      if !Attack.include?(Input::Key['Mouse Right'])
        Attack.push(Input::Key['Mouse Right'])
      end
    elsif $tons_version != nil && $tons_version >= 6.4 &&
        TONS_OF_ADDONS::CUSTOM_CONTROLS || defined?(RMXOS)
      C.push(Input::Key['Mouse Left']) if !C.include?(Input::Key['Mouse Left'])
    end
  end
 
end

#===============================================================================
# Rect
#===============================================================================

class Rect
 
  def covers?(x, y)
    return !(x < self.x || x >= self.x + self.width ||
        y < self.y || y >= self.y + self.height)
  end
 
end

#===============================================================================
# Sprite
#===============================================================================

class Sprite
 
  def mouse_in_area?
    return false if self.bitmap == nil
    return ($mouse.x >= self.x && $mouse.x < self.x + self.src_rect.width &&
        $mouse.y >= self.y && $mouse.y < self.y + self.src_rect.height)
  end
 
end

#===============================================================================
# Window_Base
#===============================================================================

class Window_Base
 
  def mouse_in_area?
    return ($mouse.x >= self.x && $mouse.x < self.x + self.width &&
        $mouse.y >= self.y && $mouse.y < self.y + self.height)
  end
 
  def mouse_in_inner_area?
    return ($mouse.x >= self.x + 16 && $mouse.x < self.x + self.width - 16 &&
        $mouse.y >= self.y + 16 && $mouse.y < self.y + self.height - 16)
  end
 
end

#===============================================================================
# Window_Selectable
#===============================================================================

class Window_Selectable
 
  alias contents_is_mousecontroller_later contents=
  def contents=(bitmap)
    contents_is_mousecontroller_later(bitmap)
    begin
      update_selections
      update_mouse if self.active
    rescue
    end
  end
 
  alias index_is_mousecontroller_later index=
  def index=(value)
    index_is_mousecontroller_later(value)
    update_selections
  end
 
  alias active_is_mousecontroller_later active=
  def active=(value)
    active_is_mousecontroller_later(value)
    update_cursor_rect
  end
 
  def update_selections
    @selections = []
    index, ox, oy = self.index, self.ox, self.oy
    (0...@item_max).each {|i|
        @index = i
        update_cursor_rect
        rect = self.cursor_rect.clone
        rect.x += self.ox
        rect.y += self.oy
        @selections.push(rect)}
    @index, self.ox, self.oy = index, ox, oy
    self.cursor_rect.empty
  end
 
  alias update_mousecontroller_later update
  def update
    update_mouse if self.active
    update_mousecontroller_later
  end
 
  def update_mouse
    if self.mouse_in_inner_area?
      update_mouse_selection
      return
    end
    self.index = -1
    if self.contents != nil && @selections.size > 0 && self.mouse_in_area?
      update_mouse_scrolling
    end
  end
 
  def update_mouse_selection
    update_selections if @selections.size != @item_max
    @selections.each_index {|i|
        if @selections.covers?($mouse.x - self.x - 16 + self.ox,
            $mouse.y - self.y - 16 + self.oy)
          self.index = i if self.index != i
          return
        end}
    self.index = -1
  end
 
  def update_mouse_scrolling
    if Input.repeat?(Input::C)
      if $mouse.x < self.x + 16
        if self.ox > 0
          $game_system.se_play($data_system.cursor_se)
          self.ox -= @selections[0].width
          self.ox = 0 if self.ox < 0
        end
      elsif $mouse.x >= self.x + self.width - 16
        max_ox = self.contents.width - self.width + 32
        if self.ox <= max_ox
          $game_system.se_play($data_system.cursor_se)
          self.ox += @selections[0].width
          self.ox = max_ox if self.ox >= max_ox
        end
      elsif $mouse.y < self.y + 16
        if self.oy > 0
          $game_system.se_play($data_system.cursor_se)
          self.oy -= @selections[0].height
          self.oy = 0 if self.oy < 0
        end
      elsif $mouse.y >= self.y + self.height - 16
        max_oy = self.contents.height - self.height + 32
        if self.oy <= max_oy
          $game_system.se_play($data_system.cursor_se)
          self.oy += @selections[0].height
          self.oy = max_oy if self.oy >= max_oy
        end
      end
    end
  end
 
end

 


Part 3

 

 

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Lagless Path Finder by Blizzard
# Version: 1.01
# Type: Pathfinding System
# Date: 9.2.2013
# Date v1.01: 11.4.2013
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#  
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# # 
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# # 
# #  You are free:
# # 
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# # 
# #  Under the following conditions:
# # 
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# # 
# #  Noncommercial. You may not use this work for commercial purposes.
# # 
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# # 
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# # 
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# # 
# #  - Nothing in this license impairs or restricts the author's moral rights.
# # 
# #----------------------------------------------------------------------------
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# IMPORTANT NOTE:
#
#   This Path Finder is a derived version of Blizz-ABS's original Path Finder.
#   If you are using Blizz-ABS, please remove this script. Blizz-ABS has a
#   Path Finder already built-in.
#
#
# Compatibility:
#
#   99% compatible with SDK v1.x. 90% compatible with SDK v2.x. May cause
#   incompatibility issues with exotic map systems.
#
#
# Features:
#
#   - calculates path from point A to point B on the map
#   - allows immediate calculation as well as path calculation requests that
#     are done over the course of a few frames in order to reduce lag
#   - supports dynamic calculation that is done every step to ensure the
#     character reaches its targets
#   - can assign other characters as targets so dynamic calculation with a
#     moving will cause the character to find the target regardless of his
#     changed position
#
# new in v1.01:
#   - fixed attempted optimizations to work properly
#
#
# Instructions:
#  
# - Explanation:
#  
#   This script will allow your characters to walk from point A to point B,
#   navigating by themselves, finding the shortest path and all that without
#   you having to manually specify their moving route. They can also navigate
#   through dynamically changing environments or track a dynamically moving
#   target.
#
# - Configuration:
#
#   MAX_NODES_PER_FRAME - maximum number of node calculation per frame when
#                         using path requests instead of immediate calculations
#   DIRECTIONS_8_WAY    - if set to true, it will smooth out corner movement
#                         and use a diagonal movement step wherever possible
#                         (this does NOT mean that the path finder will do
#                         8-directional path finding!)
#
# - Script calls:
#
#   This path finder offers you several script calls in order to designate path
#   finding to characters on the map. Following script calls are at your
#   disposal:
#  
#     PathFinder.find(C_ID, X, Y)
#     PathFinder.find(C_ID, X, Y, RANGE)
#     PathFinder.find(C_ID, TARGET)
#     PathFinder.find(C_ID, TARGET, RANGE)
#     PathFinder.request(C_ID, X, Y)
#     PathFinder.request(C_ID, X, Y, RANGE)
#     PathFinder.request(C_ID, TARGET)
#     PathFinder.request(C_ID, TARGET, RANGE)
#     PathFinder.dyn_find(C_ID, X, Y)
#     PathFinder.dyn_find(C_ID, X, Y, RANGE)
#     PathFinder.dyn_find(C_ID, TARGET)
#     PathFinder.dyn_find(C_ID, TARGET, RANGE)
#     PathFinder.dyn_request(C_ID, X, Y)
#     PathFinder.dyn_request(C_ID, X, Y, RANGE)
#     PathFinder.dyn_request(C_ID, TARGET)
#     PathFinder.dyn_request(C_ID, TARGET, RANGE)
#
#   C_ID   - either an event ID, 0 for the player character or an actual
#            character (e.g. $game_map.events[iD])
#   X      - X target coordinate
#   Y      - Y target coordinate
#   RANGE  - range within which the target should be located (greater than 0)
#   TARGET - an actual target character
#  
#   This is how the 4 different script calls behave:
#  
#   - The "find" variants always calculate the path immediately.
#   - The "request" variants always request a path calculation to be done over
#     the course of several frames in order to avoid lag. Requesting paths for
#     multiple characters will cause the calculation to take longer as each
#     frame only a certain number of nodes is calculated (can be configured).
#     So if there are more characters requesting a path, naturally each one
#     will consume a part of the allowed node calculations every frame.
#   - The "dyn" variants (dynamic) will recalculate/request a calculation every
#     step in order to keep a path up to date with an ever-changing
#     environment. You won't need to use these calls if there are no moving
#     events on the map or if there are no environmental passability changes.
#   - When using a "dyn" variant, if actual coordinates (X, Y) are used, the
#     character will find its path to these fixed coordinates. If an actual
#     target character is being used, the path finder will track the character
#     instead of fixed coordinates. If the character changes its position, the
#     path calculation will attempt to find a path to the new position of the
#     target.
#   - Using "dyn_find" a lot, with many characters at the same time and/or for
#     long paths may cause performance issue and lag. Use it wisely.
#   - Using "dyn_request" is much more performance-friendly, but it will also
#     cause characters to "stop and think". This can also cause problems in a
#     constantly changing environment as the environment may change during the
#     few frames while the calculation is being done. Use it wisely.
#  
#   In order to cancel dynamic path calculation for a character, use following
#   script call:
#  
#     character.clear_path_target
#  
#   Example:
#    
#     $game_map.events[23].clear_path_target
#  
#   In order to check if a character has a dynamic path calculation for a
#   target, use following script call:
#  
#     character.has_path_target?
#  
#   Example:
#    
#     if $game_map.events[23].has_path_target?
#  
#
# Notes:
#
#   - This path finder is an implementation fo the A* Search Algorithm.
#   - The PathFinder module is being updated during the call of $game_system.update.
#     Keep this in mind if you are using specific exotic scripts.
#
#
# If you find any bugs, please report them here:
# http://forum.chaos-project.com
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# START Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

module BlizzCFG
 
  MAX_NODES_PER_FRAME = 100
  DIRECTIONS_8_WAY = false
 
end

#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# END Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

$lagless_path_finder = 1.01

#==============================================================================
# module PathFinder
#==============================================================================

module Math
 
  def self.hypot_squared(x, y)
    return (x * x + y * y)
  end
 
end

#==============================================================================
# module PathFinder
#==============================================================================

module PathFinder
 
  PATH_DIRS = [[0, 1, 2], [-1, 0, 4], [1, 0, 6], [0, -1, 8]]
  DIR_DOWN_LEFT = [2, 4]
  DIR_LEFT_DOWN = [4, 2]
  DIR_DOWN_RIGHT = [2, 6]
  DIR_RIGHT_DOWN = [6, 2]
  DIR_LEFT_UP = [4, 8]
  DIR_UP_LEFT = [8, 4]
  DIR_RIGHT_UP = [6, 8]
  DIR_UP_RIGHT = [8, 6]
  DIR_OFFSETS = [[0, 0], [-1, 1], [0, 1], [1, 1], [-1, 0], [0, 0], [1, 0],
                [-1, -1], [0, -1], [1, -1]]
 
  @requests = {}
 
  def self.clear
    @requests = {}
  end
 
  def self.find(char, x, y = nil, range = 0)
    char, x, y, range = self.check_args(char, x, y, range)
    self._find(char, x, y, range, false)
    return true
  end
 
  def self.dyn_find(char, x, y = nil, range = 0)
    tx, ty = x, y
    char, x, y, range = self.check_args(char, x, y, range)
    self._find(char, x, y, range, true)
    char.set_path_target(tx, ty, range, true)
    return true
  end
 
  def self.request(char, x, y = nil, range = 0)
    char, x, y, range = self.check_args(char, x, y, range)
    self._request(char, x, y, range, false)
    return true
  end
 
  def self.dyn_request(char, x, y = nil, range = 0)
    tx, ty = x, y
    char, x, y, range = self.check_args(char, x, y, range)
    self._request(char, x, y, range, true)
    char.set_path_target(tx, ty, range, false)
    return true
  end
 
  def self.check_args(char, x, y, range)
    if x.is_a?(Game_Character)
      range = (y != nil ? y : 0)
      y = x.y
      x = x.x
    end
    range = 0 if range < 0
    if char.is_a?(Numeric)
      char = (char > 0 ? $game_map.events[char] : $game_player)
    end
    p "Warning! Character to move does not exist!" if $DEBUG && char == nil
    return [char, x, y, range]
  end
 
  def self._find(char, x, y, range, dynamic)
    @requests[char] = PathRequest.new(char.x, char.y, x, y, range, dynamic)
    result = nil
    result = self.calc_node(char) while result == nil
    @requests.delete(char)
    if $DEBUG && result == []
      p "Warning! Path Finder could not find path for character at (#{x},#{y})!"
    end
    char.set_found_path(result)
  end
 
  def self._request(char, x, y, range, dynamic)
    if @requests[char] == nil
      @requests[char] = PathRequest.new(char.x, char.y, x, y, range, dynamic)
    end
  end
 
  def self.update
    @requests = {} if @requests == nil
    characters = @requests.keys
    count = BlizzCFG::MAX_NODES_PER_FRAME
    while characters.size > 0 && count > 0
      char = characters.shift
      result = self.calc_node(char)
      result != nil ? char.set_found_path(result) : characters.push(char)
      count -= 1
    end
  end

  def self.calc_node(char)
    request = @requests[char]
    if request.open.size == 0
      @requests.delete(char)
      return []
    end
    found = false
    key = request.open.keys.min {|a, b|
        a[2] > b[2] ? 1 : (a[2] < b[2] ? -1 :
        (Math.hypot_squared(a[0] - request.tx, a[1] - request.ty) <=>
        Math.hypot_squared(b[0] - request.tx, b[1] - request.ty)))}
    request.closed[key[0], key[1]] = request.open[key]
    request.open.delete(key)
    kx, ky = 0, 0
    passable = false
    passable_checked = false
    PATH_DIRS.each {|dir|
        kx, ky = key[0] + dir[0], key[1] + dir[1]
        passable = false
        passable_checked = false
        if (kx - request.tx).abs + (ky - request.ty).abs <= request.range
          passable = char.passable?(key[0], key[1], dir[2])
          passable_checked = true
          if passable
            request.closed[kx, ky] = dir[2]
            found = true
            break
          end
        end
        if request.closed[kx, ky] == 0
          passable = char.passable?(key[0], key[1], dir[2]) if !passable_checked
          if passable
            request.open[[kx, ky, key[2] + 1]] = dir[2]
          end
        end}
    return nil if !found
    result = request.backtrack(kx, ky)
    @requests.delete(char)
    return result
  end
 
end

#==============================================================================
# PathRequest
#==============================================================================

class PathRequest
 
  attr_reader :open
  attr_reader :closed
  attr_reader :sx
  attr_reader :sy
  attr_reader :tx
  attr_reader :ty
  attr_reader :range
  attr_reader :dynamic
 
  def initialize(ox, oy, tx, ty, range, dynamic = false)
    @sx, @sy, @tx, @ty, @range, @dynamic = ox, oy, tx, ty, range, dynamic
    @open = {[@sx, @sy, 0] => -1}
    @closed = Table.new($game_map.width, $game_map.height)
  end
 
  def backtrack(tx, ty)
    cx, cy, x, y, result = tx, ty, 0, 0, []
    loop do
      cx, cy = cx - x, cy - y
      break if cx == @sx && cy == @sy
      result.unshift(@closed[cx, cy])
      x, y = PathFinder::DIR_OFFSETS[@closed[cx, cy]]
    end
    return self.modify_8_way(result)
  end
 
  def modify_8_way(result)
    if BlizzCFG::DIRECTIONS_8_WAY
      result.each_index {|i|
          if result != nil && result[i + 1] != nil
            case [result, result[i + 1]]
            when PathFinder::DIR_DOWN_LEFT, PathFinder::DIR_LEFT_DOWN
              result, result[i + 1] = 1, nil
            when PathFinder::DIR_DOWN_RIGHT, PathFinder::DIR_RIGHT_DOWN
              result, result[i + 1] = 3, nil
            when PathFinder::DIR_LEFT_UP, PathFinder::DIR_UP_LEFT
              result, result[i + 1] = 7, nil
            when PathFinder::DIR_RIGHT_UP, PathFinder::DIR_UP_RIGHT
              result, result[i + 1] = 9, nil
            end
          end}
      result.compact!
    end
    return result
  end
 
end

#==============================================================================
# Game_System
#==============================================================================

class Game_System
 
  alias update_lagless_path_finder_later update
  def update
    PathFinder.update
    update_lagless_path_finder_later
  end
 
end

#==============================================================================
# Game_Map
#==============================================================================

class Game_Map
 
  alias setup_lagless_path_finder_later setup
  def setup(map_id)
    PathFinder.clear
    setup_lagless_path_finder_later(map_id)
  end
 
end

#==============================================================================
# Game_Character
#==============================================================================

class Game_Character
 
  def set_path_target(x, y, range, immediate)
    @path_x, @path_y, @path_range, @path_immediate = x, y, range, immediate
  end
 
  def clear_path_target
    @path_x, @path_y, @path_range, @path_immediate = nil, nil, nil, nil
  end
 
  def has_path_target?
    return (@path_x != nil)
  end
 
  def set_found_path(path)
    return if path.size == 0
    route = RPG::MoveRoute.new
    route.repeat = false
    # each move command code equals direction / 2
    path.reverse.each {|dir| route.list.unshift(RPG::MoveCommand.new(dir / 2))}
    self.force_move_route(route)
  end
 
  alias update_move_lagless_path_finder_later update_move
  def update_move
    update_move_lagless_path_finder_later
    return if self.moving? || !self.has_path_target?
    x, y = @path_x, @path_y
    x, y = @path_x.x, @path_x.y if @path_x.is_a?(Game_Character)
    if @x == x && @y == y
      #p @x, x, @y, y
      #p @path_x
      self.clear_path_target
    elsif @path_immediate
      PathFinder.dyn_find(self, @path_x, @path_y, @path_range)
    else
      PathFinder.dyn_request(self, @path_x, @path_y, @path_range)
    end
  end
 
end

 

 

 

Mouse works for left/right click, but I tried and failed to connect it with the pathfinder, and I'm not sure how to set it up to hide when the keyboard is in use.

 
 

If a scripter person has the time/is willing (and if what I want is possible).  I'd appreciate either a modification of one of the scripts, or a new script with just the functions I need.  Thanks Muchlies!

 

~Phionabrie

Share this post


Link to post
Share on other sites

Forget about mouse support with RPG Maker. The scripts you're using are dirty workarounds and you'll eventually run into a series of issues (as you already have by the way) that are a pain in the ass to solve. Maybe there's a good samaritan out there who will address your request but be aware that you're dealing with stuff that's not supposed to happen in the first place.

Share this post


Link to post
Share on other sites

Decided to use events instead of terrain tags for floor stuff because it works better for my game, which means the only thing I need different from my mouse script is how to make it hide.  Anyone familiar enough with the mouse script (first set) who might be able to tell me how to do that?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...