GamePad and Blizz-ABS

Started by R5GAMER, March 28, 2015, 10:08:08 pm

Previous topic - Next topic

R5GAMER

Hello!

I found a script which allows to use the gamepad but by trying him(it) on my project
I have the impression that the code doesn't works certainly because the system of Blizz ABS
takes the priority but I shall like that the player can have the possibility of playing either on the keyboard or on the gamepad:)


#≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
# ** Glitchfinder's Gamepad Input Module          [RPG Maker XP] [RPG Maker VX]
#    Version 1.00
#------------------------------------------------------------------------------
#  This script helps scripters to use an XInput-compatible gamepad with their
#  games.
#==============================================================================
# * Version History
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   Version 1.00 ------------------------------------------------- (2010-08-20)
#     - Initial version
#     - Author: Glitchfinder
#==============================================================================
# * Instructions
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  Place this script above Main, and below the default scripts. (I realize this
#  is obvious to most, but some people don't get it.)
#
#  You must also place Input.dll into the game's main project folder, since
#  this script needs it to access the XInput functions it uses.
#
#  This module is automatically updated by the default Input module, which
#  means that the only time you need to call the update method is in a scene
#  that does not update the default Input module.
#
#  This module does not break the functionality of the default Input module.
#
#  To use this module to check a gamepad button, simply use one of the four
#  methods (press?(button[, index]), trigger?(button[, index]),
#  repeat?(button[, index]), or release?(button[, index])), where button is the
#  constant of the button you want to check. Button may also be used as
#  Gamepad::BUTTONNAME. For a list of acceptable button names, look below the
#  header, in the section that declares button constants. The methods use index
#  to determine which gamepad to check. If no index is given, they will check
#  gamepad 0. Index is a value from 0 to 3.
#
#  To use this module to check a gamepad trigger or joystick, simply use one of
#  the four methods (axis_press?(axis[, index]), axis_trigger?(axis[, index]),
#  axis_repeat?(axis[, index]), or axis_release?(axis[, index])), where axis is
#  the constant of the axis you want to check. Axis may also be used as
#  Gamepad::AXISNAME. For a list of acceptable axis names, look below the
#  header, in the section that declares axis constants. The methods use index
#  to determine which gamepad to check. If no index is given, they will check
#  gamepad 0. Index is a value from 0 to 3.
#
#  To use this module to check the value on a gamepad triger or joystick axis,
#  use one of the two methods (axis_value(axis[, index]),
#  real_axis_value(axis[, index])), where axis is the constant of the axis you
#  want to check. Axis may also be used as Gamepad::AXISNAME. For a list of
#  acceptable axis names, look below the header, in the section that declares
#  axis constants. The methods use index to determine which gamepad to check.
#  If no index is given, they will check gamepad 0. Index is a value from 0 to
#  3. The difference between these two methods is that real_axis_value() will
#  always return the current value, while axis_value will return 0 if the
#  axis falls within its dead zone.
#
#  To use this module to cause a gamepad to "rumble", or vibrate, use the
#  vibrate() method. Details for that are below, in the method list.
#==============================================================================
# * Method List
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  Gamepad.update
#    Updates gamepad input. Calls to this method are not necessary unless the
#    default Input module is not being updated.
#
#  Gamepad.press?(button[, index])
#    Determines whether the gamepad button determined by button is currently
#    being pressed. If the button is being pressed, returns true. If not,
#    returns false. Uses index to determine the gamepad to check, from 0 to 3.
#    The index defaults to 0.
#
#  Gamepad.trigger?(button[, index])
#    Determines whether the gamepad button determined by button is being
#    pressed again. "Pressed again" is seen as time having passed between the
#    button being not pressed and being pressed. If the button is being
#    pressed, returns true. If not, returns false. Uses index to determine the
#    gamepad to check, from 0 to 3. The index defaults to 0.
#
#  Gamepad.repeat?(button[, index])
#    Determines whether the gamepad button determined by button is being
#    pressed again. Unlike trigger?(), this takes into account the repeat input
#    of a button being held down continuously. If the button is being pressed,
#    returns true. If not, returns false. Uses index to determine the gamepad
#    to check, from 0 to 3. The index defaults to 0.
#
#  Gamepad.release?(button[, index])
#    Determines whether the gamepad button determined by button has just been
#    released. If the button has been released, returns true. If not, returns
#    false. Uses index to determine the gamepad to check, from 0 to 3. The
#    index defaults to 0.
#
#  Gamepad.axis_press?(axis[, index])
#    Determines whether the gamepad axis determined by axis is currently being
#    pressed. If the button is being pressed, returns true. If not, returns
#    false. Uses index to determine the gamepad to check, from 0 to 3. The
#    index defaults to 0.
#
#  Gamepad.axis_trigger?(axis[, index])
#    Determines whether the gamepad axis determined by axis is being pressed
#    again. "Pressed again" is seen as time having passed between the button
#    being not pressed and being pressed. If the button is being pressed,
#    returns true. If not, returns false. Uses index to determine the gamepad
#    to check, from 0 to 3. The index defaults to 0.
#
#  Gamepad.axis_repeat?(axis[, index])
#    Determines whether the gamepad axis determined by axis is being pressed
#    again. Unlike trigger?(), this takes into account the repeat input of a
#    button being held down continuously. If the button is being pressed,
#    returns true. If not, returns false. Uses index to determine the gamepad
#    to check, from 0 to 3. The index defaults to 0.
#
#  Gamepad.axis_release?(axis[, index])
#    Determines whether the gamepad axis determined by axis has just been
#    released. If the button has been released, returns true. If not, returns
#    false. Uses index to determine the gamepad to check, from 0 to 3. The
#    index defaults to 0.
#
#  Gamepad.axis_value(axis[, index])
#    Returns the current value of the gamepad axis determined by axis. The
#    gamepad checked is determined by index, from 0 to 3. The value for index
#    is 0 if none is provided. If the value for the axis falls within the dead
#    zone specified for that axis, then axis_value() will return 0.
#
#  Gamepad.real_axis_value(axis[, index])
#    Returns the current value of the gamepad axis determined by axis. The
#    gamepad checked is determined by index, from 0 to 3. The value for index
#    is 0 if none is provided. This method ignores the dead zone for the axis,
#    and will always return the current value.
#
#  Gamepad.vibrate(left_motor, right_motor, frames[, index])
#    Causes the motors to vibrate for the number of frames specified. The
#    values for left_motor and right_motor range from 0 to 65535, though the
#    motors themselves may differ in function, as they do in an Xbox 360
#    controller, resulting in a different "feel" depending on the motor you
#    select. Uses index to determine the gamepad to check, from 0 to 3. The
#    index defaults to 0.
#==============================================================================
# * Known Issues
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  This script currently has trouble with the vibrate method, which does not
#  allow you to set one motor independently of the other. This part of a
#  planned update sometime in the future.
#==============================================================================
# * Glitchfinder's Advice
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  This script is meant for people with a medium or advanced level of scripting
#  knowledge and ability, or for those using scripts that require this module.
#==============================================================================
# * Contact
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  Glitchfinder, the author of this script, may be contacted through his
#  website, found at http://www.glitchkey.com
#
#  You may also find Glitchfinder at http://www.hbgames.org
#==============================================================================
# * Usage
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  This script may be used with the following terms and conditions:
#
#    1. This script is free to use in any noncommercial project. If you wish to
#       use this script in a commercial (paid) project, please contact
#       Glitchfinder at his website.
#    2. This script may only be hosted at the following domains:
#         http://www.glitchkey.com
#         http://www.hbgames.org
#    3. If you wish to host this script elsewhere, please contact Glitchfinder.
#    4. If you wish to translate this script, please contact Glitchfinder. He
#       will need the web address that you plan to host the script at, as well
#       as the language this script is being translated to.
#    5. This header must remain intact at all times.
#    6. Glitchfinder remains the sole owner of this code. He may modify or
#       revoke this license at any time, for any reason.
#    7. Any code derived from code within this script is owned by Glitchfinder,
#       and you must have his permission to publish, host, or distribute his
#       code.
#    8. This license applies to all code derived from the code within this
#       script.
#    9. If you use this script within your project, you must include visible
#       credit to Glitchfinder, within reason.
#≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

#==============================================================================
# ** Gamepad
#------------------------------------------------------------------------------
#  This module performs gamepad input processing
#==============================================================================

module Gamepad
  #--------------------------------------------------------------------------
  # * Declare Button Constants
  #--------------------------------------------------------------------------
  DPAD_UP        = 0  # Directional pad up button
  DPAD_DOWN      = 1  # Directional pad down button
  DPAD_LEFT      = 2  # Directional pad left button
  DPAD_RIGHT     = 3  # Directional pad right button
  START          = 4  # Start button
  BACK           = 5  # Back button
  LEFT_THUMB     = 6  # Left thumb button
  RIGHT_THUMB    = 7  # Right thumb button
  LEFT_SHOULDER  = 8  # Left shoulder button
  RIGHT_SHOULDER = 9  # Right shoulder button
  A              = 10 # A button
  B              = 11 # B button
  X              = 12 # X Button
  Y              = 13 # Y Button
  #--------------------------------------------------------------------------
  # * Declare Axis Constants
  #--------------------------------------------------------------------------
  LEFT_TRIGGER   = 0  # Left trigger axis       (0 to 255)
  RIGHT_TRIGGER  = 1  # Right trigger axis      (0 to 255)
  LX             = 2  # Left thumbstick x axis  (-32768 to 32767)
  LY             = 3  # Left thumbstick y axis  (-32768 to 32767)
  RX             = 4  # Right thumbstick x axis (-32768 to 32767)
  RY             = 5  # Right thumbstick y axis (-32768 to 32767)
  #--------------------------------------------------------------------------
  # * Declare Module Variables
  #--------------------------------------------------------------------------
  begin
    # Declare API calls
    @gamepadGetCapabilities = Win32API.new('Input.dll',
      'GamepadGetCapabilities', 'IIP', 'I')
    @gamepadGetDSoundAudioDeviceGuids = Win32API.new('Input.dll',
      'GamepadGetDSoundAudioDeviceGuids', 'IPP', 'I')
    @gamepadGetState = Win32API.new('Input.dll', 'GamepadGetState', 'IP', 'I')
    @gamepadSetState = Win32API.new('Input.dll', 'GamepadSetState', 'IP', 'I')
    # Declare blank structures
    @capabilities = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].pack('c2S2c2s4S2')
    @gamepad = [0, 0, 0, 0, 0, 0, 0].pack('Sc2s4')
    @state = [0, 0, 0, 0, 0, 0, 0, 0].pack('ISc2s4')
    @vibrate = [0, 0].pack('n2')
    @gamepadGetCapabilities.call(0, 0, @capabilities)
    @capabilities.unpack('C2S2C2n6')
    # Create blank button array
    @buttons = Array.new(14, false)
    # Create a blank axis array
    @axis = Array.new(6, false)
    values = Array.new(6, 0)
    zones = [30, 30, 7849, 7849, 8689, 8689]
    # Declare controller information storage
    @controllers = {}
    # Declare default controller information
    @controllers.default = {
      'Active' => false,                   # Controller active flag
      'Change ID' => 0,                    # Current state change ID
      'Press' => @buttons.clone,           # Flags for button press state
      'Trigger' => @buttons.clone,         # Flags for button trigger state
      'Repeat' => @buttons.clone,          # Flags for button repeat state
      'Release' => @buttons.clone,         # Flags for button release state
      'Repeat Timer' => Array.new(14, 0),  # Timer for button repeat state
      'Base Repeat' => 15,                 # Base time for repeat flag (frames)
      'Axes' => Array.new(6, 0),           # Axis values
      'Axis Dead Zones' => zones.clone,    # Dead zone for the axes
      'Axis Press' => @axis.clone,         # Flags for axis press state
      'Axis Trigger' => @axis.clone,       # Flags for axis trigger state
      'Axis Repeat' => @axis.clone,        # Flags for axis repeat state
      'Axis Release' => @axis.clone,       # Flags for axis release state
      'Axis Repeat Timer' => values.clone, # Timer for axis repeat state
      'Vibrate State' => [0, 0],           # Current vibrate state
      'Vibrate Timer' => 0,                # Current vibrate timer
      'Vibrate Repeat Timer' => 0,         # Current rumbe repeat timer
      'Vibrate Minimum Timer' => 0         # Min. time before changing vibrate
    }
    # Iterate through the total number of controllers allowed
    for i in 0..3
      # Add a new controller to the controller array
      @controllers[i] = @controllers.default.clone
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def self.update
    # Iterate through all controllers
    for i in 0..3
      # Set up a blank state structure
      state = @state
      # Detect the controller state
      success = @gamepadGetState.call(i, state)
      # If the state was successfully obtained
      if success == 1
        # Set the controller to active
        @controllers[i]['Active'] = true
        # Backup the previous button states
        controller = @controllers[i].clone
        # Reset the controller button states
        @controllers[i]['Press']        = @buttons.clone
        @controllers[i]['Trigger']      = @buttons.clone
        @controllers[i]['Repeat']       = @buttons.clone
        @controllers[i]['Release']      = @buttons.clone
        @controllers[i]['Axis Press']   = @axis.clone
        @controllers[i]['Axis Trigger'] = @axis.clone
        @controllers[i]['Axis Repeat']  = @axis.clone
        @controllers[i]['Axis Release'] = @axis.clone
        # Unpack the controller state
        state = state.unpack('ISC2s4')
        # If the controller state has changed
        if state[0] != @controllers[i]['Change ID']
          # Add the controller button states to the controller state
          @controllers[i]['Press'][0]  = (state[1] & 0x00000001 == 0x00000001)
          @controllers[i]['Press'][1]  = (state[1] & 0x00000002 == 0x00000002)
          @controllers[i]['Press'][2]  = (state[1] & 0x00000004 == 0x00000004)
          @controllers[i]['Press'][3]  = (state[1] & 0x00000008 == 0x00000008)
          @controllers[i]['Press'][4]  = (state[1] & 0x00000010 == 0x00000010)
          @controllers[i]['Press'][5]  = (state[1] & 0x00000020 == 0x00000020)
          @controllers[i]['Press'][6]  = (state[1] & 0x00000040 == 0x00000040)
          @controllers[i]['Press'][7]  = (state[1] & 0x00000080 == 0x00000080)
          @controllers[i]['Press'][8]  = (state[1] & 0x0100 == 0x0100)
          @controllers[i]['Press'][9]  = (state[1] & 0x0200 == 0x0200)
          @controllers[i]['Press'][10] = (state[1] & 0x1000 == 0x1000)
          @controllers[i]['Press'][11] = (state[1] & 0x2000 == 0x2000)
          @controllers[i]['Press'][12] = (state[1] & 0x4000 == 0x4000)
          @controllers[i]['Press'][13] = (state[1] & 0x8000 == 0x8000)
          # Add the controller trigger states to the current controller state
          @controllers[i]['Axes'][0]   = state[2]
          @controllers[i]['Axes'][1]   = state[3]
          # Add the controller thumb coords to the current controller state
          @controllers[i]['Axes'][2]   = state[4]
          @controllers[i]['Axes'][3]   = state[5]
          @controllers[i]['Axes'][4]   = state[6]
          @controllers[i]['Axes'][5]   = state[7]
        end
        # Iterate through the buttons
        for button in 0...@controllers[i]['Press'].size
          # If the button is pressed, and the repeat count is at 0
          if ((@controllers[i]['Press'][button] == true) &&
            (@controllers[i]['Repeat Timer'][button] <= 0))
            # Set the button to repeat
            @controllers[i]['Repeat'][button] = true
            # Get the base repeat time
            repeat_timer = @controllers[i]['Base Repeat']
            # Reset the repeat timer
            @controllers[i]['Repeat Timer'][button] = repeat_timer
          # If the repeat timer is above 0
          elsif @controllers[i]['Repeat Timer'][button] > 0
            # Cycle down the repeat timer
            @controllers[i]['Repeat Timer'][button] -= 1
          end
          # If the button is pressed, and it wasn't pressed previously
          if ((@controllers[i]['Press'][button] == true) &&
            (controller['Press'][button] == false))
            # Set the button to trigger
            @controllers[i]['Trigger'][button] = true
          # If the button is not pressed, and it was previously
          elsif ((@controllers[i]['Press'][button] == false) &&
            (controller['Press'][button] == true))
            # Set the button to release
            @controllers[i]['Release'][button] = true
          end
        end
        # Iterate through the buttons
        for axis in 0...@controllers[i]['Axes'].size
          # If the trigger is greater than the dead zone, set it to pressed
          if (@controllers[i]['Axes'][axis].abs >
            @controllers[i]['Axis Dead Zones'][axis])
            # Set the axis to pressed
            @controllers[i]['Axis Press'][axis] = true
          end
          # If the axis is pressed, and the repeat count is at 0
          if ((@controllers[i]['Axis Press'][axis] == true) &&
            (@controllers[i]['Axis Repeat Timer'][axis] <= 0))
            # Set the axis to repeat
            @controllers[i]['Axis Repeat'][axis] = true
            # Get the base repeat time
            repeat_timer = @controllers[i]['Base Repeat']
            # Reset the repeat timer
            @controllers[i]['Axis Repeat Timer'][axis] = repeat_timer
          # If the repeat timer is above 0
          elsif @controllers[i]['Axis Repeat Timer'][axis] > 0
            # Cycle down the repeat timer
            @controllers[i]['Axis Repeat Timer'][axis] -= 1
          end
          # If the axis is pressed, and it wasn't pressed previously
          if ((@controllers[i]['Axis Press'][axis] == true) &&
            (controller['Axis Press'][axis] == false))
            # Set the axis to trigger
            @controllers[i]['Axis Trigger'][axis] = true
          # If the axis is not pressed, and it was previously
          elsif ((@controllers[i]['Press'][axis] == false) &&
            (controller['Axis Press'][axis] == true))
            # Set the axis to release
            @controllers[i]['Axis Release'][axis] = true
          end
        end
        # If the controller is set to vibrate
        if @controllers[i]['Vibrate Timer'] > 0
          # If the vibrate repeat timer has reached 0
          if @controllers[i]['Vibrate Repeat Timer'] <= 0
            # Get the current vibration values
            left_motor = @controllers[i]['Vibrate State'][0] - 1
            right_motor = @controllers[i]['Vibrate State'][1] - 1
            # Correct the motor values
            left_motor = 0 if left_motor < 0
            right_motor = 0 if right_motor < 0
            # Create the vibration state structure
            vibrate = [left_motor, right_motor].pack('n2')
            # Reset the controller vibrate state
            @gamepadSetState.call(i, vibrate)
            # Pack the current vibrate state
            vibrate_state = @controllers[i]['Vibrate State'].pack('n2')
            # Set the vibrate state to the current controller vibrate state
            @gamepadSetState.call(i, vibrate_state)
            # Reset the vibrate repeat timer
            @controllers[i]['Vibrate Repeat Timer'] = Graphics.frame_rate
          # If the vibrate repeat timer is greater than 0
          else
            # Decrement the vibrate repeat timer
            @controllers[i]['Vibrate Repeat Timer'] -= 1
          end
          # Decrement the vibrate timer
          @controllers[i]['Vibrate Timer'] -= 1
        # If the vibrate timer is 0, and the vibrate state is still set
        elsif ((@controllers[i]['Vibrate Timer'] <= 0) &&
          (@controllers[i]['Vibrate State'] != [0, 0]))
          # Reset the vibrate state
          @controllers[i]['Vibrate State'] = [0, 0]
          # Set the vibrate repeat timer to 1/3 of a second
          @controllers[i]['Vibrate Repeat Timer'] = Graphics.frame_rate / 3
        # If the vibrate timer is 0 and the vibrate state is cleared
        elsif ((@controllers[i]['Vibrate Timer'] <= 0) &&
          (@controllers[i]['Vibrate State'] == [0, 0]))
          # If the vibrate repeat timer is running
          if @controllers[i]['Vibrate Repeat Timer'] >= 0
            # Decrement the vibrate repeat timer
            @controllers[i]['Vibrate Repeat Timer'] -= 1
          # If the timer has run out
          else
            # Reset the vibrate repeat timer
            @controllers[i]['Vibrate Repeat Timer'] = 0
            # Reset the controller vibrate state
            @gamepadSetState.call(i, @vibrate)
          end
        end
        # If the controller's minimum vibrate update timer is running
        if @controllers[i]['Vibrate Minimum Timer'] > 0
          # Decrement the timer
          @controllers[i]['Vibrate Minimum Timer'] -= 1
        end
      # If the controller is not connected, or the state could not be read
      elsif success == 2 || success == -1
        # Set the controller to inactive
        @controllers[i]['Active'] = false
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Get Button Pressed State
  #     button : button number
  #     index  : controller number (0 to 3)
  #--------------------------------------------------------------------------
  def self.press?(button, index = 0)
    # Return false if the controller is inactive
    return false if @controllers[index]['Active'] == false
    # Return button pressed state
    return @controllers[index]['Press'][button]
  end
  #--------------------------------------------------------------------------
  # * Get Button Triggered State
  #     button : button number
  #     index  : controller number (0 to 3)
  #--------------------------------------------------------------------------
  def self.trigger?(button, index = 0)
    # Return false if the controller is inactive
    return false if @controllers[index]['Active'] == false
    # Return button triggered state
    return @controllers[index]['Trigger'][button]
  end
  #--------------------------------------------------------------------------
  # * Get Button Repeated State
  #     button : button number
  #     index  : controller number (0 to 3)
  #--------------------------------------------------------------------------
  def self.repeat?(button, index = 0)
    # Return false if the controller is inactive
    return false if @controllers[index]['Active'] == false
    # Return button repeated state
    return @controllers[index]['Repeat'][button]
  end
  #--------------------------------------------------------------------------
  # * Get Button Released State
  #     button : button number
  #     index  : controller number (0 to 3)
  #--------------------------------------------------------------------------
  def self.release?(button, index = 0)
    # Return false if the controller is inactive
    return false if @controllers[index]['Active'] == false
    # Return button released state
    return @controllers[index]['Release'][button]
  end
  #--------------------------------------------------------------------------
  # * Get Axis Pressed State
  #     axis  : axis number
  #     index : controller number (0 to 3)
  #--------------------------------------------------------------------------
  def self.axis_press?(axis, index = 0)
    # Return false if the controller is inactive
    return false if @controllers[index]['Active'] == false
    # Return axis pressed state
    return @controllers[index]['Axis Press'][axis]
  end
  #--------------------------------------------------------------------------
  # * Get Axis Triggered State
  #     axis  : axis number
  #     index : controller number (0 to 3)
  #--------------------------------------------------------------------------
  def self.axis_trigger?(axis, index = 0)
    # Return false if the controller is inactive
    return false if @controllers[index]['Active'] == false
    # Return axis triggered state
    return @controllers[index]['Axis Trigger'][axis]
  end
  #--------------------------------------------------------------------------
  # * Get Axis Repeated State
  #     axis  : axis number
  #     index : controller number (0 to 3)
  #--------------------------------------------------------------------------
  def self.axis_repeat?(axis, index = 0)
    # Return false if the controller is inactive
    return false if @controllers[index]['Active'] == false
    # Return axis repeated state
    return @controllers[index]['Axis Repeat'][axis]
  end
  #--------------------------------------------------------------------------
  # * Get Axis Released State
  #     axis  : axis number
  #     index : controller number (0 to 3)
  #--------------------------------------------------------------------------
  def self.axis_release?(axis, index = 0)
    # Return false if the controller is inactive
    return false if @controllers[index]['Active'] == false
    # Return axis released state
    return @controllers[index]['Axis Release'][axis]
  end
  #--------------------------------------------------------------------------
  # * Get Axis Value
  #     axis  : axis number
  #     index : controller number (0 to 3)
  #--------------------------------------------------------------------------
  def self.axis_value(axis, index = 0)
    # Set a temporary variable to the axis value
    value = self.real_axis_value(axis, index)
    # Return axis value
    return value unless value.abs < @controllers[index]['Axis Dead Zones'][axis]
    # Return 0 if the axis is within the dead zone
    return 0
  end
  #--------------------------------------------------------------------------
  # * Get Real Axis Value
  #     axis  : axis number
  #     index : controller number (0 to 3)
  #--------------------------------------------------------------------------
  def self.real_axis_value(axis, index = 0)
    # Return the axis value
    return @controllers[index]['Axes'][axis]
  end
  #--------------------------------------------------------------------------
  # * Set Controller to Vibrate
  #     left_motor  : left motor value (0 to 65535)
  #     right_motor : right motor value (0 to 65535)
  #     frames      : number of frames to vibrate
  #     index       : controller number (0 to 3)
  #--------------------------------------------------------------------------
  def self.vibrate(left_motor, right_motor, frames, index = 0)
    # Return false if the vibrate has updated too recently
    return false if @controllers[index]['Vibrate Minimum Timer'] > 0
    # Set the controller vibrate timer to the number of frames
    @controllers[index]['Vibrate Timer'] = frames
    # Correct the motor values if out of range
    left_motor = 0 if left_motor < 0
    left_motor = 65535 if left_motor > 65535
    right_motor = 0 if right_motor < 0
    right_motor = 65535 if right_motor > 65535
    # Set the controller motor values
    @controllers[index]['Vibrate State'] = [left_motor.to_i, right_motor.to_i]
    # Set the minimum update timer
    @controllers[index]['Vibrate Minimum Timer'] = Graphics.frame_rate / 4
    # Return true if the vibrate was successfully set
    return true
  end
  #--------------------------------------------------------------------------
  # * Initialize Module
  #--------------------------------------------------------------------------
  begin
    # Force an initial update of the gamepad
    self.update
  end
end

#==============================================================================
# ** Input
#------------------------------------------------------------------------------
#  This module performs input processing
#==============================================================================

module Input
  # Add class data
  class << self
    #------------------------------------------------------------------------
    # * Alias Methods
    #------------------------------------------------------------------------
    # If the update method has not been aliased
    unless method_defined?(:glitch_gamepad_input_update)
      # Alias the update method
      alias glitch_gamepad_input_update update
    end
    #------------------------------------------------------------------------
    # * Frame Update
    #------------------------------------------------------------------------
    def update
      # Call original method
      glitch_gamepad_input_update
      # Update Gamepad module
      Gamepad.update
    end
  end
end


Link code :: http://www.hbgames.org/forums/viewtopic.php?t=73959

Thanks :D
..........________
....'/,-Y"............."~-.
..l.Y.......................^.
./\............................_\
i.................... ___/"...."\
|.................../"...."\ .....o!
l..................].......o !__../
.\..._..._.........\..___./......"~\
..X...\/...\.....................___./
.(. \.___......_.....--~~".....~`-.           
....`.Z,--........./.....................\
.......\__....(......../.........._____)
...........\.........l......../---~~" /
............Y.......\................../
............|........"x_____.^
............|.....................\
............j.....................Y

KK20

Quote
# * Glitchfinder's Advice
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#  This script is meant for people with a medium or advanced level of scripting
#  knowledge and ability, or for those using scripts that require this module.

In other words, this is a scripting tool, it's not a plug-n-play script. The script hasn't even defined, for example, what pressing the A button on the gamepad will do. You have to do that yourself. But seeing as you're not a scripter...

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Sase

Just use a program to map gamepad buttons to keyboard keys.

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

R5GAMER

I still do not understand, how can we use what you just send me ...?
..........________
....'/,-Y"............."~-.
..l.Y.......................^.
./\............................_\
i.................... ___/"...."\
|.................../"...."\ .....o!
l..................].......o !__../
.\..._..._.........\..___./......"~\
..X...\/...\.....................___./
.(. \.___......_.....--~~".....~`-.           
....`.Z,--........./.....................\
.......\__....(......../.........._____)
...........\.........l......../---~~" /
............Y.......\................../
............|........"x_____.^
............|.....................\
............j.....................Y

ForeverZer0

Quote from: R5GAMER on March 30, 2015, 10:22:30 pm
I still do not understand, how can we use what you just send me ...?


Quote from: Sase on March 29, 2015, 04:55:23 am
Just use a program to map gamepad buttons to keyboard keys.


I don;'t understand what it is exactly you don't understand. It is a small program you can distribute with your game to allow use of a gamepad. You can have the keys mapped exactly as you see fit. It is pretty self-explanatory.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

R5GAMER

March 31, 2015, 10:10:46 am #6 Last Edit: March 31, 2015, 10:12:16 am by R5GAMER
Quote from: ForeverZer0 on March 31, 2015, 12:39:39 am
Quote from: R5GAMER on March 30, 2015, 10:22:30 pm
I still do not understand, how can we use what you just send me ...?


Quote from: Sase on March 29, 2015, 04:55:23 am
Just use a program to map gamepad buttons to keyboard keys.


I don;'t understand what it is exactly you don't understand. It is a small program you can distribute with your game to allow use of a gamepad. You can have the keys mapped exactly as you see fit. It is pretty self-explanatory.


I tested :


UP = "Key['Z'], #{Gamepad::DPAD_UP}"


or


UP = Gamepad::DPAD_UP


But it doesn't respond ... I don't think this is the idea that you try to give me, but I try to understand ... How it works ...: /
..........________
....'/,-Y"............."~-.
..l.Y.......................^.
./\............................_\
i.................... ___/"...."\
|.................../"...."\ .....o!
l..................].......o !__../
.\..._..._.........\..___./......"~\
..X...\/...\.....................___./
.(. \.___......_.....--~~".....~`-.           
....`.Z,--........./.....................\
.......\__....(......../.........._____)
...........\.........l......../---~~" /
............Y.......\................../
............|........"x_____.^
............|.....................\
............j.....................Y

KK20

It's not a script dude :facepalm:

http://joytokey.net/en/download

Download, run the program, configure what each gamepad button corresponds to what key on the keyboard, save, and play RPG Maker game.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

R5GAMER

Quote from: R5GAMER on March 31, 2015, 10:10:46 am
Quote from: ForeverZer0 on March 31, 2015, 12:39:39 am
Quote from: R5GAMER on March 30, 2015, 10:22:30 pm
I still do not understand, how can we use what you just send me ...?


Quote from: Sase on March 29, 2015, 04:55:23 am
Just use a program to map gamepad buttons to keyboard keys.


I don;'t understand what it is exactly you don't understand. It is a small program you can distribute with your game to allow use of a gamepad. You can have the keys mapped exactly as you see fit. It is pretty self-explanatory.


I tested :


UP = "Key['Z'], #{Gamepad::DPAD_UP}"


or


UP = Gamepad::DPAD_UP


But it doesn't respond ... I don't think this is the idea that you try to give me, but I try to understand ... How it works ...: /


Quote
It's not a script dude Facepalm

http://joytokey.net/en/download

Download, run the program, configure what each gamepad button corresponds to what key on the keyboard, save, and play RPG Maker game.


In my test i used "Glitchfinder's Gamepad Input Module" (in my first post)
..........________
....'/,-Y"............."~-.
..l.Y.......................^.
./\............................_\
i.................... ___/"...."\
|.................../"...."\ .....o!
l..................].......o !__../
.\..._..._.........\..___./......"~\
..X...\/...\.....................___./
.(. \.___......_.....--~~".....~`-.           
....`.Z,--........./.....................\
.......\__....(......../.........._____)
...........\.........l......../---~~" /
............Y.......\................../
............|........"x_____.^
............|.....................\
............j.....................Y

KK20

Again, you don't need a script. You can remove Glitchfinder's script entirely from your project.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

LiTTleDRAgo

March 31, 2015, 03:37:45 pm #10 Last Edit: April 01, 2015, 11:37:38 pm by Archer
@KK20> probably he didn't want to include any software when distributing his game.

---deleted---

NB : Untested, I didn't have a gamepad.

R5GAMER

Quote from: LiTTleDRAgo on March 31, 2015, 03:37:45 pm
@KK20> probably he didn't want to include any software when distributing in my game.

Spoiler: ShowHide
#==============================================================================
# ** Input
#------------------------------------------------------------------------------
#  This module handles all Input
#==============================================================================
class << Input
 #----------------------------------------------------------------------------
 # * Script Check
 #----------------------------------------------------------------------------
 $BlizzABS         || raise("Require Blizz ABS")
 defined?(Gamepad) || raise("Require Glitchfinder's Gamepad Input Module")
 #----------------------------------------------------------------------------
 # * Configuration
 #----------------------------------------------------------------------------
 Gamepad_Hash = {
 
   UP    => Gamepad::DPAD_UP,
   LEFT  => Gamepad::DPAD_LEFT,
   DOWN  => Gamepad::DPAD_DOWN,
   RIGHT => Gamepad::DPAD_RIGHT,
   B     => Gamepad::BACK,
   C     => Gamepad::START,
   L     => Gamepad::LEFT_SHOULDER,
   R     => Gamepad::RIGHT_SHOULDER,
   
   # The rest look at Input module in the Blizz ABS Part 2
   Confirm  => Gamepad::START,
   Cancel   => Gamepad::BACK,
   Attack   => Gamepad::A,
   Defend   => Gamepad::B,

 }
 #----------------------------------------------------------------------------
 # * Alias Listing
 #----------------------------------------------------------------------------
 alias_method :trigger_for_gamepad, :"trigger?"
 alias_method :press_for_gamepad,   :"press?"
 alias_method :repeat_for_gamepad,  :"repeat?"
 #----------------------------------------------------------------------------
 # * trigger?
 #  Test if key was triggered once.
 #----------------------------------------------------------------------------
 def trigger?(keys)
   result = trigger_for_gamepad(keys)
   keys = [keys] unless keys.is_a?(Array)
   if !result && (gamepad = keys.find {|i| Gamepad_Hash[i]})
     result ||= Gamepad.trigger?(gamepad)
   end
   return result
 end
 #----------------------------------------------------------------------------
 # * press?
 #  Test if key is being pressed.
 #----------------------------------------------------------------------------
 def press?(keys)
   result = press_for_gamepad(keys))
   keys = [keys] unless keys.is_a?(Array)
   if !result && (gamepad = keys.find {|i| Gamepad_Hash[i]})
     result ||= Gamepad.press?(gamepad)
   end
   return result
 end
 #----------------------------------------------------------------------------
 # * repeat?
 #  Test if key is being pressed for repeating.
 #----------------------------------------------------------------------------
 def repeat?(keys)
   result = repeat_for_gamepad(keys))
   keys = [keys] unless keys.is_a?(Array)
   if !result && (gamepad = keys.find {|i| Gamepad_Hash[i]})
     result ||= Gamepad.repeat?(gamepad)
   end
   return result
 end
end


NB : Untested, I didn't have a gamepad.


Yes, i didn't want to include any software when distributing his game.
I had errors on the 'line '56' and '58' there was a bracket(parenthesis) too...

I change in line '58':
result = press_for_gamepad(keys))

to
result = press_for_gamepad(keys)


I change in line '68':
result = repeat_for_gamepad(keys))

to
result = repeat_for_gamepad(keys)


And i have this error "Script line 17: NameError occured. uninitialized constant Module::UP"
..........________
....'/,-Y"............."~-.
..l.Y.......................^.
./\............................_\
i.................... ___/"...."\
|.................../"...."\ .....o!
l..................].......o !__../
.\..._..._.........\..___./......"~\
..X...\/...\.....................___./
.(. \.___......_.....--~~".....~`-.           
....`.Z,--........./.....................\
.......\__....(......../.........._____)
...........\.........l......../---~~" /
............Y.......\................../
............|........"x_____.^
............|.....................\
............j.....................Y

LiTTleDRAgo

try add Input:: at each of them

ex : Input::UP, Input::DOWN, etc

R5GAMER

March 31, 2015, 11:23:54 pm #13 Last Edit: April 01, 2015, 06:38:58 pm by Archer
Quote from: LiTTleDRAgo on March 31, 2015, 08:05:16 pm
try add Input:: at each of them

ex : Input::UP, Input::DOWN, etc


I modified as the example below

Gamepad_Hash = {
 
   UP    => Gamepad::DPAD_UP,
   LEFT  => Gamepad::DPAD_LEFT,
   DOWN  => Gamepad::DPAD_DOWN,
   RIGHT => Gamepad::DPAD_RIGHT,
   B     => Gamepad::BACK,
   C     => Gamepad::START,
   L     => Gamepad::LEFT_SHOULDER,
   R     => Gamepad::RIGHT_SHOULDER,
   
   # The rest look at Input module in the Blizz ABS Part 2
   Confirm  => Gamepad::START,
   Cancel   => Gamepad::BACK,
   Attack   => Gamepad::A,
   Defend   => Gamepad::B,

 }

to

Gamepad_Hash = {
 
   Input::UP    => Gamepad::DPAD_UP,
   Input::LEFT  => Gamepad::DPAD_LEFT,
   Input::DOWN  => Gamepad::DPAD_DOWN,
   Input::RIGHT => Gamepad::DPAD_RIGHT,
   Input::B     => Gamepad::BACK,
   Input::C     => Gamepad::START,
   Input::L     => Gamepad::LEFT_SHOULDER,
   Input::R     => Gamepad::RIGHT_SHOULDER,
   
   # The rest look at Input module in the Blizz ABS Part 2
   Input::Confirm  => Gamepad::START,
   Input::Cancel   => Gamepad::BACK,
   Input::Attack   => Gamepad::A,
   Input::Defend   => Gamepad::B,

 }


I don't have any error but the Gamepad doesn't respond .. :/

*EDIT* : When I place(square) Gamepad::START or other one in an event and when I puts him(it) in parallel process, the gamepad respond..
..........________
....'/,-Y"............."~-.
..l.Y.......................^.
./\............................_\
i.................... ___/"...."\
|.................../"...."\ .....o!
l..................].......o !__../
.\..._..._.........\..___./......"~\
..X...\/...\.....................___./
.(. \.___......_.....--~~".....~`-.           
....`.Z,--........./.....................\
.......\__....(......../.........._____)
...........\.........l......../---~~" /
............Y.......\................../
............|........"x_____.^
............|.....................\
............j.....................Y

LiTTleDRAgo

Blizz ABS overwrites Input module, try place Glitchfinder's gamepad script below Blizz ABS

R5GAMER

Quote from: Archer on April 01, 2015, 07:32:08 pm
Blizz ABS overwrites Input module, try place Glitchfinder's gamepad script below Blizz ABS


It is what I made but that changes nothing...
..........________
....'/,-Y"............."~-.
..l.Y.......................^.
./\............................_\
i.................... ___/"...."\
|.................../"...."\ .....o!
l..................].......o !__../
.\..._..._.........\..___./......"~\
..X...\/...\.....................___./
.(. \.___......_.....--~~".....~`-.           
....`.Z,--........./.....................\
.......\__....(......../.........._____)
...........\.........l......../---~~" /
............Y.......\................../
............|........"x_____.^
............|.....................\
............j.....................Y

LiTTleDRAgo

April 01, 2015, 11:38:19 pm #16 Last Edit: April 02, 2015, 12:53:20 am by Archer
try this

Spoiler: ShowHide
#==============================================================================
# ** Input
#------------------------------------------------------------------------------
#  This module handles all Input
#==============================================================================
class << Input
  #----------------------------------------------------------------------------
  # * Script Check
  #----------------------------------------------------------------------------
  $BlizzABS         || raise("Require Blizz ABS")
  defined?(Gamepad) || raise("Require Glitchfinder's Gamepad Input Module")
  #----------------------------------------------------------------------------
  # * Configuration
  #----------------------------------------------------------------------------
  GPad_Hash = {
 
    Input::UP    => Gamepad::DPAD_UP,
    Input::LEFT  => Gamepad::DPAD_LEFT,
    Input::DOWN  => Gamepad::DPAD_DOWN,
    Input::RIGHT => Gamepad::DPAD_RIGHT,
    Input::B     => Gamepad::BACK,
    Input::C     => Gamepad::START,
    Input::L     => Gamepad::LEFT_SHOULDER,
    Input::R     => Gamepad::RIGHT_SHOULDER,
   
    # The rest look at Input module in the Blizz ABS Part 2
    Input::Confirm  => Gamepad::START,
    Input::Cancel   => Gamepad::BACK,
    Input::Attack   => Gamepad::A,
    Input::Defend   => Gamepad::B,

  }
  #----------------------------------------------------------------------------
  # ● Aliased Method: press?, :repeat?, :trigger?
  #----------------------------------------------------------------------------
  [:press?,:repeat?,:trigger?].each do |method|
    alias_method(:"bz_gamepad_#{method}", method)
    define_method(method) do |keys|
      result = send(:"bz_gamepad_#{method}", keys)
      result ||= [keys].flatten.any? {|i| Gamepad.send(method, GPad_Hash[i])}
      return result
    end
  end
end


NB : Untested

R5GAMER

April 02, 2015, 12:02:55 am #17 Last Edit: April 02, 2015, 12:04:54 am by Archer
Quote from: Archer on April 01, 2015, 11:38:19 pm
try this

Spoiler: ShowHide
#==============================================================================
# ** Input
#------------------------------------------------------------------------------
#  This module handles all Input
#==============================================================================
class << Input
 #----------------------------------------------------------------------------
 # * Script Check
 #----------------------------------------------------------------------------
 $BlizzABS         || raise("Require Blizz ABS")
 defined?(Gamepad) || raise("Require Glitchfinder's Gamepad Input Module")
 #----------------------------------------------------------------------------
 # * Configuration
 #----------------------------------------------------------------------------
 Gamepad_Hash = {
 
   Input::UP    => Gamepad::DPAD_UP,
   Input::LEFT  => Gamepad::DPAD_LEFT,
   Input::DOWN  => Gamepad::DPAD_DOWN,
   Input::RIGHT => Gamepad::DPAD_RIGHT,
   Input::B     => Gamepad::BACK,
   Input::C     => Gamepad::START,
   Input::L     => Gamepad::LEFT_SHOULDER,
   Input::R     => Gamepad::RIGHT_SHOULDER,
   
   # The rest look at Input module in the Blizz ABS Part 2
   Input::Confirm  => Gamepad::START,
   Input::Cancel   => Gamepad::BACK,
   Input::Attack   => Gamepad::A,
   Input::Defend   => Gamepad::B,

 }
 #--------------------------------------------------------------------------
 # ● Aliased Method: press?, :repeat?, :trigger?
 #--------------------------------------------------------------------------
 [:press?,:repeat?,:trigger?].each do |method|
   next unless method_defined?(:"#{method}")
   alias_method(:"bz_gamepad_#{method}", :"#{method}")
   define_method(:"#{method}") do |keys|
     result = send(:"bz_gamepad_#{method}", keys)
     unless result
       keys = [keys] unless keys.is_a?(Array)
       gpad = keys.collect {|i| Gamepad_Hash[i]}).compact
       result ||= gpad.any? {|i| Gamepad.send(:"#{method}",i)}
     end
     return result
   end
 end
end


NB : Untested



Error "line 43 : SyntaxeError occured."

*EDIT* :

gpad = keys.collect {|i| Gamepad_Hash[i]}).compact

to
gpad = keys.collect {|i| Gamepad_Hash[i]}.compact


But, doesn't not change....
..........________
....'/,-Y"............."~-.
..l.Y.......................^.
./\............................_\
i.................... ___/"...."\
|.................../"...."\ .....o!
l..................].......o !__../
.\..._..._.........\..___./......"~\
..X...\/...\.....................___./
.(. \.___......_.....--~~".....~`-.           
....`.Z,--........./.....................\
.......\__....(......../.........._____)
...........\.........l......../---~~" /
............Y.......\................../
............|........"x_____.^
............|.....................\
............j.....................Y

LiTTleDRAgo

script edited, try it again


if that still doesn't work, then I give up (since I don't have any Gamepad to test it out)

R5GAMER

..........________
....'/,-Y"............."~-.
..l.Y.......................^.
./\............................_\
i.................... ___/"...."\
|.................../"...."\ .....o!
l..................].......o !__../
.\..._..._.........\..___./......"~\
..X...\/...\.....................___./
.(. \.___......_.....--~~".....~`-.           
....`.Z,--........./.....................\
.......\__....(......../.........._____)
...........\.........l......../---~~" /
............Y.......\................../
............|........"x_____.^
............|.....................\
............j.....................Y