Demo – Version 1.4 >
#-------------------------------------------------------------------------------
# Galv's Quick Weapon Swap
#-------------------------------------------------------------------------------
# For: RPGMAKER VX ACE
# Version 1.4
# Requested by mary674
#------------------------------------------------------------------------------#
# 2013-04-10 - Version 1.4 - made compatible with explorer's hud script
# - (make sure this is below it in the script list)
# 2013-02-25 - Version 1.3 - fixed menu crash
# 2013-02-25 - Version 1.2 - compatability with my pop up script
# 2013-02-25 - Version 1.1 - save bug error fixed
# 2013-02-24 - Version 1.0 - release
#------------------------------------------------------------------------------#
# Changes the party leader's weapons (or equipment) by pressing a button on the
# map (default keyboard Q and W (L and R)). It cycles through all weapons the
# actor can equip and pops up text with which weapon was equipped.
#------------------------------------------------------------------------------#
($imported ||= {})["Galv_Quick_Weapon_Swap"] = true
module Galv_Qswap
#------------------------------------------------------------------------------#
# SETUP OPTIONS
#------------------------------------------------------------------------------#
BTN_LEFT = :L # Buttons to cycle equipment (:L and :R are Q and W keys)
BTN_RIGHT = :R
DISABLE_SWITCH = 1 # Turn swith ON to disable this.
EQUIP_NONE = true # true - can equip nothing. false - cannot equip nothing
NO_EQUIP_TXT = "Nothing Equipped" # Text displayed if you equip nothing
EQUIP_TXT = " Equipped" # Text displayed after weapon name
SE = ["Equip1",100,100] # "SE_Name",volume,pitch when swapping
Y_OFFSET = -50 # Y offset for popup text
DRAW_ICON = true # Draws icon with equipped weapon
#------------------------------------------------------------------------------#
# END SETUP OPTIONS
#------------------------------------------------------------------------------#
end
class Game_Player < Game_Character
alias galv_quick_weapon_gp_update update
def update
quick_change_equip if !$game_map.interpreter.running?
update_popup if @popsprite
galv_quick_weapon_gp_update
end
def quick_change_equip
return if $game_switches[Galv_Qswap::DISABLE_SWITCH]
if Input.trigger?(Galv_Qswap::BTN_LEFT)
weapon_list = get_equip_array
e_id = !actor.equips[0].nil? ? actor.equips[0].id : 0
eq_list = weapon_list.select { |w| w.id < e_id }
if eq_list.empty? && e_id != 0 && Galv_Qswap::EQUIP_NONE
do_quick_equip(nil)
elsif eq_list.empty?
do_quick_equip(weapon_list.reverse[0])
else
do_quick_equip(eq_list.reverse[0])
end
elsif Input.trigger?(Galv_Qswap::BTN_RIGHT)
weapon_list = get_equip_array
e_id = !actor.equips[0].nil? ? actor.equips[0].id : 0
eq_list = weapon_list.select { |w| w.id > e_id }
if eq_list.empty? && e_id != 0 && Galv_Qswap::EQUIP_NONE
do_quick_equip(nil)
elsif eq_list.empty?
do_quick_equip(weapon_list[0])
else
do_quick_equip(eq_list[0])
end
end
end
def get_equip_array
@quick_swap = $game_party.all_items.select { |item|
actor.equippable?(item) && item.is_a?(RPG::Weapon) &&
!actors_equip?(item) }
end
def do_quick_equip(item)
actor.change_equip(0, item)
RPG::SE.new(Galv_Qswap::SE[0],Galv_Qswap::SE[1],Galv_Qswap::SE[2]).play
popup(item)
end
def actors_equip?(item)
return nil if actor.equips[0].nil?
actor.equips[0].id == item.id
end
def update_popup
@popsprite.update
end
def dispose_popup
@popsprite.dispose if @popsprite
@popsprite = nil
end
def popup(name)
@popsprite.dispose if @popsprite
@popsprite = Sprite_QPopText.new(@viewport1,$game_player,name)
end
end # Game_Player < Game_Character
class Scene_Map < Scene_Base
alias galv_quick_weapon_sm_dispose_spriteset dispose_spriteset
def dispose_spriteset
galv_quick_weapon_sm_dispose_spriteset
$game_player.dispose_popup
end
end # Scene_Map < Scene_Base
class Sprite_QPopText < Sprite
def initialize(viewport,character,item)
super(viewport)
@character = character
@item = item
@rise = 0
create_bitmap
update
end
def dispose
self.bitmap.dispose
if @icon_sprite
@icon_sprite.bitmap.dispose
@icon_sprite.dispose
end
super
end
def create_bitmap
if @item && Galv_Qswap::DRAW_ICON
@icon_sprite = Sprite.new
@icon_sprite.bitmap = Cache.system("Iconset")
end
self.bitmap = Bitmap.new(200, 20)
self.bitmap.font.size = 20
self.bitmap.font.color.set(255, 255, 255)
self.z = 2
end
def update
super
update_position
update_bitmap
update_visibility
update_icon if @icon_sprite && Galv_Qswap::DRAW_ICON
end_popup
end
def end_popup
return $game_player.dispose_popup if @rise >= 80
end
def name_text
if @item
return @item.name + Galv_Qswap::EQUIP_TXT
else
return Galv_Qswap::NO_EQUIP_TXT
end
end
def update_bitmap
@rise += 1
self.bitmap.clear
self.bitmap.draw_text(self.bitmap.rect, name_text, 1)
self.draw_icon(@item.icon_index) if @item && Galv_Qswap::DRAW_ICON
end
def draw_icon(icon_index)
rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
@icon_sprite.src_rect = rect
@icon = icon_index
end
def update_position
self.x = @character.screen_x - 100
self.y = @character.screen_y + Galv_Qswap::Y_OFFSET - @rise * 0.5
end
def update_icon
@icon_sprite.x = @character.screen_x - name_text.length * 4 - 26
@icon_sprite.y = self.y - 2
@icon_sprite.opacity = self.opacity
end
def update_visibility
self.opacity = 390 - @rise * 7
end
end # Sprite_PopText < Sprite
if $imported["Galv_Explorers_Hud"]
class Scene_Map < Scene_Base
attr_accessor :galv_hud
end
class Game_Player < Game_Character
alias galv_quick_weapon_gp_hud_patch_quick_change_equip quick_change_equip
def quick_change_equip
galv_quick_weapon_gp_hud_patch_quick_change_equip
SceneManager.scene.galv_hud.refresh_windows
end
end
end
Just wondering, is there any way you could make a version of this which cycles through variables instead? i think this script idea is really awesome and could be used flexibly for all sorts of ideas! The one I had in mind is simply to make the buttons increase/decrease a variable between several values, leaving it open for the game creator to add whatever events they want.
If I had something like this in my game I think it’d be good for an advanced interaction system. The different variable values would correspond to interaction modes and NPCs around the map would have different events depending on which one you have selected when you talk to them. For example perhaps you could have a simple talk/attack/pickpocket kind of interface for a thief character. Or in a game that’s more about adventure/mystery, maybe you collect keywords as you go along and they get mapped to these variables, then you can bring up different subjects of conversation!
That’d require the ability to disable certain variables and change them on the fly via script calls though. Like… say you start with just “Talk”, so your only option is value 0. Then you gain the topic “The King’s Health” so now you can toggle between values 0 and 1. But say you go gain a conversation topic that isn’t the next one in the order- that means the script would need to have functionality to toggle between 0, 1 and 4 while missing out 2 and 3…
Er… hope I explained my idea well XD Sorry for the big silly post but this script just inspired me a lot! I’m a bit of an events fiend and I could create so many gameplay ideas just from this framework.. wowww… *sparkly anime eyes*
For now I guess I can still pull some of this stuff off in non-combat games where I could just replace the weapon items with commands/conversation topics/etc. Thanks so much for the awesome script!! :D
That’s a really cool idea! Might make it a separate script. Although still very busy for a while so don’t know when I can get back to scripting :)
Hey there, I’ve got a big problem. After a certain point in my game, this script stops working. This really sucks, because I need it for my game to work. Thanks to anybody if they can help.
I am guessing you turned on the disable switch.
In the settings you specify a switch:
DISABLE_SWITCH = 1 # Turn swith ON to disable this.
When you use “control switches” event command to turn on the switch number specified, it disables the script.