Introduction
This script is a very simple script that lets you press a key that lets you cycle through weapons for your lead character, assuming that you have suitable weapons for the character. It is possible to have 'no' weapons with this script, by cycling through them all.
Script
Hotkey Cycling
Code:
#==============================================================================
# ** Hotkey Weapon Cycling
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.0
# 04-20-2013
# RGSS / RPGMaker XP
#==============================================================================
# This script is a very simple script that lets you press a key that lets you
# cycle through weapons for your lead character, assuming that you have suit-
# able weapons for the character. It is possible to have 'no' weapons with
# this script, by cycling through them all.
#==============================================================================
# SET THE ICON PLACEMENT
WEAPHUD_X = 600
WEAPHUD_Y = 100
# SET THE HOTKEY
WEAPHUD_KEY = Input::X
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
# This class handles the actor. It's used within the Game_Actors class
# ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :weapon_id # weapon ID
end
#==============================================================================
# ** Window_WeapHud
#------------------------------------------------------------------------------
# This window is used to display the small window that shows the weapon that
# is currently selected.
#==============================================================================
class Window_WeapHud < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 24+32,24+32)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
icon_number = 0
actor = $game_party.actors[0]
icon_number = actor.weapon_id if actor.weapon_id != nil
item = $data_weapons[icon_number]
return if item == nil
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
end
end
class Scene_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias w_hotkey_main main
alias w_hotkey_update update
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Create the window
@weaphud = Window_WeapHud.new
# Make it transparent
@weaphud.opacity = 0
# Set its position
@weaphud.x = WEAPHUD_X
@weaphud.y = WEAPHUD_Y
# The original call
w_hotkey_main
@weaphud.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# The original call
w_hotkey_update
# Get various values (weapon id, class id, and character's class weap list)
weaphud_weapon = $game_party.actors[0].weapon_id
class_val = $game_party.actors[0].class_id
weapon_set = $data_classes[class_val].weapon_set
# Skip if the guy doesn't press the key
return unless Input.trigger?(WEAPHUD_KEY)
# Now perform the routines
max_weaps = ($data_weapons.size)-1
i = 0
# Cycle through ids of weapons in database
until i == max_weaps
i += 1
# If ID is beyond the current weapon in use
if i > weaphud_weapon
# If the ID is a class-allowed weapon
if weapon_set.include?(i)
# If there is a weapon in the party store
if $game_party.weapon_number(i) > 0
# Return current weapon to store
$game_party.gain_weapon(weaphud_weapon, 1)
# Remove new weapon from store
$game_party.gain_weapon(i, -1)
# And add to equipment
$game_party.actors[0].weapon_id = i
# Refresh and exit
@weaphud.refresh
return
end
end
end
end
# Remove weapon if none matched
unless weaphud_weapon == 0
# Return current weapon to store
$game_party.gain_weapon(weaphud_weapon, 1)
# Remove weapon from player, making him/her unarmed
$game_party.actors[0].weapon_id = 0
# Refresh and exit
@weaphud.refresh
return
end
end
end
FAQ
Not designed with multiple weapon slots in mind. It will only handle the 1st equipment slot for single weapon systems. Also, the hud is extremely simplified, showing only the weapon's icon. It's recommended to make one icon for each weapon so you can see which is currently selected.
Compatibility
RPGMaker XP only. It won't work with VX.
Terms and Conditions
Free for use, even in commercial scripts. Due credit is all that's required.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)