Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: craud on November 01, 2012, 03:29:04 am

Title: [XP] Need to force equipment list to update.
Post by: craud on November 01, 2012, 03:29:04 am
Hi,

I'm currently working a system where a character's class is determined by their "accessory" equipment. I did this very simply by adding:

@actor.class_id = @actor.armor4_id + 1


To the section of Scene_Equip headed "Frame Update (when item window is active)". This works in the sense that your class alters based on the accessory you have equipped (no accessory means class #1, accessory #1 means class #2 etc.) and it removes incompatible equipment. However, the list of what equipment is newly available doesn't itself update until you've equipped and de-equipped another item.

eg. If a character is a Knight and they have a sword, then they equip the Wizard class which uses staffs but not swords, the sword will be removed but the staff won't appear as an equippable item until you equip and then de-equip something else, at which point it appears normally.

I know I need to force the game to refresh or update something once you equip an item, I'm just not sure what or how to go about it.

For reference, here's the section of Scene_Equip which I altered, showing where the new line was added.

def update_item
   # If B button was pressed
   if Input.trigger?(Input::B)
     # Play cancel SE
     $game_system.se_play($data_system.cancel_se)
     # Activate right window
     @right_window.active = true
     @item_window.active = false
     @item_window.index = -1
     return
   end
   # If C button was pressed
   if Input.trigger?(Input::C)
     # Play equip SE
     $game_system.se_play($data_system.equip_se)
     # Get currently selected data on the item window
     item = @item_window.item
     # Change equipment
     @actor.equip(@right_window.index, item == nil ? 0 : item.id)
     @actor.class_id = @actor.armor4_id + 1
     # Activate right window
     @right_window.active = true
     @item_window.active = false
     @item_window.index = -1
     # Remake right window and item window contents
     @right_window.refresh
     @item_window.refresh
     return
   end


Thanks to anyone who can help.
Title: Re: [XP] Need to force equipment list to update.
Post by: G_G on November 01, 2012, 06:03:09 am
You have to refresh every window item.
Replace these lines
      @actor.equip(@right_window.index, item == nil ? 0 : item.id)
      @actor.class_id = @actor.armor4_id + 1

With this
      old_armor4 = @actor.armor4_id
      @actor.equip(@right_window.index, item == nil ? 0 : item.id)
      if @actor.armor4_id != old_armor4
          @actor.class_id = @actor.armor4_id + 1
          @item_window1.refresh
          @item_window2.refresh
          @item_window3.refresh
          @item_window4.refresh
          @item_window5.refresh
      end
Title: Re: [XP] Need to force equipment list to update.
Post by: craud on November 09, 2012, 03:53:13 am
Thanks! (Sorry for late reply; yay thesis)