MarkDarkness
Member
Hey, everyone... I'm trying to use this automatic weapon optimization script by RPG Advocate, but it is failing to work in a very strange way: it only carries on with the optimization if the input is assigned to either button B or button C, which of course binds the command to the same keys as ACCEPT and CANCEL. Anybody knows what is going on here? You can search for if Input.trigger?(Input::Y) to go straight to the problematic line.
Do I need any further code?
Also, if it's not too much trouble, can anybody tell me how I'd go about using one of those "keyboard keys extensor" scripts and assigning this command to the letter "O"?
Do I need any further code?
Also, if it's not too much trouble, can anybody tell me how I'd go about using one of those "keyboard keys extensor" scripts and assigning this command to the letter "O"?
Code:
#==============================================================================
# Automatic Equipment Optimization by RPG Advocate
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :cursed_weapons # array of cursed weapons
attr_accessor :cursed_armors # array of cursed armors
attr_accessor :two_handed_weapons # array of two-handed weapons
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias aeo_init initialize
def initialize
aeo_init
# Create empty arrays to prevent errors (unless already created/filled)
@cursed_weapons = [] if @cursed_weapons == nil
@cursed_armors = [] if @cursed_armors == nil
@two_handed_weapons = [] if @two_handed_weapons == nil
end
end
class Scene_Equip
WEAPON_ATK_WEIGHT = 1.0
WEAPON_PDF_WEIGHT = 0.25
WEAPON_MDF_WEIGHT = 0.25
WEAPON_STR_WEIGHT = 0.75
WEAPON_DEX_WEIGHT = 0.75
WEAPON_AGI_WEIGHT = 0.50
WEAPON_INT_WEIGHT = 0.50
ARMOR_PDF_WEIGHT = 1.0
ARMOR_MDF_WEIGHT = 0.75
ARMOR_STR_WEIGHT = 0.50
ARMOR_DEX_WEIGHT = 0.50
ARMOR_AGI_WEIGHT = 0.25
ARMOR_INT_WEIGHT = 0.25
ARMOR_EVA_WEIGHT = 0.10
NO_ACCESSORY_OPTIMIZATION = false
#--------------------------------------------------------------------------
# * Frame Update (when right window is active)
#--------------------------------------------------------------------------
alias aeo_update_right update_right
def update_right
# Perform the original call
aeo_update_right
# If Y button was pressed
if Input.trigger?(Input::Y)
# Play decision SE
$game_system.se_play($data_system.decision_se)
optimize(0)
optimize(1)
optimize(2)
optimize(3)
optimize(4)
@left_window.refresh
@right_window.refresh
@item_window1.refresh
@item_window2.refresh
@item_window3.refresh
@item_window4.refresh
@item_window5.refresh
return
end
end
#--------------------------------------------------------------------------
# * Optimize Equipment
# slot : equipment slot
#--------------------------------------------------------------------------
def optimize(slot)
if slot == 0
# Prevent weapon switch on cursed weapons
if $game_system.cursed_weapons.include?(@actor.weapon_id)
return
end
object = $data_weapons[@actor.weapon_id]
optimal = object.id
current = 0.00
if @actor.weapon_id != 0
current += object.atk * WEAPON_ATK_WEIGHT
current += object.pdef * WEAPON_PDF_WEIGHT
current += object.mdef * WEAPON_MDF_WEIGHT
current += object.str_plus * WEAPON_STR_WEIGHT
current += object.dex_plus * WEAPON_DEX_WEIGHT
current += object.agi_plus * WEAPON_AGI_WEIGHT
current += object.int_plus * WEAPON_INT_WEIGHT
else
optimal = 0
end
max_eval = current
@actor.equip(0, 0)
flag = false
zero_flag = true
for weapon in $data_weapons
if !flag
flag = true
next
end
evaluation = 0.00
evaluation += weapon.atk * WEAPON_ATK_WEIGHT
evaluation += weapon.pdef * WEAPON_PDF_WEIGHT
evaluation += weapon.mdef * WEAPON_MDF_WEIGHT
evaluation += weapon.str_plus * WEAPON_STR_WEIGHT
evaluation += weapon.dex_plus * WEAPON_DEX_WEIGHT
evaluation += weapon.agi_plus * WEAPON_AGI_WEIGHT
evaluation += weapon.int_plus * WEAPON_INT_WEIGHT
if evaluation > 0
zero_flag = false
end
if @actor.equippable?(weapon) &&
$game_party.weapon_number(weapon.id) > 0 && evaluation > max_eval
max_eval = evaluation
optimal = weapon.id
end
end
if zero_flag
optimal = 0
end
@actor.equip(0, optimal)
if $game_system.two_handed_weapons.include?(optimal)
@actor.equip(1, 0)
end
end
if slot >= 1
not_equipped = false
case slot
when 1
if $game_system.two_handed_weapons.include?(@actor.weapon_id)
return
end
if @actor.armor1_id == 0
not_equipped = true
else
object = $data_armors[@actor.armor1_id]
end
when 2
if @actor.armor2_id == 0
not_equipped = true
else
object = $data_armors[@actor.armor2_id]
end
when 3
if @actor.armor3_id == 0
not_equipped = true
else
object = $data_armors[@actor.armor3_id]
end
when 4
if NO_ACCESSORY_OPTIMIZATION
return
end
if @actor.armor4_id == 0
not_equipped = true
else
object = $data_armors[@actor.armor4_id]
end
end
optimal = object.id
if $game_system.cursed_armors.include?(optimal)
return
end
current = 0.00
if not_equipped = false
current += object.eva * ARMOR_EVA_WEIGHT
current += object.pdef * ARMOR_PDF_WEIGHT
current += object.mdef * ARMOR_MDF_WEIGHT
current += object.str_plus * ARMOR_STR_WEIGHT
current += object.dex_plus * ARMOR_DEX_WEIGHT
current += object.agi_plus * ARMOR_AGI_WEIGHT
current += object.int_plus * ARMOR_INT_WEIGHT
else
optimal = 0
end
max_eval = current
@actor.equip(slot, 0)
flag = false
zero_flag = true
for armor in $data_armors
if !flag
flag = true
next
end
if armor.kind != slot-1
next
end
evaluation = 0.00
evaluation += armor.eva * ARMOR_EVA_WEIGHT
evaluation += armor.pdef * ARMOR_PDF_WEIGHT
evaluation += armor.mdef * ARMOR_MDF_WEIGHT
evaluation += armor.str_plus * ARMOR_STR_WEIGHT
evaluation += armor.dex_plus * ARMOR_DEX_WEIGHT
evaluation += armor.agi_plus * ARMOR_AGI_WEIGHT
evaluation += armor.int_plus * ARMOR_INT_WEIGHT
if evaluation > 0
zero_flag = false
end
if @actor.equippable?(armor) &&
$game_party.armor_number(armor.id) > 0 && evaluation > max_eval
max_eval = evaluation
optimal = armor.id
end
end
if zero_flag
optimal = 0
end
@actor.equip(slot, optimal)
end
end
end