The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: Lytanathan on October 07, 2010, 06:23:48 AM

Title: Key Equipment Removal by Lytanathan
Post by: Lytanathan on October 07, 2010, 06:23:48 AM
I've lurked on this forum long enough, it's time I actually contribute something. Thus:

Key Equipment Removal
Version: 1.0
Author: Lytanathan

Description

Basically, all this script does is remove weapons or armor with a price of 0 from an actor before the actor is removed from your party. This could be useful if you have a piece of equipment that acts as a key item in your game, and there is the potential that a character may have it equipped when he or she leaves your party for any reason. It would not be good to find yourself in a dungeon, only to discover that your cleric had the Staff of Power equipped when she was kidnapped, and you needed it to open the sealed door barring the way to rescue her, now would it?

Instructions

Simply copy and paste the script above Main and below Materials in the Script Editor. No configuration in the code is necessary.
To make a weapon or armor that is unequipped when an actor is removed from the party, simply make it unsellable (set the price to 0)

Code: [Select]
#==============================================================================
# Key Equipment Removal by Lytanathan
# -----------------------------------------------------------------------------
# If you have any equipment that is unsellable (aka equippable key items), you
# probably don't want the player to lose the item if an actor is removed from
# your party. This script overrides the remove_actor function of Game_Party so
# that any weapon or armor with a price of 0 is removed from the actor before
# he/she/it is removed from the party.
# -----------------------------------------------------------------------------
# Instructions
# -----------------------------------------------------------------------------
# Copy and paste this script into the Script Editor above Main and below
# Materials.
# To make a weapon or armor that is unequipped when an actor is removed, assign
# its price to 0 (make it unsellable).
# -----------------------------------------------------------------------------
# Compatability
# -----------------------------------------------------------------------------
# I haven't done a lot of testing on this script, other than to see if it works.
# Compatibility problems may occur, especially with scripts that change the
# party or the equipment systems.
#==============================================================================

class Game_Party < Game_Unit

  #--------------------------------------------------------------------------
  # * Remove Actor
  #     actor_id : actor ID
  #--------------------------------------------------------------------------
  def remove_actor(actor_id)

    for i in 0..$game_actors[actor_id].equips.size
      if $game_actors[actor_id].equips[i] != nil
        if $game_actors[actor_id].equips[i].price == 0
          $game_actors[actor_id].change_equip(i, nil)
        end
      end
    end
   
    @actors.delete(actor_id)
    $game_player.refresh
  end
 
end

Potential Issues

I haven't done a lot of testing on this script, other than to see if it works. Compatibility problems may occur, especially with scripts that change the party or the equipment systems.

Credit

Lytanathan
Title: Re: Key Equipment Removal by Lytanathan
Post by: cozziekuns on October 07, 2010, 11:15:29 PM
This looks like a cool script.  The only thing that I would recommend is using the equips definition instead of making your own array, which is more efficient and would be more compatible with custom equipment scripts. Also, instead of the 0..4, you should use 0..@item.size. But these are just small nitpicks.
Title: Re: Key Equipment Removal by Lytanathan
Post by: Lytanathan on October 11, 2010, 06:47:52 PM
Thanks for the advice! Pretty much cut the code in half, and it still works!
As you could probably tell, I'm not a very good scripter yet. But I'm working on it!