- Joined
- May 16, 2012
- Messages
- 71
- Reaction score
- 25
- First Language
- English
- Primarily Uses
Hello everybody, this is a script I requseted a friend named ???nOBodY??? make for me a long time ago.
I thought the script worked fine until recently when I finally caught on to a bug I'd been having that I didn't understand - now I've isolated the issue.
The script works by adding +1 to an index every time a weapon is added to your inventory. This allows the Cycler to know how many weapons the player holds, so it can cycle through them all, so if you have 13 weapons, it will go through 1 at a time over 13 presses of a button.
The issue seems to be that the script doesn't properly interact with shops, it does not remove -1 from the index when a weapon is sold. It's an invisible value due to being within the script. But I'm beyond positive this is what is happening. If you have 13 weapons, you can sell 3 of those 13 weapons and only have 10 left, but the weapon cycler still registers the index as 13, and therefore it fills up those extra 3 in the index by repeating weapons - meaning sometimes you press the button and it cycles to the same weapon 3 times in a row.
I have tested this in a vanilla project with only the weapon cycle and it's HUD script counterpart. I'm 100% positive this is a bug where the script just does not comprehend how to handle removing items via shops. It seems to have absolutely no problem adding the index value when buying weapons - the issue comes from selling. If anybody can help I'm requesting a fix that will allow it to work. I have created a small demo where you can test the issue and the scripts are in it. I will also post the script I think is the issue right here in case anybody can fix it without needing the demo. It is not a compatibility issue with other scripts, nor is it user error - just some sort of index issue - I understand, very basically, how scripts work - but not enough to fix this :/
(for those of you wondering this script is mostly for an ABS, not a traditional RPG - it is the equivalent of the feature in Shooter games where pressing a button switches your weapon on the fly - no menu needed.)
Small Demo of Bug
Weapon Cycler Script (Likely Culprit)
I thought the script worked fine until recently when I finally caught on to a bug I'd been having that I didn't understand - now I've isolated the issue.
The script works by adding +1 to an index every time a weapon is added to your inventory. This allows the Cycler to know how many weapons the player holds, so it can cycle through them all, so if you have 13 weapons, it will go through 1 at a time over 13 presses of a button.
The issue seems to be that the script doesn't properly interact with shops, it does not remove -1 from the index when a weapon is sold. It's an invisible value due to being within the script. But I'm beyond positive this is what is happening. If you have 13 weapons, you can sell 3 of those 13 weapons and only have 10 left, but the weapon cycler still registers the index as 13, and therefore it fills up those extra 3 in the index by repeating weapons - meaning sometimes you press the button and it cycles to the same weapon 3 times in a row.
I have tested this in a vanilla project with only the weapon cycle and it's HUD script counterpart. I'm 100% positive this is a bug where the script just does not comprehend how to handle removing items via shops. It seems to have absolutely no problem adding the index value when buying weapons - the issue comes from selling. If anybody can help I'm requesting a fix that will allow it to work. I have created a small demo where you can test the issue and the scripts are in it. I will also post the script I think is the issue right here in case anybody can fix it without needing the demo. It is not a compatibility issue with other scripts, nor is it user error - just some sort of index issue - I understand, very basically, how scripts work - but not enough to fix this :/
(for those of you wondering this script is mostly for an ABS, not a traditional RPG - it is the equivalent of the feature in Shooter games where pressing a button switches your weapon on the fly - no menu needed.)
Small Demo of Bug
Weapon Cycler Script (Likely Culprit)
Spoiler
Code:
# Weapon Cycle
# by ???nOBodY???
# Requested By: Revival
# *fix 1: fix index when changing equip manually via event or menu
# *fix 2: se on cycle
#Set to false if equipping from the menu is disabled
WEAPON_CYCLE_ADJUST_INDEX_ON_MANUAL_EQUIP = true
#Set mapped key/button
WEAPON_CYCLE_BUTTON = Input::L
#Switch to disable/enable weapon cycler
WEAPON_CYCLE_SWITCH = 1 #switch id
#Set to nil to disable
WEAPON_CYCLE_SE = "Audio/SE/Equip.ogg"
class Game_System
attr_accessor :wpnC_wpns
attr_accessor :wpnC_index
alias weapon_cycle_initializer initialize
def initialize
weapon_cycle_initializer
@wpnC_wpns = []
@wpnC_index = 0
end
end
#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
# This class handles maps. It includes event starting determinants and map
# scrolling functions. The instance of this class is referenced by $game_map.
#==============================================================================
class Game_Player < Game_Character
def play_weapon_cycle_se
if WEAPON_CYCLE_SE != nil
Audio.se_play(WEAPON_CYCLE_SE, 100, 100)
end
end
def weapon_cycle
#Get actor object
char = $game_party.members[0]
#Cycle Wpns update
for item in $game_party.items
if item.is_a?(RPG::Weapon)
next if $game_system.wpnC_wpns.include?(item)
next if !char.equippable?(item)
$game_system.wpnC_wpns.push(item) unless $game_system.wpnC_wpns.include?(item)
end
end
#Cycle Index update
if $game_system.wpnC_index < $game_system.wpnC_wpns.size-1
$game_system.wpnC_index += 1
else
$game_system.wpnC_index = 0
end
#Equip Change
play_weapon_cycle_se
char.change_equip(0, $game_system.wpnC_wpns[$game_system.wpnC_index]) unless $game_system.wpnC_wpns[$game_system.wpnC_index].nil?
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# * Processing of Movement via input from the Directional Buttons
#--------------------------------------------------------------------------
alias weapon_cycle_move_by_input move_by_input
def move_by_input
weapon_cycle_move_by_input
if Input.trigger?(WEAPON_CYCLE_BUTTON) && $game_switches[WEAPON_CYCLE_SWITCH]
weapon_cycle
end
end
end
if WEAPON_CYCLE_ADJUST_INDEX_ON_MANUAL_EQUIP
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
# This class handles actors. It's used within the Game_Actors class
# ($game_actors) and referenced by the Game_Party class ($game_party).
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Change Equipment (designate object)
# equip_type : Equip region (0..4)
# item : Weapon or armor (nil is used to unequip)
# test : Test flag (for battle test or temporary equipment)
#--------------------------------------------------------------------------
alias weapon_cycle_change_equip change_equip
def change_equip(equip_type, item, test = false)
weapon_cycle_change_equip(equip_type, item, test)
$game_system.wpnC_index = $game_system.wpnC_wpns.index(item) if $game_system.wpnC_wpns.include?(item)
end
end
end #if WEAPON_CYCLE_ADJUST_INDEX_ON_MANUAL_EQUIP
Last edited by a moderator:

