The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: blazinhandle on January 15, 2008, 12:18:39 AM

Title: Modifying Module RPG: Weapon
Post by: blazinhandle on January 15, 2008, 12:18:39 AM
I'm trying to modify the Weapon Class so that I can add an sp_plus statistic to each weapon but do not know how to go about it.

I tried something like this but to no avail:

[spoiler]module RPG
  class Weapon
    attr_accessor :maxsp
    def setup_additional_stats
      @maxsp = 0
      case @id
      when 1
        @maxsp = 5
      end
    end
  end
end
class Game_Temp
  alias setup initialize
  def initialize
    setup
    for weapon in $data_weapons
      weapon.setup_additional_stats
    end
  end
end
[/spoiler]
Title: Re: Modifying Module RPG: Weapon
Post by: Falcon on January 15, 2008, 12:26:33 AM
Strike 1, wrong forum.
http://rmrk.net/index.php/topic,19774.0.html

For starters, you're not aliasing the initialize method, which would most likely cause your error.
Title: Re: Modifying Module RPG: Weapon
Post by: modern algebra on January 22, 2008, 08:40:10 PM
Here's how I went about adding a statistic when I needed to. First, I went into the database and stole Zeriab's module addon: http://rmrk.net/index.php/topic,21582.0.html

Then (and this might not be the best way to do it), I wrote in the additional stats like this:

attr_sec_accessor :hp_plus, 'get_additional_stats (0)'
attr_sec_accessor :sp_plus, 'get_additional_stats (1)'


and then I wrote a method in the class like this:


def get_additional_stats (parameter)
  case @id
  when 0 # Bronze Sword
    hp_add = XX
    sp_add = YY
    return [hp_add, sp_add][parameter]
  when 1 # ETC...
  end
  return 0
end


You could do that for as many stats as you want to, but like I said, it might not be the best way; it's just the way I did it.
Title: Re: Modifying Module RPG: Weapon
Post by: Zeriab on January 23, 2008, 01:51:13 AM
Could this script perhaps do what you are looking for? http://rmrk.net/index.php/topic,18159.0.html
Either way you can also choose modern's solution ^_^