Yep, it's his bug.
Problem is with the logic regarding recent items.
for i in 0...$recent_items.size
puts [i, $recent_items[i]].inspect
if $recent_items[i].id == $data_items[item_id].id && $recent_items[i].is_a?(RPG::Item)
$recent_items.delete_at(i)
end
end
$recent_items.push(item)
if $recent_items.size > 40
$recent_items.delete_at(0)
end
If you are to gain another item that you recently obtained, it deletes the item from the $recent_items list and then re-adds it again. However, if you were to gain item A, then item B, then item A, the use of
$recent_items.delete_at(i) modifies the array WHILE we are currently iterating through it in the loop. This created a
nil record, hence the error message received.
He should have used
delete_if instead. I went ahead and modified the methods to do this. I also checked if he made this
delete_at error anywhere else, and found out that the lose_item/weapon/armor methods he rewrote are completely wrong. I fixed those as well.
Replace the Game_Party class in the script with this:
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
# This class handles the party. It includes information on amount of gold
# and items. Refer to "$game_party" for the instance of this class.
#==============================================================================
class Game_Party
#--------------------------------------------------------------------------
# * Gain Items (or lose)
# item_id : item ID
# n : quantity
#--------------------------------------------------------------------------
def gain_item(item_id, n)
# Update quantity data in the hash.
if item_id > 0
@items[item_id] = [[item_number(item_id) + n, 0].max, 99].min
gain_recent_item(item_id) if n >= 0
end
end
#--------------------------------------------------------------------------
# * Gain Weapons (or lose)
# weapon_id : weapon ID
# n : quantity
#--------------------------------------------------------------------------
def gain_weapon(weapon_id, n)
# Update quantity data in the hash.
if weapon_id > 0
@weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, 99].min
gain_recent_weapon(weapon_id) if n >= 0
end
end
#--------------------------------------------------------------------------
# * Gain Armor (or lose)
# armor_id : armor ID
# n : quantity
#--------------------------------------------------------------------------
def gain_armor(armor_id, n)
# Update quantity data in the hash.
if armor_id > 0
@armors[armor_id] = [[armor_number(armor_id) + n, 0].max, 99].min
gain_recent_armor(armor_id) if n >= 0
end
end
#--------------------------------------------------------------------------
# * Lose Items
# item_id : item ID
# n : quantity
#--------------------------------------------------------------------------
def lose_item(item_id, n)
# Reverse the numerical value and call it gain_item
gain_item(item_id, -n)
if $game_party.item_number(item_id) == 0
$recent_items.delete_if { |i| i.id == item_id && i.is_a?(RPG::Item) }
end
end
#--------------------------------------------------------------------------
# * Lose Weapons
# weapon_id : weapon ID
# n : quantity
#--------------------------------------------------------------------------
def lose_weapon(weapon_id, n)
# Reverse the numerical value and call it gain_weapon
gain_weapon(weapon_id, -n)
if $game_party.weapon_number(weapon_id) == 0
$recent_items.delete_if { |i| i.id == weapon_id && i.is_a?(RPG::Weapon) }
end
end
#--------------------------------------------------------------------------
# * Lose Armor
# armor_id : armor ID
# n : quantity
#--------------------------------------------------------------------------
def lose_armor(armor_id, n)
# Reverse the numerical value and call it gain_armor
gain_armor(armor_id, -n)
if $game_party.armor_number(armor_id) == 0
$recent_items.delete_if { |i| i.id == armor_id && i.is_a?(RPG::Armor) }
end
end
#--------------------------------------------------------------------------
# * Gain Recent Items
# item_id : item ID
#--------------------------------------------------------------------------
def gain_recent_item(item_id)
item = $data_items[item_id]
$recent_items.delete_if { |i| i.id == item.id && i.is_a?(RPG::Item) }
$recent_items.push(item)
if $recent_items.size > 40
$recent_items.delete_at(0)
end
end
#--------------------------------------------------------------------------
# * Gain Recent Weapons
# weapon_id : weapon ID
#--------------------------------------------------------------------------
def gain_recent_weapon(weapon_id)
weapon = $data_weapons[weapon_id]
$recent_items.delete_if { |i| i.id == weapon.id && i.is_a?(RPG::Weapon) }
$recent_items.push(weapon)
if $recent_items.size > 40
$recent_items.delete_at(0)
end
end
#--------------------------------------------------------------------------
# * Gain Recent Armor
# armor_id : armor ID
#--------------------------------------------------------------------------
def gain_recent_armor(armor_id)
armor = $data_armors[armor_id]
$recent_items.delete_if { |i| i.id == armor.id && i.is_a?(RPG::Armor) }
$recent_items.push(armor)
if $recent_items.size > 40
$recent_items.delete_at(0)
end
end
#--------------------------------------------------------------------------
# * Gain Items (or lose)
# item_id : item ID
# n : quantity
#--------------------------------------------------------------------------
def equip_item(item_id, n)
# Update quantity data in the hash.
if item_id > 0
@items[item_id] = [[item_number(item_id) + n, 0].max, 99].min
end
end
#--------------------------------------------------------------------------
# * Gain Weapons (or lose)
# weapon_id : weapon ID
# n : quantity
#--------------------------------------------------------------------------
def equip_weapon(weapon_id, n)
# Update quantity data in the hash.
if weapon_id > 0
@weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, 99].min
end
end
#--------------------------------------------------------------------------
# * Gain Armor (or lose)
# armor_id : armor ID
# n : quantity
#--------------------------------------------------------------------------
def equip_armor(armor_id, n)
# Update quantity data in the hash.
if armor_id > 0
@armors[armor_id] = [[armor_number(armor_id) + n, 0].max, 99].min
end
end
end