03-03-2008, 06:14 AM
Two-Handed Weapons
by RPG Advocate
saved from Phylomortis.Com
by RPG Advocate
saved from Phylomortis.Com
This script adds functionality for two-handed weapons. When a two-handed weapon is equipped, the equipped shield will be unequipped. When a shield is equipped while a two-handed weapon is equipped, the weapon will be unequipped. The stat changes shown in the left window reflect this. Additionally, this script makes it so that the weapon or shield that will be unequipped is shown in a partially transparent color. To declare a weapon as two-handed, add its ID number to the "$game_system.two_handed_weapons" array.
Note: If simply copied as directed, this script will mess up the Advanced Equip Window script. This script can be used with the Advanced Equip Window script, but you will need some understanding of how the code works in order to know how to merge thetwo together. It is your responsibility to understand this, so please don't bug me about it
Script
Two-Handed Weapons
Code:
# Two-Handed Weapons
# by RPG Advocate
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# This class handles data surrounding the system. Backround music, etc.
# is managed here as well. Refer to "$game_system" for the instance of
# this class.
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :two_handed_weapons # array of two-handed weapons
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias twohanded_initialize initialize
def initialize
twohanded_initialize
@two_handed_weapons = []
end
end
#==============================================================================
# ** Window_EquipRight
#------------------------------------------------------------------------------
# This window displays items the actor is currently equipped with on the
# equipment screen.
#==============================================================================
class Window_EquipRight < Window_Selectable
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :translucent_text
#--------------------------------------------------------------------------
# * Object Initialization
# actor : actor
#--------------------------------------------------------------------------
alias twoh_initialize initialize
def initialize(actor)
@translucent_text = [false, false]
twoh_initialize(actor)
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
alias twoh_refresh refresh
def refresh
# Perform the original call
twoh_refresh
draw_item_name(@data[0], 92, 32 * 0, @translucent_text[0])
draw_item_name(@data[1], 92, 32 * 1, @translucent_text[1])
draw_item_name(@data[2], 92, 32 * 2, false)
draw_item_name(@data[3], 92, 32 * 3, false)
draw_item_name(@data[4], 92, 32 * 4, false)
end
#--------------------------------------------------------------------------
# * Draw Item Name
# item : item
# x : draw spot x-coordinate
# y : draw spot y-coordinate
# translucent : translucent
#--------------------------------------------------------------------------
def draw_item_name(item, x, y, translucent = true)
if item == nil
return
end
bitmap = RPG::Cache.icon(item.icon_name)
if translucent
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), 128)
self.contents.font.color = disabled_color
else
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
self.contents.font.color = normal_color
end
self.contents.draw_text(x + 28, y, 212, 32, item.name)
end
end
#==============================================================================
# ** Scene_Equip
#------------------------------------------------------------------------------
# This class performs equipment screen processing.
#==============================================================================
class Scene_Equip
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
alias twoh_refresh refresh
def refresh
# The original call
twoh_refresh
# Get currently equipped item
item1 = @right_window.item
# If item window is active
if @item_window.active
# Get currently selected item
item2 = @item_window.item
item3 = @actor.armor1_id
item4 = @actor.weapon_id
# Change equipment
last_hp = @actor.hp
last_sp = @actor.sp
w = item2.id
if item2.is_a?(RPG::Weapon) && $game_system.two_handed_weapons.include?(w)
@right_window.translucent_text = [false, true]
@right_window.refresh
@actor.equip(1, 0)
end
if item2.is_a?(RPG::Armor) && item2.kind == 0 &&
$game_system.two_handed_weapons.include?(@actor.weapon_id)
@right_window.translucent_text = [true, false]
@right_window.refresh
flag = true
@actor.equip(0, 0)
end
# Get parameters for after equipment change
new_atk = @actor.atk
new_pdef = @actor.pdef
new_mdef = @actor.mdef
# Return equipment
@actor.equip(@right_window.index, item1 == nil ? 0 : item1.id)
if item2.is_a?(RPG::Weapon) && $game_system.two_handed_weapons.include?(w)
@actor.equip(1, item3)
end
if item2.is_a?(RPG::Armor) && item2.kind == 0 && flag
@actor.equip(0, item4)
end
@actor.hp = last_hp
@actor.sp = last_sp
# Draw in left window
@left_window.set_new_parameters(new_atk, new_pdef, new_mdef)
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
alias twoh_update update
def update
# If item_window value is changed
if @item_window.index != @old_index
@right_window.translucent_text = [false, false]
@right_window.refresh
end
@old_index = @item_window.index
# Perform the original call
twoh_update
end
#--------------------------------------------------------------------------
# * Frame Update (when item window is active)
#--------------------------------------------------------------------------
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)
# Obtain id of item selected
w = item.id
# If two-handed weapon selected, equip weapon remove shield
if item.is_a?(RPG::Weapon) && $game_system.two_handed_weapons.include?(w)
@actor.equip(1, 0)
end
# if shield selected and two-handed equipped, remove two-handed weapon
if item.is_a?(RPG::Armor) && item.kind == 0 &&
$game_system.two_handed_weapons.include?(@actor.weapon_id)
@actor.equip(0, 0)
end
# 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
# Refresh item windows
@item_window1.refresh
@item_window2.refresh
return
end
end
end