MACL - Method and Class Library 2.3

I kinda wish they would have thrown all globals into a single $game class.

class Game
  def add_object(class_name)
    eval "attr_reader :class_name.downcase;"
    eval "@#{class_name.downcase} = class_name.new"
  end
end
Expand to see the code.


Making all Game classes just sub-classes of this would have been a great idea.
class Game
  class Temp
  end
  class Map
  end
end
Expand to see the code.


I would have thrown this into the SDK/MACL a long time ago and rewrote all of it, but it just would have been too many script problems. :(

But I will rewrite the game_data module to be something like this, and just construct a single game variable. What etheon said reminded me of wanting to do this a year ago but didn't want to piss everyone off. I guess in the MACL, we can at least use this vs. making new game objects.

Actually this is going in the SDK (too). At least a better version of this anyways. If you have anything you want to add, now is the time.
I don't really have anything I want to add. If it were up to me, the WHOLE thing would be re-written :p
I am all up for a project or re-writing everything while keeping to the main layout as much as possible. Although it wouldn't do much good outside having a library for script users. We could create an entire project remaking a lot of the RGSS and include a lot addons. Just wouldn't work for any scripts not designed for the system. RMXP - Scripters Edition. lol
Well, we could rewrite the whole thing whilst keeping in mind to build light interfaces, or façades, with would allow perfect and seamless integration of (most) old scripts.
Ok. Let's do it. Open invitation to any scripter who has ever wanted to re-write the RMXP script library. I am having a private forum made so we can develop and discuss this (so we aren't hijacking this thread anymore).

Details Show
The forum will be named RMXP - Scripter's Edition (we can change the name, just making it that for now) and the password will be enterbrainless (unless we need a different password). I'll update this post with precise details when the forum is actually made.
I'm in! Once you get the forum up, I suggest we start drafting on how we'll do this; more specifically :

1) Source Control? (SVN, CVS, etc.)
2) RGSS Re-design : what do we keep, what do we add, what do we modify, what do we throw away
3) Facades : make a draft of the needed facades (although I suppose step 2 has to be finished first)
Alright, last time, this is all my personal methods, even if I posted them previously, I'm posting them again because things change and theres stuff I caught that didn't work right in my past methods. I've re-written everything in here and tested EACH method 12x each in the past 3 days, so if I missed anything this time around with these re-writes I should be shot

Ruby.Numeric.strings Show
#===============================================================================
# ** Ruby.Numeric.strings
#-------------------------------------------------------------------------------
#   Created some additional methods for the Numeric class, which is the parent
# class to all number-related classes. All of these methods deal with turning
# a number into some kind of formatted string form.
#
# Method List
# -----------
#   format_s
#   precise_s
#   percent_s
#   currency_s
#
#===============================================================================
#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
if Object.const_defined?(:SDK)
  SDK.log('MACL::Ruby.Numeric.strings', 'Kain Nobel', 2.0, '09.28.2008')
end
#-------------------------------------------------------------------------------
# * MACL Loading
#-------------------------------------------------------------------------------
MACL::Loaded << "Ruby.Numeric.strings"
#===============================================================================
# ** Numeric
#===============================================================================

class Numeric < Object
  #-----------------------------------------------------------------------------
  # * Name      : Format String
  #   Info      : Returns formatted string (exp; 1234.56 => "1,234.56")
  #   Author    : Kain Nobel
  #   Call Info : Float true will return float, false returns no floating value
  #-----------------------------------------------------------------------------
  def format_s(float = true)
    begin
      parts = self.to_s.split('.')
      parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")
      return parts.length == 2 && float ? parts[0]+"."+parts[1] : parts[0]
    rescue
      return self
    end
  end
  #-----------------------------------------------------------------------------
  # * Name      : Precise
  #   Info      : Returns number to a precise ammount
  #   Author    : Kain Nobel
  #   Call Info : Digits if positive shows this many float digits
  #               Digits if negative rounds integer back this many digits
  #-----------------------------------------------------------------------------
  def precise_s(digits = 2)
    return "%01.#{digits}f"%((Float(self)*(10**digits)).round.to_f/10**digits)
  end
  #-----------------------------------------------------------------------------
  # * Name      : Percent
  #   Info      : Return number as a percent string
  #               (Example: (100 / 8.0).percent #=> "12.5 %")
  #   Author    : Kain Nobel
  #   Call Info : Max is what the percent is comparing to
  #               Tolerence is the ammount of float to show (Default 0)
  #-----------------------------------------------------------------------------
  def percent_s(tolerence = 0, format = false)
    begin
      return format ? self.format_s+"%" : self.to_s+"%"
    rescue
      return self
    end
  end
  #-----------------------------------------------------------------------------
  # * Name      : Currency
  #   Info      : Returns currency string (exp; "$1,234.56")
  #   Author    : Kain Nobel
  #   Call Info : Sign is the currency symbol, for instance "$" or "Yen" or w/e
  #               Tail true sign is pinned to end, false sign pinned to start
  #-----------------------------------------------------------------------------
  def currency(sign = nil, tail = false)
    sign = "$" if !sign.is_a?(String)
    tail = self.to_i.zero? || tail
    begin
      if tail ; return (self.precise_s(2).to_f).format_s+" "+sign
      else    ; return sign+" "+(self.precise_s(2).to_f).format_s
      end
    rescue
      return sign+" "+self.to_s
    end
  end
end
Expand to see the code.


'RGSS.Actor and Party Info Show
#==============================================================================
# ** RGSS.Actor and Party Info
#------------------------------------------------------------------------------
# Description:
# ------------
# These set of methods add observer methods to the Game_Actor and Game_Party
# classes, you can get information on how weak an enemy is to a state, all
# of the enemies resistances and weaknesses, etc.
# 
# Method List:
# ------------
#
#   Game_Actor
#   ----------
#   exp_s
#   next_exp_s
#   next_rest_exp_s
#   now_exp
#   next_exp
#   weapon_set
#   armor_set
#   weapon_stats()
#   armor_stats
#   strongest_weapon
#   weakest_weapon
#   strongest_armor
#   weakest_armor
#
#   Game_Party
#   ----------
#   average()
#   gain_all()
#   lose_all
#
#==============================================================================
#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
if Object.const_defined?(:SDK)
  SDK.log('MACL::RGSS.Actor and Party Info', 'Kain Nobel', 2.0, '09.27.2008')
end
#-------------------------------------------------------------------------------
# * MACL Loading
#-------------------------------------------------------------------------------
MACL::Loaded << 'RGSS.Actor and Party Info'
#===============================================================================
# ** Game_Actor
#===============================================================================
class Game_Actor < Game_Battler
  #-----------------------------------------------------------------------------
  # * Public Instance Variables
  #-----------------------------------------------------------------------------
  attr_accessor :weapon_id
  attr_accessor :armor1_id
  attr_accessor :armor2_id
  attr_accessor :armor3_id
  attr_accessor :armor4_id
  #-----------------------------------------------------------------------------
  # * Name      : Experience List
  #   Info      : Returns '@exp_list[@level+1]'
  #   Author    : Kain Nobel
  #   Call Info : None
  #-----------------------------------------------------------------------------
  def exp_list
    return @exp_list[@level+1]
  end
  #--------------------------------------------------------------------------
  # * Name      : Experience String (Overwrite)
  #   Info      : Returns Experience String
  #   Author    : Kain Nobel
  #   Call Info : Format will format experience string with commas
  #--------------------------------------------------------------------------
  def exp_s(format = true)
    return exp_list > 0 ? format ? @exp.format_s : @exp.to_s : "Master"
  end
  #--------------------------------------------------------------------------
  # * Name      : Next Experience String (Overwrite)
  #   Info      : Returns Experience String
  #   Author    : Kain Nobel
  #   Call Info : Format will format experience string with commas
  #--------------------------------------------------------------------------
  def next_exp_s(format = true)
    return exp_list > 0 ? format ? exp_list.format_s : exp_list.to_s : "Master"
  end
  #--------------------------------------------------------------------------
  # * Name      : Next Rest Experience String (Overwrite)
  #   Info      : Returns Experience String
  #   Author    : Kain Nobel
  #   Call Info : Format will format experience string with commas
  #--------------------------------------------------------------------------
  def next_rest_exp_s(format = true)
    return exp_list > 0 ? format ? (exp_list-@exp).format :
    (exp_list-@exp).to_s : "Master"
  end
  #--------------------------------------------------------------------------
  # * Name      : Now Experience
  #   Info      : Returns current Experience
  #   Author    : Kain Nobel
  #   Call Info : None
  #-----------------------------------------------------------------------------
  def now_exp
    return @exp - @exp_list[@level]
  end
  #-----------------------------------------------------------------------------
  # * Name      : Next Experience
  #   Info      : Returns Experience to Next Level
  #   Author    : Kain Nobel
  #   Call Info : None
  #-----------------------------------------------------------------------------
  def next_exp
    return exp_list > 0 ? exp_list - @exp_list[@level] : 0
  end
  #-----------------------------------------------------------------------------
  # * Name      : Weapon Set
  #   Info      : Returns all weapon objects for an actor's class
  #   Author    : Kain Nobel
  #   Call Info : None
  #-----------------------------------------------------------------------------
  def weapon_set
    return $data_classes[@class_id].weapon_set
  end
  #-----------------------------------------------------------------------------
  # * Name      : Armor Set
  #   Info      : Returns all armor objects for an actor's class
  #   Author    : Kain Nobel
  #   Call Info : Kind ID for the Armors to check
  #-----------------------------------------------------------------------------
  def armor_set(kind = nil)
    if kind.nil?
      return $data_classes[@class_id].armor_set
    end
    armors = []
    ($data_classes[@class_id].armor_set).each do |armor|
      armors.push(armor) if $data_armors[armor].kind == kind
    end
    return armors
  end
  #-----------------------------------------------------------------------------
  # * Name      : Weapon Stats
  #   Info      : Returns a list of desired stats for the actor's weapon set
  #   Author    : Kain Nobel
  #   Call Info : Parameter is a string representing parameter in question
  #-----------------------------------------------------------------------------
  def weapon_stats(parameter)
    stats = []
    weapon_set.each do |i|
      if $game_party.weapons.include?(i)
        case (parameter.to_s)
        when 'name' ; stats.push($data_weapons[i].name)
        when 'price'; stats.push($data_weapons[i].price)
        when 'atk'  ; stats.push($data_weapons[i].atk)
        when 'pdef' ; stats.push($data_weapons[i].pdef)
        when 'mdef' ; stats.push($data_weapons[i].mdef)
        when 'str'  ; stats.push($data_weapons[i].str_plus)
        when 'dex'  ; stats.push($data_weapons[i].dex_plus)
        when 'agi'  ; stats.push($data_weapons[i].agi_plus)
        when 'int'  ; stats.push($data_weapons[i].int_plus)
        else ; print(":"+parameter+": is not a valid parameter when\n",
        "checking for $game_actor["+@actor_id.to_s+"].weapon_set()")
        end
      end
    end
    return stats.sort!
  end
  #-----------------------------------------------------------------------------
  # * Name      : Armor Stats
  #   Info      : Returns a list of desired stats for an actor's armor set
  #   Author    : Kain Nobel
  #   Call Info : Parameter is a string representing parameter in question
  #               Kind refers to the kind of amror it is
  #-----------------------------------------------------------------------------
  def armor_stats(parameter, kind = 0)
    stats = []
    armor_set.each do |i|
      if $data_armors[i].kind == kind && $game_party.armors.include?(i)
        case (parameter.to_s)
        when 'name' ; stats.push($data_armors[i].name)
        when 'price'; stats.push($data_armors[i].price)
        when 'atk'  ; stats.push($data_armors[i].atk)
        when 'pdef' ; stats.push($data_armors[i].pdef)
        when 'mdef' ; stats.push($data_armors[i].mdef)
        when 'str'  ; stats.push($data_armors[i].str_plus)
        when 'dex'  ; stats.push($data_armors[i].dex_plus)
        when 'agi'  ; stats.push($data_armors[i].agi_plus)
        when 'int'  ; stats.push($data_armors[i].int_plus)
        else ; print(":"+parameter+": is not a valid parameter when\n",
        "checking for $game_actor["+@actor_id.to_s+"].armor_set()")
        end
      end
    end
    return stats.sort!
  end
  #-----------------------------------------------------------------------------
  # * Name      : Strongest Weapon
  #   Info      : Returns the strongest weapon, based on parameter
  #   Author    : Kain Nobel
  #   Call Info : Parameter is a string representing parameter in question
  #-----------------------------------------------------------------------------
  def strongest_weapon(parameter)
    w = weapon_stats(parameter)
    return w[-1]
  end
  #-----------------------------------------------------------------------------
  # * Name      : Strongest Armor
  #   Info      : Returns the strongest armor, based on parameter
  #   Author    : Kain Nobel
  #   Call Info : Parameter is a string representing parameter in question
  #               Kind refers to the kind of amror it is
  #-----------------------------------------------------------------------------
  def strongest_armor(parameter, kind = 0)
    a = armor_stats(parameter, kind)
    return a[-1]
  end
  #-----------------------------------------------------------------------------
  # * Name      : Weakest Weapon
  #   Info      : Returns the weakest weapon, based on parameter
  #   Author    : Kain Nobel
  #   Call Info : Parameter is a string representing parameter in question
  #-----------------------------------------------------------------------------
  def weakest_weapon(parameter)
    w = weapon_stats(parameter)
    return w[0]
  end
  #-----------------------------------------------------------------------------
  # * Name      : Weakest Armor
  #   Info      : Returns the weakest armor, based on parameter
  #   Author    : Kain Nobel
  #   Call Info : Parameter is a string representing parameter in question
  #               Kind refers to the kind of amror it is
  #-----------------------------------------------------------------------------
  def weakest_armor(parameter, kind = 0)
    a = armor_stats(parameter, kind)
    return a[0]
  end
end

#===============================================================================
# ** Game_Party
#===============================================================================

class Game_Party
  #-----------------------------------------------------------------------------
  # * Public Instance Variables
  #-----------------------------------------------------------------------------
  attr_accessor :gold # This is set so you can do $game_party.gold = n
  #-----------------------------------------------------------------------------
  # * Name      : Average
  #   Info      : Returns average of party's stats, based on parameter
  #   Author    : Kain Nobel
  #   Call Info : Parameter is a string representing parameter in question
  #               Float will return the average as a float (Optional)
  #-----------------------------------------------------------------------------
  def average(stat, float = false)
    return 0 if @actors.size == 0
    avg   = float ? 0.0 : 0
    case stat.downcase!
    when 'hp'    ; @actors.each_index {|i| avg += @actors[i].hp}
    when 'maxhp' ; @actors.each_index {|i| avg += @actors[i].maxhp}
    when 'sp'    ; @actors.each_index {|i| avg += @actors[i].sp}
    when 'maxsp' ; @actors.each_index {|i| avg += @actors[i].maxsp}
    when 'level' ; @actors.each_index {|i| avg += @actors[i].level}
    when 'exp'   ; @actors.each_index {|i| avg += @actors[i].exp}
    when 'str'   ; @actors.each_index {|i| avg += @actors[i].str}
    when 'dex'   ; @actors.each_index {|i| avg += @actors[i].dex}
    when 'agi'   ; @actors.each_index {|i| avg += @actors[i].agi}
    when 'int'   ; @actors.each_index {|i| avg += @actors[i].int}
    when 'atk'   ; @actors.each_index {|i| avg += @actors[i].atk}
    when 'pdef'  ; @actors.each_index {|i| avg += @actors[i].pdef}
    when 'mdef'  ; @actors.each_index {|i| avg += @actors[i].mdef}
    when 'eva'   ; @actors.each_index {|i| avg += @actors[i].eva}
    end
    return avg / @actors.size
  end
  #-----------------------------------------------------------------------------
  # * Name      : Gain All
  #   Info      : Gain all items (depending on type)
  #   Author    : Kain Nobel
  #   Call Info : Type is the type of 'item' to gain
  #                 -1 : All Items, Weapons, Armors
  #                  0 : All Items
  #                  1 : All Weapons
  #                  2 : All Armors
  #               Quantity is an integer from 1 to 99 (Optional)
  #-----------------------------------------------------------------------------
  def gain_all(type, quantity = 99)
    if type.is_a?(Fixnum) && type.between?(-1, 2)
      case type
      when -1
        $data_items.each_index    {|i| gain_item(i, quantity.abs)}
        $data_weapons.each_index  {|i| gain_weapon(i, quantity.abs)}
        $data_armors.each_index   {|i| gain_armor(i, quantity.abs)}
      when 0 ; $data_items.each_index   {|i| gain_item(i, quantity.abs)}
      when 1 ; $data_weapons.each_index {|i| gain_weapon(i, quantity.abs)}
      when 2 ; $data_armors.each_index  {|i| gain_armor(i, quantity.abs)}
      end
    end
  end
  #-----------------------------------------------------------------------------
  # * Name      : Lose All
  #   Info      : Lose all items (depending on type)
  #   Author    : Kain Nobel
  #   Call Info : Type is the type of 'item' to lose
  #                 -1 : All Items, Weapons, Armors
  #                  0 : All Items
  #                  1 : All Weapons
  #                  2 : All Armors
  #               Quantity is an integer from 1 to 99 (Optional)
  #-----------------------------------------------------------------------------
  def lose_all(type, quantity = 99)
    quantity = -quantity.abs if quantity > 0
    gain_all(type, quantity)
  end
end
Expand to see the code.


RGSS.Character.MoveTest Show
#===============================================================================
# ~** Character Move Test **~
#-------------------------------------------------------------------------------
# Written By  : Kain Nobel
# Version     : 2.0
# Last Update : 09.02.2008
#===============================================================================
# Description
# -----------
#
#   This is a special set of methods, that will tell you which direction a
#   character or event is moving, and supports both 4 and 8 directional movement
#   checking.
#
#   When checking something like $game_map.events[1].moving_down?, you have the
#   optional argument 'diag'. If you set this argument as 'true' and a player is
#   moving_lower_left, then it'll return false, else it'll return true for both.
#
#   Also, for Game_Player, we've got additional methods for checking if player
#   is 'attempting' to move a certain direction. This is for scripts that want
#   to know, "Is he just 'attempting' to move left, or is he 'really' moving
#   left? So, it doesn't check for Input, rather it'll check for Movement AND
#   Input.
#
# Methods List
# -------------
# Game_Character
#   moving_down?
#   moving_left?
#   moving_right?
#   moving_up?
#   moving_upper_left?
#   moving_upper_right?
#   moving_lower_left?
#   moving_lower_right?
#   move_direction
#   moving_diagonal?
#
# Game_Player (< Game_Character)
#   attempt_down?
#   attempt_left?
#   attempt_right?
#   attempt_up?
#   attempt_upper_left?
#   attempt_upper_right?
#   attempt_lower_left?
#   attempt_lower_right?
#   attempt_moving?
#   attempt_direction?
#   attempt_diagonal?
#
#===============================================================================
#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
if Object.const_defined?(:SDK)
  SDK.log('MACL::RGSS.Character.MoveTest', 'Kain Nobel', 2.0, '09.21.2008')
end
#-------------------------------------------------------------------------------
# * MACL Loading
#-------------------------------------------------------------------------------
MACL::Loaded << 'RGSS.Character.MoveTest'
#===============================================================================
# ** Game_Character
#-------------------------------------------------------------------------------
#   The parent superclass of Game_Player and Game_Event has been modified to
# return detailed information on which direction a character is moving.
#===============================================================================
class Game_Character
  #-----------------------------------------------------------------------------
  # * Moving Down?
  #-----------------------------------------------------------------------------
  def moving_down?(diag = false)
    return false if !diag && (moving_lower_left? || moving_lower_right?)
    return (self.real_y < self.y * 128)
  end
  #-----------------------------------------------------------------------------
  # * Moving Left?
  #-----------------------------------------------------------------------------
  def moving_left?(diag = false)
    return false if !diag && (moving_upper_left? || moving_lower_left?)
    return (self.real_x > self.x * 128)
  end
  #-----------------------------------------------------------------------------
  # * Moving Right?
  #-----------------------------------------------------------------------------
  def moving_right?(diag = false)
    return false if !diag && (moving_upper_right? || moving_lower_right?)
    return (self.real_x < self.x * 128)
  end
  #-----------------------------------------------------------------------------
  # * Moving Left?
  #-----------------------------------------------------------------------------
  def moving_up?(diag = false)
    return false if !diag && (moving_upper_left? || moving_upper_right?)
    return (self.real_y > self.y * 128)
  end
  #-----------------------------------------------------------------------------
  # * Moving Lower Left?
  #-----------------------------------------------------------------------------
  def moving_lower_left?
    return (self.real_y < self.y * 128) && (self.real_x > self.x * 128)
  end
  #-----------------------------------------------------------------------------
  # * Moving Lower Right?
  #-----------------------------------------------------------------------------
  def moving_lower_right?
    return (self.real_y < self.y * 128) && (self.real_x < self.x * 128)
  end
  #-----------------------------------------------------------------------------
  # * Moving Lower Left?
  #-----------------------------------------------------------------------------
  def moving_upper_left?
    return (self.real_y > self.y * 128) && (self.real_x > self.x * 128)
  end
  #-----------------------------------------------------------------------------
  # * Moving Lower Right?
  #-----------------------------------------------------------------------------
  def moving_upper_right?
    return (self.real_y > self.y * 128) && (self.real_x < self.x * 128)
  end
  #-----------------------------------------------------------------------------
  # * Move Direction?
  #-----------------------------------------------------------------------------
  def move_direction
    return 2 if moving_down?  && !(moving_lower_left?   || moving_lower_right?)
    return 4 if moving_left?  && !(moving_lower_left?   || moving_upper_left?)
    return 6 if moving_right? && !(moving_lower_right?  || moving_upper_right?)
    return 8 if moving_up?    && !(moving_upper_left?   || moving_upper_right?)
    return 1 if moving_lower_left?
    return 3 if moving_lower_right?
    return 7 if moving_upper_left?
    return 9 if moving_upper_right?
    return 0
  end
  #-----------------------------------------------------------------------------
  # * Moving Diagonal?
  #-----------------------------------------------------------------------------
  def moving_diagonal?
    return true if moving_upper_left? or moving_upper_right?
    return true if moving_lower_left? or moving_lower_right?
    return false
  end
  #-----------------------------------------------------------------------------
  # * Attempt Print Test
  #-----------------------------------------------------------------------------
  def moving_print_test(diag = false)
    print("Down : "+moving_down?(diag).to_s+
    "\nLeft : "+moving_left?(diag).to_s+
    "\nRight : "+moving_right?(diag).to_s+
    "\nUp : "+moving_up?(diag).to_s+
    "\nUpRight : "+moving_upper_right?.to_s+
    "\nUpLeft : "+moving_upper_left?.to_s+
    "\nDownRight : "+moving_lower_right?.to_s+
    "\nDownLeft : "+moving_lower_left?.to_s+
    "\nDirection : "+move_direction.to_s)
  end
end

#===============================================================================
# ** Game_Player
#-------------------------------------------------------------------------------
#   The child class of Game_Character, returns user's directional input to tell
# you if they're 'attemtping' to move a certain direction.
#===============================================================================
class Game_Player < Game_Character
  #-----------------------------------------------------------------------------
  # * Attempt Down?
  #-----------------------------------------------------------------------------
  def attempt_down?(diag = false)
    unless Input.press?(Input::LEFT) || Input.press?(Input::RIGHT)
      return Input.press?(Input::DOWN)
    end ; return false
  end
  #-----------------------------------------------------------------------------
  # * Attempt Left?
  #-----------------------------------------------------------------------------
  def attempt_left?(diag = false)
    unless Input.press?(Input::UP) || Input.press?(Input::DOWN)
      return Input.press?(Input::LEFT)
    end ; return false
  end
  #-----------------------------------------------------------------------------
  # * Attempt Right?
  #-----------------------------------------------------------------------------
  def attempt_right?(diag = false)
    unless Input.press?(Input::UP) || Input.press?(Input::DOWN)
      return Input.press?(Input::RIGHT)
    end ; return false
  end
  #-----------------------------------------------------------------------------
  # * Attempt Up?
  #-----------------------------------------------------------------------------
  def attempt_up?(diag = false)
    unless Input.press?(Input::LEFT) || Input.press?(Input::RIGHT)
      return Input.press?(Input::UP)
    end ; return false
  end
  #-----------------------------------------------------------------------------
  # * Attempt Upper Left?
  #-----------------------------------------------------------------------------
  def attempt_upper_left?
    m = Input.press?(Input::UP) && Input.press?(Input::LEFT)
    if defined?(Aleworks) && !m
      return Input.press?(Input::UPPER_LEFT)
    end
    return m
  end
  #-----------------------------------------------------------------------------
  # * Attempt Upper Right?
  #-----------------------------------------------------------------------------
  def attempt_upper_right?
    m = Input.press?(Input::UP) && Input.press?(Input::RIGHT)
    if defined?(Aleworks) && !m
      return Input.press?(Input::UPPER_RIGHT)
    end
    return m
  end
  #-----------------------------------------------------------------------------
  # * Attempt Lower Left?
  #-----------------------------------------------------------------------------
  def attempt_lower_left?
    m = Input.press?(Input::DOWN) && Input.press?(Input::LEFT)
    if defined?(Aleworks) && !m
      return Input.press?(Input::LOWER_LEFT)
    end
    return m
  end
  #-----------------------------------------------------------------------------
  # * Attempt Lower Right?
  #-----------------------------------------------------------------------------
  def attempt_lower_right?
    m = Input.press?(Input::DOWN) && Input.press?(Input::RIGHT)
    if defined?(Aleworks) && !m
      return Input.press?(Input::LOWER_RIGHT)
    end
    return m
  end
  #-----------------------------------------------------------------------------
  # * Attempt Moving?
  #-----------------------------------------------------------------------------
  def attempt_moving?(diag = false)
    return true if attempt_down?(diag)
    return true if attempt_left?(diag)
    return true if attempt_right?(diag)
    return true if attempt_up?(diag)
    return attempt_diagonal?
  end
  #-----------------------------------------------------------------------------
  # *  Attempt Direction
  #-----------------------------------------------------------------------------
  def attempt_direction?
    if    attempt_down?         ; return 2
    elsif attempt_left?         ; return 4
    elsif attempt_right?        ; return 6
    elsif attempt_up?           ; return 8
    elsif attempt_lower_left?   ; return 1
    elsif attempt_lower_right?  ; return 3
    elsif attempt_upper_left?   ; return 7
    elsif attempt_upper_right?  ; return 9
    else                        ; return 0
    end
  end
  #-----------------------------------------------------------------------------
  # * Attempt Diagonal?
  #-----------------------------------------------------------------------------
  def attempt_diagonal?
    return true if attempt_upper_left?
    return true if attempt_upper_right?
    return true if attempt_lower_left?
    return true if attempt_lower_right?
    return false
  end
  #-----------------------------------------------------------------------------
  # * Attempt Print Test
  #-----------------------------------------------------------------------------
  def attempt_print_test(diag = false)
    print("Down : "+attempt_down?(diag).to_s+
    "\nLeft : "+attempt_left?(diag).to_s+
    "\nRight : "+attempt_right?(diag).to_s+
    "\nUp : "+attempt_up?(diag).to_s+
    "\nUpRight : "+attempt_upper_right?.to_s+
    "\nUpLeft : "+attempt_upper_left?.to_s+
    "\nDownRight : "+attempt_lower_right?.to_s+
    "\nDownLeft : "+attempt_lower_left?.to_s)
  end
end
Expand to see the code.


'RGSS.Map' Show
#===============================================================================
# ** Game_Map
#-------------------------------------------------------------------------------
# Public Instance Variables
# -------------------------
# @map_infos
# @map_name
# @parent_id
# @parent_name
#
# Methods List
# ------------
#
# this_event
# event_count
# map_count
# map_name
# parent_id
# parent_name
# exists?
#===============================================================================
#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
if Object.const_defined?(:SDK)
  SDK.log('MACL::RGSS.Map', 'MACL Authors', 2.0, '09.28.2008')
end
#-------------------------------------------------------------------------------
# * MACL Loading
#-------------------------------------------------------------------------------
MACL::Loaded << 'RGSS.Map'
#===============================================================================
# ** Game_Map
#-------------------------------------------------------------------------------
#   Added a library of query methods for retrieving information such as event
# count and obtaining information from MapInfos.rxdata
#===============================================================================
class Game_Map
  #-----------------------------------------------------------------------------
  # * Public Instance Variables
  #-----------------------------------------------------------------------------
  attr_reader :map_infos
  #-----------------------------------------------------------------------------
  # * Alias Listings
  #-----------------------------------------------------------------------------
  alias_method :kn_MACL_game_map_setup, :setup
  #-----------------------------------------------------------------------------
  # * Setup
  #-----------------------------------------------------------------------------
  def setup(map_id)
    kn_MACL_game_map_setup(map_id)
    @map_infos ||= load_data("Data/MapInfos.rxdata")
  end
  #-----------------------------------------------------------------------------
  # * Name      : This Event
  #   Info      : Finds the first event directly in front of $game_player
  #   Author    : Kain Nobel
  #   Call Info : None, returns event here or event in front
  #-----------------------------------------------------------------------------
  def this_event
    x, y, d = $game_player.x, $game_player.y, $game_player.direction
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    for event in @events.values
      return event.id if event.x == x     && event.y == y
      return event.id if event.x == new_x && event.y == new_y
    end
  end
  #-----------------------------------------------------------------------------
  # * Name      : Event Count
  #   Info      : Simply counts how many events are on the $game_map
  #   Author    : Kain Nobel
  #   Call Info : None, returns number of events on map
  #-----------------------------------------------------------------------------
  def event_count
    return @events.empty? ? 0 : @events.size
  end
  #-----------------------------------------------------------------------------
  # * Name      : Exists?
  #   Info      : Tests to see if Map exists
  #   Author    : Kain Nobel
  #   Call Info : Map ID is the Map in question
  #-----------------------------------------------------------------------------
  def exists?(map_id)
    return FileTest.exist?(sprintf("Data/Map%03d.rxdata", map_id))
  end
  #-----------------------------------------------------------------------------
  # * Name      : Map Count
  #   Info      : Returns number of valid Map filenames
  #   Author    : Kain Nobel
  #   Call Info : None, returns number of maps in project folder
  #-----------------------------------------------------------------------------
  def map_count
    return @map_infos.keys.size
  end
  #-----------------------------------------------------------------------------
  # * Name      : Map Name
  #   Info      : Sends name of the map in question to a string
  #   Author    : Kain Nobel
  #   Call Info : Map ID (Optional) returns specified Map ID's name
  #-----------------------------------------------------------------------------
  def map_name(map_id = @map_id)
    return @map_infos[map_id].name
  end
  #-----------------------------------------------------------------------------
  # * Name      : Parent ID
  #   Info      : Returns ID of parent map
  #   Author    : Kain Nobel
  #   Call Info : Map ID (Optional) returns specified Map ID's parent Map ID
  #-----------------------------------------------------------------------------
  def parent_id(map_id = @map_id)
    begin  ; return @map_infos[map_id].parent_id
    rescue ; return 0
    end
  end
  #-----------------------------------------------------------------------------
  # * Name      : Parent Name
  #   Info      : Sends name of the parent map in question to a string
  #   Author    : Kain Nobel
  #   Call Info : Map ID (Optional) returns specified Map ID's parent's name
  #-----------------------------------------------------------------------------
  def parent_name
    return map_name(parent_id)
  end
end
Expand to see the code.


I've got a bunch of stuff in my CMS that could probably be used universally too. For instance, this rescue call for the Bitmap class.

#===============================================================================
# ** Bitmap
#-------------------------------------------------------------------------------
#   Aliased initialize method, to rescue 32 x 32 if origional args are too small
#===============================================================================
class Bitmap
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :cms_bitmap_initialize, :initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(*args)
    begin   ; cms_bitmap_initialize(*args)
    rescue  ; cms_bitmap_initialize(32, 32)
    end
  end
end
Expand to see the code.


I also have an embedded facesets system too that I wrote, that could be used universally. Give me 'til tomorrow night and I'll unnest it from my CMS and re-write it
The Data thing was just having this:

module Data # has to be class Data for no apparent reason
  Actors = load_data "Data\Actors.rxdata"
  Animations = load_data "Data\Animations.rxdata"
  [..]
end

I don't know, it's probably a really stupid idea.  I could be very much in on this re-writing RMXP thing though.  I think it would be nice to take a fresh Ruby base and code our own version of RGSS instead, using C++ or something and keeping it open source so it's possible to change stuff like the embedded classes (Tilemap, Input, Viewport...) and of course make it more flexible.  At that point, though, we wouldn't really be working with RMXP anymore, we'd probably be working on a newer, better maker.
That's not too of a bad idea with the Data module. I prefer the constants to global variables. We could definitely do that (or something similar) in the project-rewrite or whatever. We can re-write whatever aspects we want, but I am scared of us saying "Let's make a new engine" because every time someone says that, they usually disappear and never see any results or see only a few. I have no problem if we do go that route, but I want to have a finished result vs. hype.
Exactly.  Which is why I won't be spear-heading this project ;)
But I still want your ideas there. ;)

I want this a complete group effort. I only want to see this done and the most it can be and I will push it until it is.

Sorry about the delay on the MACL update. So many projects at once and I am working on going through every method, cleaning up as much as possible. Currently stuck at Bitmap.gradient, cleaning up a few methods and adding more. lol
FFFF WONDERFUL!!! THE PROJECT WITH ALL THE UPDATES TO THE MACL WAS CORRUPTED! I DONT EVEN KNOW THE LAST TIME I BACKED IT UP! THERE WENT PROBABLY 30 HOURS TO HELL!

SO MAD RIGHT NOW!!!
Damnit!!!!!! That sucks man! If I were you, I'd constantly backup my Scripts.rxdata file, daily... weekly... monthly, thats something that I always do.

Have you tried putting just the "Scripts.rxdata" in another project, or a new project? ...Most likely, if that was the last thing you were working on thats probably the only corrupted file, but what if its a stupid Map or something? Ha, I doubt it, you're a scripter not a mapper! But still, not to be Captain Obvious or nothing, but test out just the "Scripts" file on a new project, there's probably a chance thats not the corrupted file (but like I said, I doubt it since that is something you always work on.)

Is there anything we could help you with on re-attempt to update the MACL? I can go through and try and organize the new methods 'n stuff if you would like, leaving you to just proof read and make changes to whatever isn't working. I'm not sure what all you plan on including but I'm down for whatever to help you with it.

*Leaves to backup his current scripts.*
I usually do weekly, but just haven't had the time. I haven't had any problems in about 2 years. It was all the .rxdata files. I tried putting it into a new project and putting all the other files into the project. Now luck either way. :(

All I can say is it's a good thing I have about 40% of the updates scattered in my other projects. Now to go through 120 project files and check, add and merge. I will probably end up  not having everything that I did have, but I am going to try. In all cases, the compiler is going to wait for the 2.6 version now. I just don't have the time and patience for it right now.


If you really want to help, can you create a new project, go through this topic and add every addition into the project. Each with its own part, seperated like the MACL would. RGSS.Map, RGSS.Character, etc.

That would save me an hour or 2 and I would greatly appreciate it.
Okay I'm going to go ahead and do it for you.

Here, I already had this project pre-loaded. It has all of the origional stuff from 2.4, so I just loaded all the new additions to that project. Nothing is tested, but at least thats out of the way.

http://www.mediafire.com/download.php?jymf02mtww1
Appreciate that
One last thing I wrote for the Game_Map class (I origionally wrote it into Event_Spawner, but is more defined now.)

This prints an events commands list, like so...

http://i224.photobucket.com/albums/dd28 ... ntList.png[/img]

I do have to do the parameters though, but here it is so far :P

$game_map.print_list(event_id) Show
class Game_Map
  #-----------------------------------------------------------------------------
  # * Print List
  #-----------------------------------------------------------------------------
  def print_list(event_id)
     list = String.new
     unless $game_map.events[event_id].nil?
        for c in $game_map.events[event_id].list
           code = c.code.to_s
           code.gsub!("0",    "")
           code.gsub!("101", "Show Text")
           code.gsub!("102", "Show Choices")
           code.gsub!("402", "When [**]")
           code.gsub!("403", "When Cancel")
           code.gsub!("103", "Input Number")
           code.gsub!("104", "Change Text Options")
           code.gsub!("105", "Button Input Processing")
           code.gsub!("106", "Wait")
           code.gsub!("111", "Conditional Branch")
           code.gsub!("411", "Else")
           code.gsub!("412", "Branch End")
           code.gsub!("112", "Loop")
           code.gsub!("413", "Repeat Above")
           code.gsub!("113", "Break Loop")
           code.gsub!("115", "Exit Event Processing")
           code.gsub!("116", "Erase Event")
           code.gsub!("117", "Call Common Event")
           code.gsub!("118", "Label")
           code.gsub!("119", "Jump to Label")
           code.gsub!("121", "Control Switches")
           code.gsub!("122", "Control Variables")
           code.gsub!("123", "Control Self Switch")
           code.gsub!("124", "Control Timer")
           code.gsub!("125", "Change Gold")
           code.gsub!("126", "Change Items")
           code.gsub!("127", "Change Weapons")
           code.gsub!("128", "Change Armor")
           code.gsub!("129", "Change Party Member")
           code.gsub!("131", "Change Windowskin")
           code.gsub!("132", "Change Battle BGM")
           code.gsub!("133", "Change Battle End ME")
           code.gsub!("134", "Change Save Access")
           code.gsub!("135", "Change Menu Access")
           code.gsub!("136", "Change Encounter")
           code.gsub!("201", "Transfer Player")
           code.gsub!("202", "Set Event Location")
           code.gsub!("203", "Scroll Map")
           code.gsub!("204", "Change Map Settings")
           code.gsub!("205", "Change Fog Color Tone")
           code.gsub!("206", "Change Fog Opacity")
           code.gsub!("207", "Show Animation")
           code.gsub!("208", "Change Transparent Flag")
           code.gsub!("209", "Set Move Route")
           code.gsub!("210", "Wait for Move's Completion")
           code.gsub!("221", "Prepare for Transition")
           code.gsub!("222", "Execute Transition")
           code.gsub!("223", "Change Screen Color Tone")
           code.gsub!("224", "Screen Flash")
           code.gsub!("225", "Screen Shake")
           code.gsub!("231", "Show Picture")
           code.gsub!("232", "Move Picture")
           code.gsub!("233", "Rotate Picture")
           code.gsub!("234", "Change Picture Color Tone")
           code.gsub!("235", "Erase Picture")
           code.gsub!("236", "Set Weather Effects")
           code.gsub!("241", "Play BGM")
           code.gsub!("242", "Fade Out BGM")
           code.gsub!("245", "Play BGS")
           code.gsub!("246", "Fade Out BGS")
           code.gsub!("247", "Memorize BGM/BGS")
           code.gsub!("248", "Restore BGM/BGS")
           code.gsub!("249", "Play ME")
           code.gsub!("250", "Play SE")
           code.gsub!("251", "Stop SE")
           code.gsub!("301", "Battle Processing")
           code.gsub!("601", "If Win")
           code.gsub!("602", "If Escape")
           code.gsub!("603", "If Lose")
           code.gsub!("302", "Shop Processing")
           code.gsub!("303", "Name Input Processing")
           code.gsub!("311", "Change HP")
           code.gsub!("312", "Change SP")
           code.gsub!("313", "Change State")
           code.gsub!("314", "Recover All")
           code.gsub!("315", "Change EXP")
           code.gsub!("316", "Change Level")
           code.gsub!("317", "Change Parameters")
           code.gsub!("318", "Change Skills")
           code.gsub!("319", "Change Equipment")
           code.gsub!("320", "Change Actor Name")
           code.gsub!("321", "Change Actor Class")
           code.gsub!("322", "Change Actor Graphic")
           code.gsub!("331", "Change Enemy HP")
           code.gsub!("332", "Change Enemy SP")
           code.gsub!("333", "Change Enemy State")
           code.gsub!("334", "Enemy Recover All")
           code.gsub!("335", "Enemy Appearance")
           code.gsub!("336", "Enemy Transform")
           code.gsub!("337", "Show Battle Animation")
           code.gsub!("338", "Deal Damage")
           code.gsub!("339", "Force Action")
           code.gsub!("340", "Abort Battle")
           code.gsub!("351", "Call Menu Screen")
           code.gsub!("352", "Call Save Screen")
           code.gsub!("353", "Game Over")
           code.gsub!("354", "Return to Title Screen")
           code.gsub!("355", "Script")
           code = ("   " * c.indent) + "@>" + code + ": "+c.parameters.to_s+"\n"
           list += code
        end
     end
     print list
  end
end
Expand to see the code.
This is a little thing that improves :hwnd, a method used in various scripts which require Win32API structures.  I personally made this to fix my mouse script.  It fixes the "bug" where anything that requires the method fails to work when you press F2 (which displays the frame rate).

  Findwindow    = Win32API.new('user32',    'FindWindowA',      %w(p p), 'l')
  Readini       = Win32API.new('kernel32',  'GetPrivateProfileStringA',
                               %w(p p p p l p), 'l')
  #--------------------------------------------------------------------------
  # * Find the game window and return it
  #--------------------------------------------------------------------------
  def self.hwnd
    # Finds Game Name
    game_name = "\0" * 256
    Readini.call('Game', 'Title', '', game_name, 255, ".\\Game.ini")
    game_name.delete!("\0")
    win = Findwindow.call('RGSS Player', game_name)
    if win == 0
      i = 0
      while i <= Graphics.frame_rate
        win = Findwindow.call('RGSS Player', game_name+' - '+i.to_s+' FPS')
        break if win != 0
        i += 1
      end
    end
    # Finds Window
    return win
  end
Expand to see the code.
mewsterus wrote:
This is a little thing that improves :hwnd, a method used in various scripts which require Win32API structures.   I personally made this to fix my mouse script.   It fixes the "bug" where anything that requires the method fails to work when you press F2 (which displays the frame rate).

  Findwindow     = Win32API.new('user32',      'FindWindowA',         %w(p p), 'l')
  Readini          = Win32API.new('kernel32',   'GetPrivateProfileStringA',
                                              %w(p p p p l p), 'l')
  #--------------------------------------------------------------------------
  # * Find the game window and return it
  #--------------------------------------------------------------------------
  def self.hwnd
     # Finds Game Name
     game_name = "\0" * 256
     Readini.call('Game', 'Title', '', game_name, 255, ".\\Game.ini")
     game_name.delete!("\0")
     win = Findwindow.call('RGSS Player', game_name)
     if win == 0
        i = 0
        while i <= Graphics.frame_rate
           win = Findwindow.call('RGSS Player', game_name+' - '+i.to_s+' FPS')
           break if win != 0
           i += 1
        end
     end
     # Finds Window
     return win
  end
Expand to see the code.

Actually, you need to obtain the hwnd index only once, so you can get it using the original name(Without the FPS) of the window when the game starts, so you can do something like this:
  Findwindow = Win32API.new('user32', 'FindWindowA', 'pp', 'l')
  Readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', 'pppplp', 'l')
  def self.hwnd
     if @hwnd.nil?
        game_name = "\0" * 256
        Readini.call('Game', 'Title', '', game_name, 255, ".\\Game.ini")
        game_name.delete!("\0")
        @hwnd = Findwindow.call('RGSS Player', game_name)
     else
        @hwnd
     end
  end
  self.hwnd
Expand to see the code.
@mew

Content Hidden Show
#--------------------------------------------------------------------------
  # * Get Screen Window Handle
  #--------------------------------------------------------------------------
  def Mouse.hwnd
    game_name = "\0" * 256
    Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l').call('Game','Title','',game_name,255,".\\Game.ini")
    game_name.delete!("\0")
    return Win32API.new('user32', 'FindWindowA', %w(p p), 'l').call('RGSS Player',game_name)
  end
Expand to see the code.


@vgvf,

isn't the handle changed if it is moved or something (not sure - never tried). Oh and not everyone uses that ReadIni ;)
@me, no, the window handles are assigned to each window when it is created, so it will never change.
Quote:
Oh and not everyone uses that ReadIni ;)
I just copied what mewsterus posted and edited it a little.
Ok so I've been using the MACL 2.1 and decided to update it to 2.3 and now I get an error on line 5523
Content Hidden Show
      if conditions[effect]
        # Call Method
        send(effect, *args)
      end
Expand to see the code.


Any idea's or should I just go back to 2.1 which didn't give me problems?
make a demo and tell me when the error occurs. I'll try and figure it out.
it happens before the game starts after you hit "test game" it goes to open the window and bam throws the error up. I'll update my game demo with it in there and make it unencrypted and PM you with it if you like
Me(tm) wrote:
@mew

Content Hidden Show
#--------------------------------------------------------------------------
  # * Get Screen Window Handle
  #--------------------------------------------------------------------------
  def Mouse.hwnd
    game_name = "\0" * 256
    Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l').call('Game','Title','',game_name,255,".\\Game.ini")
    game_name.delete!("\0")
    return Win32API.new('user32', 'FindWindowA', %w(p p), 'l').call('RGSS Player',game_name)
  end
Expand to see the code.


@vgvf,

isn't the handle changed if it is moved or something (not sure - never tried). Oh and not everyone uses that ReadIni ;)


The point of the code was to fix the F2 bug, which vgvgf did better than I did methinks. What you posted kind of backtracked over that fix...
I rewrote the Mouse Module based off Aleworks::API (yes, it should be MACL standard its fuckin' awesome), and checked my CPU and it used about 8-14% less (varies), probably because its using less memory by not redefining the constants in the module. A single module to handle all API is great, Aleworks does it just fine! Also, vgvgf is correct, set the 'hwnd' to an instance (if nil) then return that baby and frame rate got WAY better!

I also re-wrote your 'Mouse Selectable Windows' script, it runs pretty fast now. I like my version of the setup better, because you can individually enable/disable windows that use mouse via {'Window_XXX' => true/false, ...}, then Selectable_Objects.default = true/false to set all undefined windows mouse enabled.

'Modules.Mouse Module' Show
#==============================================================================
# ** Modules.Mouse Input (7.0)                     By Near Fantastica & SephirothSpawn
#------------------------------------------------------------------------------
# * Description :
#
#     The Mouse Input Module defines mouse input. It will retrieve the cursor
#     x and y position, as well as grid locations. This script updates
#     itself when the input module updates.
#------------------------------------------------------------------------------
# * Customization :
#
#     Turning Windows Cursor off when opening Game
#      - Hide_Mouse_Cursor = true (turn off) or false (leave alone)
#
#     Mouse triggers that cause Input triggers
#      - Mouse_to_Input_Triggers = { mouse_key => Input::KeyConstant, ... }
#------------------------------------------------------------------------------
# * Syntax :
#
#     Get Mouse Position :
#      - position = Mouse.position
#
#     Get Mouse Grid Position :
#      - grid_position = Mouse.grid
#
#     Trigger Status
#      - Mouse.trigger?
#
#     Repeat Status
#      - Mouse.repeat?
#==============================================================================

MACL::Loaded << 'Modules.Mouse Module'

#==============================================================================
# ** Mouse
#==============================================================================

module Mouse
  #--------------------------------------------------------------------------
  # * Include Aleworks::API module
  #--------------------------------------------------------------------------
  include Aleworks::API
  #--------------------------------------------------------------------------
  # * Show Windows Cursor Setting
  #--------------------------------------------------------------------------
  Hide_Mouse_Cursor = false
  #--------------------------------------------------------------------------
  # * 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
  #--------------------------------------------------------------------------
  FindWindowA     = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
  ShowCursor.call(Hide_Mouse_Cursor ? 0 : 1)
  @triggers       =     [[0, 1], [0, 2], [0, 4]]
  #--------------------------------------------------------------------------
  # * Mouse Grid Position
  #--------------------------------------------------------------------------
  def self.grid
     # Return Nil if Position is Nil
     return nil if @pos.nil?
     # Return X & Y Locations
     x = (@pos[0] + $game_map.display_x / 4) / 32
     y = (@pos[1] + $game_map.display_y / 4) / 32
     return [x, y]
  end
  #--------------------------------------------------------------------------
  # * Mouse X
  #--------------------------------------------------------------------------
  def self.x
     return position[0]
  end
  #--------------------------------------------------------------------------
  # * Mouse Y
  #--------------------------------------------------------------------------
  def self.y
     return position[1]
  end
  #--------------------------------------------------------------------------
  # * Moving Down?
  #--------------------------------------------------------------------------
  def self.moving_down?
     return (@last_y.nil? ? false : self.position[1] > @last_y)
  end
  #--------------------------------------------------------------------------
  # * Moving Up?
  #--------------------------------------------------------------------------
  def self.moving_up?
     return (@last_y.nil? ? false : self.position[1] < @last_y)
  end
  #--------------------------------------------------------------------------
  # * Moving Left?
  #--------------------------------------------------------------------------
  def self.moving_left?
     return (@last_x.nil? ? false : self.position[0] < @last_x)
  end
  #--------------------------------------------------------------------------
  # * Moving Right?
  #--------------------------------------------------------------------------
  def self.moving_right?
     return (@last_x.nil? ? false : self.position[0] > @last_x)
  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 GetCursorPos.call(pos) == 0 ? nil : pos.unpack('ll')
  end
  #--------------------------------------------------------------------------
  # * Mouse Position
  #--------------------------------------------------------------------------
  def self.pos
     # Gets X & Y Position
     x, y = self.screen_to_client(*self.global_pos)
     # Gets Width & Height of Game Window
     width, height = self.client_size
     # Begins Test
     begin
        # Return X & Y or Nil Depending on Mouse Position
        if (x >= 0 && y >= 0 && x < width && y < height)
           return x, y
        end
        return nil
     rescue
        # Return nil
        return nil
     end
  end
  #--------------------------------------------------------------------------
  # * Update Mouse Position
  #--------------------------------------------------------------------------
  def self.update
     # Update Position
     @pos = self.pos
     # Update Triggers
     for i in @triggers
        # Gets Async State
        n = GetAsyncKeyState.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
     @last_x, @last_y = self.position[0], self.position[1]
  end
  #--------------------------------------------------------------------------
  # * Trigger?
  #        id : 0:Left, 1:Right, 2:Center
  #--------------------------------------------------------------------------
  def self.trigger?(id = 0)
     return @triggers[id][0] == 1
  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, y)
     # Return nil if X & Y empty
     return nil unless x and y
     # Pack X & Y
     pos = [x, y].pack('ll')
     # Return Unpacked Position or Nil
     return ScreenToClient.call(self.window, pos) == 0 ? nil : pos.unpack('ll')
  end
  #--------------------------------------------------------------------------
  # * Hwnd
  #--------------------------------------------------------------------------
  def self.window
     if @game_window.nil?
        # Finds Game Name
        game_name = "\0" * 256
        GPPSA.call('Game', 'Title', '', game_name, 255, ".\\Game.ini")
        game_name.delete!("\0")
        # Finds Window
        @game_window = FindWindowA.call('RGSS Player', game_name)
     end
     return @game_window
  end
  #--------------------------------------------------------------------------
  # * Client Size
  #--------------------------------------------------------------------------
  def self.client_size
     # Packs Empty Rect
     rect = [0, 0, 0, 0].pack('l4')
     # Gets Game Window Rect
     GetClientRect.call(self.window, 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
Expand to see the code.


'Mouse Selectables' Show
#===============================================================================
# ** Mouse Selectables
#-------------------------------------------------------------------------------
# Revised by  : SephirothSpawn / Lambchop / Kain Nobel
# Version       : 2.5
# Last Update : 11.10.2008
#===============================================================================
#-------------------------------------------------------------------------------
# * SDK Log Script
#-------------------------------------------------------------------------------
SDK.log('Mouse Selectable Windows', 'MACL Authors', 2.5, '11.10.2008')
SDK.check_requirements(2.0, [], {'Method & Class Library' => 2.1})

#-------------------------------------------------------------------------------
# * Begin SDK Enable Test
#-------------------------------------------------------------------------------
if SDK.enabled?('Mouse Selectable Windows')

#===============================================================================
# ** Mouse
#-------------------------------------------------------------------------------
#     This module contains extra constants for selectable windows.
#===============================================================================

module Mouse
  #-----------------------------------------------------------------------------
  # * Selectable_Objects
  #-----------------------------------------------------------------------------
  Selectable_Objects = {
     'Window_PartyMain'      => false,
     'Window_PartyReserve' => false
  }
  Selectable_Objects.default = true
  #-----------------------------------------------------------------------------
  # * Selectable_Padding
  #-----------------------------------------------------------------------------
  Selectable_Padding = {}
  Selectable_Padding.default = 16
  #-----------------------------------------------------------------------------
  # * Selectable_Switch
  #-----------------------------------------------------------------------------
  Selectable_Key = Keys::N0
end

#===============================================================================
# ** Window_Selectable
#-------------------------------------------------------------------------------
#     This class has been enhanced to utilizes the mouse to handle selections.
#===============================================================================

class Window_Selectable < Window_Base
  #-----------------------------------------------------------------------------
  # * Public Instance Variables
  #-----------------------------------------------------------------------------
  attr_accessor :mouse_enabled
  #-----------------------------------------------------------------------------
  # * Alias Listings
  #-----------------------------------------------------------------------------
  alias_method :mouse_win_select_initialize,   :initialize
  alias_method :mouse_win_select_update,         :update
  #-----------------------------------------------------------------------------
  # * Mouse Enabled?
  #-----------------------------------------------------------------------------
  def mouse_enabled?
     if @mouse_enabled.nil?
        @mouse_enabled = Mouse::Selectable_Objects[self.class.to_s] == true
     end
     return @mouse_enabled == true
  end
  #-----------------------------------------------------------------------------
  # * Mouse Padding
  #-----------------------------------------------------------------------------
  def mouse_padding
     return Mouse::Selectable_Padding[self.class.to_s]
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
     if Input.trigger?(Mouse::Selectable_Key)
        self.mouse_enabled = !self.mouse_enabled?
        return
     end
     if self.mouse_enabled? && self.active && @item_max > 0 && @index >= 0
        mx, my = *Mouse.position
        if mx.between?(self.x, self.x + self.width) &&
        my.between?(self.y, self.y + self.height)
           mx -= (self.x + self.mouse_padding) ; my -= (self.y + self.mouse_padding)
           for i in 0...@item_max
              x = i % @column_max * (cursor_width + 32)
              y = i / @column_max * cursor_height - self.oy
              if mx.between?(x, x + cursor_width) &&
                   my.between?(y, y + cursor_height)
                 @index = i
                 break
              end
           end
        end
     end
     mouse_win_select_update
  end
end

#===============================================================================
# ** Arrow_Enemy
#-------------------------------------------------------------------------------
#     ...
#===============================================================================

class Arrow_Base < Sprite
  #-----------------------------------------------------------------------------
  # * Alias Listings
  #-----------------------------------------------------------------------------
  alias_method :mouse_arrow_base_update, :update
  #-----------------------------------------------------------------------------
  # * Mouse Enabled?
  #-----------------------------------------------------------------------------
  def mouse_enabled?
     if @mouse_enabled.nil?
        @mouse_enabled = Mouse::Selectable_Objects[self.class.to_s] == true
     end
     return @mouse_enabled == true
  end
  #-----------------------------------------------------------------------------
  # * Update
  #-----------------------------------------------------------------------------
  def update
     mouse_arrow_base_update
     update_mouse($game_troop.enemies) if self.is_a?(Arrow_Enemy)
     update_mouse($game_party.actors)   if self.is_a?(Arrow_Actor)
  end
  #-----------------------------------------------------------------------------
  # * Update Mouse
  #-----------------------------------------------------------------------------
  def update_mouse(battlers)
     if self.mouse_enabled?
        mx, my = *Mouse.position
        for index in 0...battlers.size
           battler = battlers[index]
           bitmap = RPG::Cache.battler(battler.battler_name, 0)
           width, height = bitmap.width, bitmap.height
           x, y = (battler.screen_x - width / 2), (battler.screen_y - height)
           if mx.between?(x, x + width) && my.between?(y, y + height)
              break if @index == index
              @index = index
              $game_system.se_play($data_system.cursor_se)
              break
           end
        end
     end
  end
end

#-------------------------------------------------------------------------------
# * SDK Enabled Test - END
#-------------------------------------------------------------------------------
end
Expand to see the code.


EDIT: I just made another feature for it, I'll update it tonight/tomorrow, but now you can set scene-based cursors (for instance, set "001-Weapon01" for Scene_Battle and "Mouse" for default scenes) via Hash constant. I'm gonna make a Window-based setting constant for it too before I post it maybe. Also gotta keep in mind Arrow_Actor, Arrow_Enemy, events, etc... I'll figure it out, hopefully I can keep it simple.
I have some work on class Hash.  No comments, unfortunately.  This allows you to sort Hashes and have them evaluate as sorted via :each, :each_key, and :each_value (:each_pair is untouched):

class Hash
  alias_method :meu_hash_clear, :clear
  def sort
    begin
      sorted = super {|a, b| yield(a[0], a[1], b[0], b[1])}
    rescue LocalJumpError
      sorted = super
    end
    output = {}
    sorted.each {|ar| output.set(ar[0], ar[1])}
    return output
  end
  def sort!
    begin
      sorted = self.sort {|k1, v1, k2, v2| yield(k1, v1, k2, v2)}
    rescue LocalJumpError
      sorted = self.sort
    end
    self.clear
    sorted.each {|key, value| self.set(key, value)}
    return self
  end
  def set(key, value)
    key_order.push(key) unless self.has_key?(key)
    self[key] = value
  end
  def each
    key_order.each {|key| yield(key, self[key])}
  end
  def each_key
    key_order.each {|key| yield(key)}
  end
  def each_value
    key_order.each {|key| yield(self[key])}
  end
  def key_order
    @key_order = self.keys if @key_order == nil
    return @key_order
  end
  def clear
    meu_hash_clear
    @key_order = self.keys
  end
  def to_s
    series = '{'
    # Run Through Each Item with index
    each do |key, value|
      series += ', ' unless series == '{'
      # Add String to Series
      series += key.to_s + ' => ' + value.to_s
    end
    series += '}'
    return series
  end
end
Expand to see the code.


Also, at the end is a nifty :to_s method based off of Array.series_string.
I don't really like the idea of changing the Hash to being sorted. At least not the general class being sorted.
I am pretty sure they are currently being placed in a red-black tree accordingly to their hash-values. (Object.hash)

I suggest you create a SortedHash subclass of the Hash class since having the sorted property is by no means requires for the general hash. I know you'll lose some syntactic sugar on this, but I really think this is a better style since a Hash represents an unsorted mapping from one object to another.

*hugs*
- Zeriab
How about this then?  It still adds the :sort method to Hash, but that method returns a SortedHash instead of a Hash.  Hash.sort! has been taken out, although it's still in SortedHash (I felt like it, even though with type uncertainties it's unlikely to get good use).  I still get to use all my sugar since I can declare a hash and get a SortedHash with :sort, rather than needing to specifically declare a SortedHash first.

I added comments too:
#==============================================================================
# ** Hash   
#==============================================================================

class Hash
  #--------------------------------------------------------------------------
  # * Sort the hash according to |k1, v1, k2, v2| and return a SortedHash
  #--------------------------------------------------------------------------
  def sort
    # Pass the block to Enumerable.sort
    begin
      sorted = super {|a, b| yield(a[0], a[1], b[0], b[1])}
    rescue LocalJumpError # If no block was provided
      sorted = super
    end
    # Initialize the output object
    output = SortedHash.new
    # Set each key in order
    sorted.each {|ar| output[ar[0]] = ar[1]}
    return output
  end
  #--------------------------------------------------------------------------
  # * Turn the hash into a string "{key => value, key => value}"
  #--------------------------------------------------------------------------
  def to_s
    series = '{'
    # Run Through Each Item with index
    each do |key, value|
      series += ', ' unless series == '{'
      # Add String to Series
      series += key.to_s + ' => ' + value.to_s
    end
    series += '}'
    return series
  end
end

#==============================================================================
# ** Sorted Hash   
#==============================================================================

class SortedHash < Hash
  #--------------------------------------------------------------------------
  # * Create the hash; initialize @key_order
  #--------------------------------------------------------------------------
  def initialize(*args)
    super
    @key_order = self.keys
  end
  #--------------------------------------------------------------------------
  # * Sort the hash according to |k1, v1, k2, v2| and return self
  #--------------------------------------------------------------------------
  def sort!
    # Pass the block to Enumerable.sort
    begin
      sorted = super {|a, b| yield(a[0], a[1], b[0], b[1])}
    rescue LocalJumpError # If no block was provided
      sorted = super
    end
    # Clear existing entries and sorted order
    self.clear
    # Set each key in order
    sorted.each {|ar| self[ar[0]] = ar[1]}
    return self
  end
  #--------------------------------------------------------------------------
  # * Set a value in the hash; add the key to the sort order if it is unique
  #--------------------------------------------------------------------------
  def []=(key, value)
    key_order.push(key) unless self.has_key?(key)
    super
  end
  #--------------------------------------------------------------------------
  # * Run a block on keys and values in the sorted order
  #--------------------------------------------------------------------------
  def each
    key_order.each {|key| yield(key, self[key])}
  end
  #--------------------------------------------------------------------------
  # * Run a block on keys only in the sorted order
  #--------------------------------------------------------------------------
  def each_key
    key_order.each {|key| yield(key)}
  end
  #--------------------------------------------------------------------------
  # * Run a block on values only in the sorted order
  #--------------------------------------------------------------------------
  def each_value
    key_order.each {|key| yield(self[key])}
  end
  #--------------------------------------------------------------------------
  # * Returns an array of keys in the sorted order
  #--------------------------------------------------------------------------
  def key_order
    @key_order = [] if @key_order == nil
    return @key_order
  end
  #--------------------------------------------------------------------------
  # * Return an array of keys in the sorted order
  #--------------------------------------------------------------------------
  def keys
    return key_order
  end
  #--------------------------------------------------------------------------
  # * Return an array of values in the sorted order
  #--------------------------------------------------------------------------
  def values
    vals = []
    key_order.each {|key| vals.push(self[key])}
    return vals
  end
  #--------------------------------------------------------------------------
  # * Clear the hash and its sorted order
  #--------------------------------------------------------------------------
  def clear
    super
    @key_order = self.keys
  end
end
Expand to see the code.
I have a simple bitmap negative effect, but it's very slow when the bitmap's more than 100x100.
Anyone has an idea how to improve this?

class Bitmap
  def negative
     for i in 0...(self.width)
        for j in 0...(self.height)
           pix = self.get_pixel(i, j)
           pix.red = (pix.red - 255) * -1
           pix.blue = (pix.blue - 255) * -1
           pix.green = (pix.green - 255) * -1
           self.set_pixel(i, j, pix)
        end
     end
  end
end
Expand to see the code.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=9417