The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Helios on February 15, 2010, 04:20:55 PM

Title: Need Help Editing a Script
Post by: Helios on February 15, 2010, 04:20:55 PM
I'm not an English-mind so sorry for my bad grammer.

This is the original script made by scripter MoMo from Japan. The script will auto-equip a "default" weapon when you remove your hero's equipped weapon. Works flawlessly.

[spoiler]module MoMo_No_Weapon_Equip
  # ???????ID
  # weapon_id[????ID] = ??ID
  weapon_id = []
  weapon_id[0] = 2 # ??????(?????????????)
  weapon_id[1] = 3
 
  NO_WEAPON_ID = weapon_id
 
  module_function
  def get_no_weapon_id(actor_id)
    if NO_WEAPON_ID[actor_id] == nil
      return NO_WEAPON_ID[0]
    end
    return NO_WEAPON_ID[actor_id]
  end
end
class Game_Actor < Game_Battler
  alias game_actor_no_weapon_equip_initialize initialize
  def initialize(actor_id)
    game_actor_no_weapon_equip_initialize(actor_id)
    @no_weapon_id = MoMo_No_Weapon_Equip.get_no_weapon_id(actor_id)
  end
  alias game_actor_no_weapon_equip_equip equip
  def equip(equip_type, id)
    wep_id = @weapon_id
    if equip_type == 0
      id = 0 if id == @no_weapon_id
      game_actor_no_weapon_equip_equip(equip_type, id)
      @weapon_id = @no_weapon_id if @weapon_id == 0
      $game_party.lose_weapon(@no_weapon_id, 1) if wep_id == @no_weapon_id
    else
      game_actor_no_weapon_equip_equip(equip_type, id)
    end
  end
end
[/spoiler]


And I'm trying to make it work for armor too.
The result is as follows:

[spoiler]
module MoMo_No_armor3_Equip
  # ???????ID
  # weapon_id[????ID] = ??ID
  armor_id = []
  armor_id[0] = 2 # ??????(?????????????)
  armor_id[1] = 3
 
  NO_ARMOR3_ID = armor_id
 
  module_function
  def get_no_armor3_id(actor_id)
    if NO_ARMOR3_ID[actor_id] == nil
      return NO_ARMOR3_ID[0]
    end
    return NO_ARMOR3_ID[actor_id]
  end
end
class Game_Actor < Game_Battler
  alias game_actor_no_armor3_equip_initialize initialize
  def initialize(actor_id)
    game_actor_no_armor3_equip_initialize(actor_id)
    @no_armor3_id = MoMo_No_armor3_Equip.get_no_armor3_id(actor_id)
  end
  alias game_actor_no_armor3_equip_equip equip
  def equip(equip_type, id)
    ar3_id = @armor3_id
    if equip_type == 0
      id = 0 if id == @no_armor3_id
      game_actor_no_armor3_equip_equip(equip_type, id)
      @armor3_id = @no_armor3_id if @armor3_id == 0
      $game_party.lose_armor(@no_armor3_id, 1) if ar3_id == @no_armor3_id
    else
      game_actor_no_armor3_equip_equip(equip_type, id)
    end
  end
end
[/spoiler]

It "worked" in a strange way...the "default" armor only appear when I change my WEAPON, not armor.

Could someone help me please?
Title: Re: Need Help Editing a Script
Post by: modern algebra on February 15, 2010, 04:30:18 PM
Keeping in mind that I haven't looked at RMXP for a long time, I think your problem is that you are only running the appropriate part of the method when equipping a weapon:


    if equip_type == 0


If equip_type is 0, it means you are equipping a weapon. If you changed that to the appropriate type (by memory: 0 => Weapon, 1 => Shield, 2 => Head, 3 => Body, 4 => Accessory), then it would run when you want it to. Judging by your naming, you want it to be body armor, so try doing it with

if equip_type == 3
Title: Re: Need Help Editing a Script
Post by: Helios on February 16, 2010, 06:45:05 AM
Yes it worked! Thanks for your help :D