Okay, I added some stuff to the script
- Minor usability improvements
- A stack limit for each item in the actor inventories
- An item limit for the actor inventories
Feel free to test it out I don't guarantee anything^^
- Minor usability improvements
- A stack limit for each item in the actor inventories
- An item limit for the actor inventories
Feel free to test it out I don't guarantee anything^^
Content Hidden
Code:
#==============================================================================
# ** Actor Battle Items
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.1
# 11-02-2020 (mm/dd/yyyy)
# RGSS / RPGMaker XP
#==============================================================================
#
# USAGE:
#
# Ever wondered how your entire party can grab potions from the same grab-
# bag of items unhindered? Did you think that certain heroes may or should
# have items that another cannot? If so, this script may be for you.
#
# This script forces the game player to actively prepare his party for com-
# bat, demanding that the player distribute items usable in combat between
# each party member. Actors not equipped with their own personal items will
# not be able to use an 'every party member' grab bag of items as before.
#
# This system adds a pop-up window which asks if a chosen item is to be
# used or transferred to an individual party member. This window appears
# in the Item menu and the new Battle Items menu which appears for each
# individual actor. Transferring items between current actors is not only
# possible, but is an option available in-battle if so configured.
#
#------------------------------------------------------------------------------
#
# USAGE:
#
# Based uppn the default scripts package that comes with RPGMaker XP, this
# system affects the Item Menu and battlesystem's item select options, and
# adds a new Battle Items menu for lack of a better title.
#
# While within the item menu, you will receive a pop-up display when you
# select an item that may be used within battle. This pop-up display asks
# whether you wish to immediately use the item, or if wish to take the item
# from the collective item list and give it to one of the party members.
#
# And while in battle, choosing the Item option from the Actor's Command
# Window will bring up only those items that were specifically given to the
# actor currently highlighted. You will not be able to use items from the
# party's collective bag of items.
#
# Meanwhile, a new menu was created, the Battle Items menu which is meant
# to be added or used within the game's main menu. The Battle Items menu
# acts much like the Item Menu in that selecting an item brings up a pop-up
# display asking the player if immediate use o r transfer to another actor
# is desired. Only combat items can be listed as only combat items can be
# placed here by the Item Menu.
#
# The system has some options available. One option is to enable/disable
# the ability to move an item from the Battle Items menu back to the normal
# item menu. The other is to enable/disable the ability to transfer items
# between actors during combat, or if they are just immediately used.
#
#------------------------------------------------------------------------------
#
# CONFIGURATION:
#
# The system has some options available. One option is to enable/disable
# All configuration variables are stored within the BattleItems module, and
# should be self explanatory. One set adjusts the placement of the pop-up
# display, the second set handles the actual text in the window (something
# I like to do for non-English users), and the last two variables handle
# the enable/disable features I discussed earlier.
#
#------------------------------------------------------------------------------
#
# CONFLICTS:
#
# This was designed with the default RPGMaker XP script set system in mind,
# and did change much within Scene_Item and the Scene_Battle.
#
# Within the Scene_Item class, new code was added to the main and update
# methods and the update_item was completely rewritten.
#
# Within Scene_Battle, the main, update and update_phase3 methods received
# new code. But the start_item_select, update_phase3_item_select, and the
# make_item_action_result were altered.
#
#------------------------------------------------------------------------------
#
# SCRIPT CALLS:
#
# Within Scene_Battle, the main, update and update_phase3 methods received
# While making this, it made sense to ensure that some things can work by
# way out outside commands. You may wish to add an item specifically to the
# items carried by a certain actor or see the list of items an actor may be
# carrying at the time. These are not high-detailed script calls, but are
# instead pretty rudimentary.
#
# Executing / Running the Battle Items scene...
# $scene = Scene_BItem.new(@status_window.index)
# This is what you normally would have placed within the Main Menu. The
# @status_window.index identifies the actor within the game party that is
# being shown.
#
# Checking an actor's Inventory:
# p $game_party.actors[0].items
# This just prints the array of items for the lead party actor as you would
# expect.
#
# Adding an item to an actor's personal inventory:
# $game_party.actors[2].gain_item(2, 3)
# This adds three 'High Potions' (Item #2 in the database) to the 3rd actor
# of your party.
#
# Other commands should be possible as the add and remove items placed into
# the Game_Actor class mimick those within the Game_Party class.
#
#
#------------------------------------------------------------------------------
#
# MORE STUFF?:
#
# Other commands should be possible as the add and remove items placed into
# Nope. This is as far as I go with this script. Yep, I heard all sorts of
# ideas, making individual weights for each item for encumbrance, limiting
# the number of items that can be carried, eliminating the Item Menu itself
# and making the player choose who gets what immediately after battle.
#
# All of these would make the script more extensive, and I am ending the
# production right here. Other users can work out their own additions.
#
#------------------------------------------------------------------------------
#
# TERMS AND CONDITIONS:
#
# Free to use, even in commercial projects. Just note that I need some form
# of due credit... even a mere mention in some end titles.
#
#
#==============================================================================
module BattleItems
# Coordinates and Width of Battle Item Pop-up window
#
POP_X = 220
POP_Y = 120
POP_W = 200
# Text options displayed in Battle Item Pop-up window
#
TEXT_USE = "Use"
TEXT_PASS = "Distribute"
TEXT_RETURN = "Return to Party"
# Whether the option to return items back to the party item lise
# is permitted in the field.
#
ITEM_RETURN = true
# Whether the option to transfer items from one to another permitted
# in battle
#
BATTLE_PASS = true
# Set the stack and item limit of the actor inventories
STACK_LIMIT = 3
ITEM_LIMIT = 2
end
#==============================================================================
# ** 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
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias battle_items_setup setup
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :items # Items
#--------------------------------------------------------------------------
# * Setup
# actor_id : actor ID
#--------------------------------------------------------------------------
def setup(actor_id)
# Perform the original method
battle_items_setup(actor_id)
#
# Create amount in possession hash for items, weapons, and armor
@items = {}
end
#--------------------------------------------------------------------------
# * Get Number of Items Possessed
# item_id : item ID
#--------------------------------------------------------------------------
def item_number(item_id)
# If quantity data is in the hash, use it. If not, return 0
return @items.include?(item_id) ? @items[item_id] : 0
end
#--------------------------------------------------------------------------
# * 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, BattleItems::STACK_LIMIT].min
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)
end
#--------------------------------------------------------------------------
# * Determine if Item is Usable
# item_id : item ID
#--------------------------------------------------------------------------
def item_can_use?(item_id)
# If item quantity is 0
if item_number(item_id) == 0
# Unusable
return false
end
# Get usable time
occasion = $data_items[item_id].occasion
# If in battle
if $game_temp.in_battle
# If useable time is 0 (normal) or 1 (only battle) it's usable
return (occasion == 0 or occasion == 1)
end
# If useable time is 0 (normal) or 2 (only menu) it's usable
return (occasion == 0 or occasion == 2)
end
end
#==============================================================================
# ** Window_BattleItems
#------------------------------------------------------------------------------
# This window displays battle items on the battle item and battle screens.
#==============================================================================
class Window_BattleItems < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
# actor : actor
#--------------------------------------------------------------------------
def initialize(actor)
super(0, 128, 640, 352)
@actor = actor
@column_max = 2
refresh
self.index = 0
# If in battle, move window to center of screen
# and make it semi-transparent
if $game_temp.in_battle
self.y = 64
self.height = 256
self.back_opacity = 160
end
end
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
# Add item
for i in 1...$data_items.size
if @actor.item_number(i) > 0
item = $data_items[i]
@data.push($data_items[i]) unless item.nil?
end
end
# If item count is not 0, make a bit map and draw all items
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
number = @actor.item_number(item.id)
if item.is_a?(RPG::Item) and
@actor.item_can_use?(item.id)
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 32
rect = Rect.new(x, y, self.width / @column_max - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
size = $game_party.actors[0].items.size
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
#==============================================================================
# ** Window_BattleItemPop
#------------------------------------------------------------------------------
# This window generates a pop-up window.
#==============================================================================
class Window_BattleItemPop < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(flag=false)
# Determine height of window on flag
height = 96
height = 128 if flag == true
# Defind window with current dimensions
super(0, 0, BattleItems::POP_W, height)
self.contents = Bitmap.new(width - 32, height - 32)
@item_max = 2
@item_max = 3 if flag == true
@flag = flag
self.index = 0
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
# Clear contents
self.contents.clear
# Set Font Color
self.contents.font.color = normal_color
#
# Draw 'use item' option
rect = Rect.new(4, 0, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, BattleItems::TEXT_USE)
#
# Draw 'transfer item' option
rect = Rect.new(4, 32, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, BattleItems::TEXT_PASS)
#
# If available, draw 'return to party' option
if @flag
rect = Rect.new(4, 64, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, BattleItems::TEXT_RETURN)
end
end
end
#==============================================================================
# ** Scene_Item
#------------------------------------------------------------------------------
# This class performs item screen processing.
#==============================================================================
class Scene_Item
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias battle_items_scene_item_main main
alias battle_items_scene_item_update update
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Setup the popup window
@bitem_pop_window = Window_BattleItemPop.new
@bitem_pop_window.visible = false
@bitem_pop_window.active = false
@bitem_pop_window.x = BattleItems::POP_X
@bitem_pop_window.y = BattleItems::POP_Y
@bitem_pop_window.z = 1500
# Make target window (set to invisible / inactive)
@transfer_window = Window_Target.new
@transfer_window.visible = false
@transfer_window.active = false
#
# Perform the original method
battle_items_scene_item_main
#
# Dispose of the window
@bitem_pop_window.dispose
@transfer_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update the Popup Window if active
@bitem_pop_window.update if @bitem_pop_window.active == true
return update_pop if @bitem_pop_window.active == true
# Update the Transfer Window if active
@transfer_window.update if @transfer_window.active == true
return update_transfer if @transfer_window.active == true
#
# Perform the original method
battle_items_scene_item_update
end
#--------------------------------------------------------------------------
# * Frame Update (when item window is active)
#--------------------------------------------------------------------------
def update_item
return if update_item_cancel?
return if update_item_decision?
end
#--------------------------------------------------------------------------
# * Frame Update (when cancelling within the active item window)
#--------------------------------------------------------------------------
def update_item_cancel?
# If B button was pressed
return false unless Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
$scene = Scene_Menu.new(0)
return true
end
#--------------------------------------------------------------------------
# * Frame Update (when deciding within the active item window)
#--------------------------------------------------------------------------
def update_item_decision?
# If C button was pressed
return false unless Input.trigger?(Input::C)
# Get currently selected data on the item window
@item = @item_window.item
# Exit if not a usable item
unless @item.is_a?(RPG::Item)
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return true
end
# Exit if it can't be used
unless $game_party.item_can_use?(@item.id)
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return true
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Get usable time
occasion = $data_items[@item.id].occasion
# If useable in battle
if (occasion == 0 or occasion == 1)
# Force window
@bitem_pop_window.visible = true
@bitem_pop_window.active = true
# Exit true
return true
end
# Cannot be used in battle
update_item_decision_use
return true
end
#--------------------------------------------------------------------------
# * Frame Update (when using an item within the active item window)
#--------------------------------------------------------------------------
def update_item_decision_use
# If effect scope is an ally
if @item.scope >= 3
# Activate target window
update_item_decision_use_ally
# If effect scope is other than an ally
else
update_item_decision_use_common
end
end
#--------------------------------------------------------------------------
# * Frame Update (when using a ally-based item in the active item window)
#--------------------------------------------------------------------------
def update_item_decision_use_ally
# Activate target window
@item_window.active = false
@target_window.x = (@item_window.index + 1) % 2 * 304
@target_window.visible = true
@target_window.active = true
# Set cursor position to effect scope (single / all)
if @item.scope == 4 || @item.scope == 6
@target_window.index = -1
else
@target_window.index = 0
end
end
#--------------------------------------------------------------------------
# * Frame Update (when using a common event item in the active item window)
#--------------------------------------------------------------------------
def update_item_decision_use_common
# If command event ID is valid
return unless @item.common_event_id > 0
# Command event call reservation
$game_temp.common_event_id = @item.common_event_id
# Play item use SE
$game_system.se_play(@item.menu_se)
# If consumable
if @item.consumable
# Decrease used items by 1
$game_party.lose_item(@item.id, 1)
# Draw item window item
@item_window.draw_item(@item_window.index)
end
# Switch to map screen
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# * Frame Update (when popup window is active - use or transfer)
#--------------------------------------------------------------------------
def update_pop
# Return if Enter isn't pressed
if Input.trigger?(Input::C)
# Play decision
$game_system.se_play($data_system.decision_se)
# Hide Hotkey Popup
@bitem_pop_window.active = @bitem_pop_window.visible = false
# Branch on choice
case @bitem_pop_window.index
when 0 ; update_item_decision_use
when 1 ; update_item_decision_transfer
end
end
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@bitem_pop_window.active = @bitem_pop_window.visible = false
@item_window.active = true
end
end
#--------------------------------------------------------------------------
# * Frame Update (settingu up the transfer window)
#--------------------------------------------------------------------------
def update_item_decision_transfer
@transfer_window.x = (@item_window.index + 1) % 2 * 304
@transfer_window.visible = true
@transfer_window.active = true
@transfer_window.index = 0
end
#--------------------------------------------------------------------------
# * Frame Update (when transfer window is active)
#--------------------------------------------------------------------------
def update_transfer
return if update_transfer_cancel?
return if update_transfer_decision?
end
#--------------------------------------------------------------------------
# * Frame Update (when cancelling within the transfer item window)
#--------------------------------------------------------------------------
def update_transfer_cancel?
# If B button was pressed
return false unless Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Erase target window
@item_window.active = true
@transfer_window.visible = false
@transfer_window.active = false
return true
end
#--------------------------------------------------------------------------
# * Frame Update (when deciding within the transfer item window)
#--------------------------------------------------------------------------
def update_transfer_decision?
# If C button was pressed
return false unless Input.trigger?(Input::C)
# Defining required variables
target = $game_party.actors[@transfer_window.index]
number = $game_party.actors[@transfer_window.index].item_number(@item.id)
@data = []
for i in 1...$data_items.size
if target.item_number(i) > 0
item = $data_items[i]
@data.push($data_items[i]) unless item.nil?
end
end
amount = @data.size
# Checking the limits
if number >= BattleItems::STACK_LIMIT
$game_system.se_play($data_system.buzzer_se)
return
end
if number == 0
if amount >= BattleItems::ITEM_LIMIT
$game_system.se_play($data_system.buzzer_se)
return
end
end
# Adding the item
$game_system.se_play($data_system.decision_se)
$game_party.lose_item(@item.id, 1)
target.gain_item(@item.id, 1)
@item_window.refresh
amount = 0
if $game_party.item_number(@item.id) == 0
@item_window.active = true
@transfer_window.visible = false
@transfer_window.active = false
else
return
end
end
end
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
# This class performs battle screen processing.
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias battle_items_scene_battle_main main
alias battle_items_scene_battle_update update
alias battle_items_scene_battle_update_phase3 update_phase3
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make target window (set to invisible / inactive)
@transfer_window = Window_Target.new
@transfer_window.visible = false
@transfer_window.active = false
# Setup the popup window
@bitem_pop_window = Window_BattleItemPop.new
@bitem_pop_window.visible = false
@bitem_pop_window.active = false
@bitem_pop_window.x = BattleItems::POP_X
@bitem_pop_window.y = BattleItems::POP_Y
@bitem_pop_window.z = 1500
#
# Perform the original method
battle_items_scene_battle_main
#
@bitem_pop_window.dispose
@transfer_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
#
# Perform the original method
battle_items_scene_battle_update
#
# Update the new windows
@transfer_window.update
@bitem_pop_window.update
end
#--------------------------------------------------------------------------
# * Frame Update (actor command phase)
#--------------------------------------------------------------------------
def update_phase3
#
# Perform window updates and exit if active
return update_phase3_item_pop if @bitem_pop_window.active == true
return update_phase3_item_transfer if @transfer_window.active == true
#
# Perform the original method
battle_items_scene_battle_update_phase3
end
#--------------------------------------------------------------------------
# * Frame Update (when popup window is active - use or transfer)
#--------------------------------------------------------------------------
def update_phase3_item_pop
# Return if Enter isn't pressed
if Input.trigger?(Input::C)
# Play decision
$game_system.se_play($data_system.decision_se)
# Hide Hotkey Popup
@bitem_pop_window.active = @bitem_pop_window.visible = false
# Branch on choice
case @bitem_pop_window.index
when 0 ; update_phase3_item_select_uae
when 1 ; update_phase3_item_select_transfer
end
end
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@bitem_pop_window.active = @bitem_pop_window.visible = false
end
end
#--------------------------------------------------------------------------
# * Start Item Selection
#--------------------------------------------------------------------------
def start_item_select
# Make item window
@item_window = Window_BattleItems.new(@active_battler)
# Associate help window
@item_window.help_window = @help_window
# Disable actor command window
@actor_command_window.active = false
@actor_command_window.visible = false
end
#--------------------------------------------------------------------------
# * Frame Update (actor command phase : item selection)
#--------------------------------------------------------------------------
def update_phase3_item_select
# Make item window visible
@item_window.visible = true
# Update item window
@item_window.update
return if update_phase3_item_select_cancel?
return if update_phase3_item_select_decision?
end
#--------------------------------------------------------------------------
# * Frame Update (actor command phase : item selection cancelled)
#--------------------------------------------------------------------------
def update_phase3_item_select_cancel?
# False unless B button was pressed
return false unless Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
# End item selection
end_item_select
# true
return true
end
#--------------------------------------------------------------------------
# * Frame Update (actor command phase : item selection decided)
#--------------------------------------------------------------------------
def update_phase3_item_select_decision?
# False unless B button was pressed
return false unless Input.trigger?(Input::C)
# Get currently selected data on the item window
@item = @item_window.item
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Perform item usage if pass option disabled
unless BattleItems::BATTLE_PASS == true
update_phase3_item_select_uae
return true
end
# Make pop-up active
@bitem_pop_window.visible = true
@bitem_pop_window.active = true
return true
end
#--------------------------------------------------------------------------
# * Frame Update (actor command phase : item selection usage)
#--------------------------------------------------------------------------
def update_phase3_item_select_uae
# Set action
@active_battler.current_action.item_id = @item.id
# Make item window invisible
@item_window.visible = false
# If effect scope is single enemy
if @item.scope == 1
# Start enemy selection
start_enemy_select
# If effect scope is single ally
elsif @item.scope == 3 or @item.scope == 5
# Start actor selection
start_actor_select
# If effect scope is not single
else
# End item selection
end_item_select
# Go to command input for next actor
phase3_next_actor
end
return
end
#--------------------------------------------------------------------------
# * Frame Update (settingu up the transfer window)
#--------------------------------------------------------------------------
def update_phase3_item_select_transfer
@transfer_window.x = (@item_window.index + 1) % 2 * 304
@transfer_window.visible = true
@transfer_window.active = true
@transfer_window.index = 0
end
#--------------------------------------------------------------------------
# * Frame Update (when transfer window is active)
#--------------------------------------------------------------------------
def update_phase3_item_transfer
return if update_phase3_item_transfer_cancel?
return if update_phase3_item_transfer_decision?
end
#--------------------------------------------------------------------------
# * Frame Update (when cancelling within the transfer item window)
#--------------------------------------------------------------------------
def update_phase3_item_transfer_cancel?
# If B button was pressed
return false unless Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Erase target window
@item_window.active = true
@transfer_window.visible = false
@transfer_window.active = false
return true
end
#--------------------------------------------------------------------------
# * Frame Update (when deciding within the transfer item window)
#--------------------------------------------------------------------------
def update_phase3_item_transfer_decision?
# If C button was pressed
return false unless Input.trigger?(Input::C)
# Defining required variables
target = $game_party.actors[@transfer_window.index]
number = $game_party.actors[@transfer_window.index].item_number(@item.id)
@data = []
for i in 1...$data_items.size
if target.item_number(i) > 0
item = $data_items[i]
@data.push($data_items[i]) unless item.nil?
end
end
amount = @data.size
# Checking the limits
if number >= BattleItems::STACK_LIMIT
$game_system.se_play($data_system.buzzer_se)
return
end
if number == 0
if amount >= BattleItems::ITEM_LIMIT
$game_system.se_play($data_system.buzzer_se)
return
end
end
# Adding the item
# Play decision SE
$game_system.se_play($data_system.decision_se)
target.gain_item(@item.id, 1)
@active_battler.lose_item(@item.id, 1)
@item_window.refresh
@item_window.active = true
@transfer_window.visible = false
@transfer_window.active = false
# End item selection
end_item_select
# Go to command input for next actor
phase3_next_actor
return true
end
#--------------------------------------------------------------------------
# * Make Item Action Results
#--------------------------------------------------------------------------
def make_item_action_result
# Get item
@item = $data_items[@active_battler.current_action.item_id]
# If unable to use due to items running out
unless @active_battler.item_can_use?(@item.id)
# Shift to step 1
@phase4_step = 1
return
end
# If consumable
if @item.consumable
# Decrease used item by 1
@active_battler.lose_item(@item.id, 1)
end
# Display item name on help window
@help_window.set_text(@item.name, 1)
# Set animation ID
@animation1_id = @item.animation1_id
@animation2_id = @item.animation2_id
# Set common event ID
@common_event_id = @item.common_event_id
# Decide on target
index = @active_battler.current_action.target_index
target = $game_party.smooth_target_actor(index)
# Set targeted battlers
set_target_battlers(@item.scope)
# Apply item effect
for target in @target_battlers
target.item_effect(@item)
end
end
end
#==============================================================================
# ** Scene_BItem
#------------------------------------------------------------------------------
# This class performs item screen processing for an individual actor
#==============================================================================
class Scene_BItem
#--------------------------------------------------------------------------
# * Object Initialization
# actor_index : actor index
#--------------------------------------------------------------------------
def initialize(actor_index = 0, equip_index = 0)
@actor_index = actor_index
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Get actor
@actor = $game_party.actors[@actor_index]
# Make help window, item window
@help_window = Window_Help.new
@status_window = Window_SkillStatus.new(@actor)
@item_window = Window_BattleItems.new(@actor)
# Associate help window
@item_window.help_window = @help_window
# Make target window (set to invisible / inactive)
@target_window = Window_Target.new
@target_window.visible = false
@target_window.active = false
# Setup the popup window
if BattleItems::ITEM_RETURN
@bitem_pop_window = Window_BattleItemPop.new(true)
else
@bitem_pop_window = Window_BattleItemPop.new
end
@bitem_pop_window.visible = false
@bitem_pop_window.active = false
@bitem_pop_window.x = BattleItems::POP_X
@bitem_pop_window.y = BattleItems::POP_Y
@bitem_pop_window.z = 1500
# Make target window (set to invisible / inactive)
@transfer_window = Window_Target.new
@transfer_window.visible = false
@transfer_window.active = false
# Execute transition
Graphics.transition
# Main loop
loop do
# Update game screen
Graphics.update
# Update input information
Input.update
# Frame update
update
# Abort loop if screen is changed
break if $scene != self
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@help_window.dispose
@status_window.dispose
@item_window.dispose
@target_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@help_window.update
@item_window.update
@status_window.update
@target_window.update
# Update the Popup Window if active
@bitem_pop_window.update if @bitem_pop_window.active == true
return update_pop if @bitem_pop_window.active == true
# Update the Transfer Window if active
@transfer_window.update if @transfer_window.active == true
return update_transfer if @transfer_window.active == true
# If item window is active: call update_item
return update_item if @item_window.active
# If target window is active: call update_target
return update_target if @target_window.active
end
#--------------------------------------------------------------------------
# * Frame Update (when item window is active)
#--------------------------------------------------------------------------
def update_item
return if update_item_prev?
return if update_item_next?
return if update_item_cancel?
return if update_item_decision?
end
#--------------------------------------------------------------------------
# * Frame Update (when scrolling to previous member in party)
#--------------------------------------------------------------------------
def update_item_prev?
return false unless Input.trigger?(Input::L)
# Play cursor SE
$game_system.se_play($data_system.cursor_se)
# To previous actor
@actor_index += $game_party.actors.size - 1
@actor_index %= $game_party.actors.size
# Switch to different skill screen
$scene = Scene_BItem.new(@actor_index)
return true
end
#--------------------------------------------------------------------------
# * Frame Update (when scrolling to next member in party)
#--------------------------------------------------------------------------
def update_item_next?
return false unless Input.trigger?(Input::R)
# Play cursor SE
$game_system.se_play($data_system.cursor_se)
# To next actor
@actor_index += 1
@actor_index %= $game_party.actors.size
# Switch to different skill screen
$scene = Scene_BItem.new(@actor_index)
return true
end
#--------------------------------------------------------------------------
# * Frame Update (when exiting the active item window)
#--------------------------------------------------------------------------
def update_item_cancel?
# If B button was pressed
return false unless Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Switch to menu screen
$scene = Scene_Menu.new(0)
return true
end
#--------------------------------------------------------------------------
# * Frame Update (when exiting the active item window)
#--------------------------------------------------------------------------
def update_item_decision?
# If C button was pressed
return false unless Input.trigger?(Input::C)
# Get currently selected data on the item window
@item = @item_window.item
# If it can't be used
unless @actor.item_can_use?(@item.id)
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# Play decision SE
$game_system.se_play($data_system.decision_se)
# Get usable time
occasion = $data_items[@item.id].occasion
# Force window
@item_window.active = false
@bitem_pop_window.visible = true
@bitem_pop_window.active = true
# Exit true
return true
end
#--------------------------------------------------------------------------
# * Frame Update (when using an item within the active item window)
#--------------------------------------------------------------------------
def update_item_decision_use
# If effect scope is an ally
if @item.scope >= 3
# Activate target window
update_item_decision_use_ally
# If effect scope is other than an ally
else
update_item_decision_use_common
end
end
#--------------------------------------------------------------------------
# * Frame Update (when using a ally-based item in the active item window)
#--------------------------------------------------------------------------
def update_item_decision_use_ally
# Activate target window
@item_window.active = false
@target_window.x = (@item_window.index + 1) % 2 * 304
@target_window.visible = true
@target_window.active = true
# Set cursor position to effect scope (single / all)
if @item.scope == 4 || @item.scope == 6
@target_window.index = -1
else
@target_window.index = 0
end
end
#--------------------------------------------------------------------------
# * Frame Update (when using a common event item in the active item window)
#--------------------------------------------------------------------------
def update_item_decision_use_common
# If command event ID is valid
return unless @item.common_event_id > 0
# Command event call reservation
$game_temp.common_event_id = @item.common_event_id
# Play item use SE
$game_system.se_play(@item.menu_se)
# If consumable
if @item.consumable
# Decrease used items by 1
@actor.lose_item(@item.id, 1)
# Draw item window item
@item_window.draw_item(@item_window.index)
end
# Switch to map screen
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# * Frame Update (when popup window is active - use or transfer)
#--------------------------------------------------------------------------
def update_pop
# Return if Enter isn't pressed
if Input.trigger?(Input::C)
# Play decision
$game_system.se_play($data_system.decision_se)
# Hide Hotkey Popup
@bitem_pop_window.active = @bitem_pop_window.visible = false
# Branch on choice
case @bitem_pop_window.index
when 0 ; update_item_decision_use
when 1 ; update_item_decision_transfer
when 2 ; update_item_decision_return
end
end
if Input.trigger?(Input::B)
$game_system.se_play($data_system.decision_se)
@bitem_pop_window.active = @bitem_pop_window.visible = false
@item_window.active = true
end
end
#--------------------------------------------------------------------------
# * Frame Update (when target window is active)
#--------------------------------------------------------------------------
def update_target
return if update_target_cancel?
return if update_target_decision?
end
#--------------------------------------------------------------------------
# * Frame Update (when cancelling within the active target window)
#--------------------------------------------------------------------------
def update_target_cancel?
# If B button was pressed
return false unless Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# If unable to use because items ran out
unless @actor.item_can_use?(@item.id)
# Remake item window contents
@item_window.refresh
end
# Erase target window
@item_window.active = true
@target_window.visible = false
@target_window.active = false
return true
end
#--------------------------------------------------------------------------
# * Frame Update (when cancelling within the active target window)
#--------------------------------------------------------------------------
def update_target_decision?
# If C button was pressed
return false unless Input.trigger?(Input::C)
# If items are used up
if @actor.item_number(@item.id) == 0
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
# If target is all
if @target_window.index == -1
# Apply item effects to entire party
used = false
for i in $game_party.actors
used |= i.item_effect(@item)
end
end
# If single target
if @target_window.index >= 0
# Apply item use effects to target actor
target = $game_party.actors[@target_window.index]
used = target.item_effect(@item)
end
# If an item was used
if used
# Play item use SE
$game_system.se_play(@item.menu_se)
# If consumable
if @item.consumable
# Decrease used items by 1
@actor.lose_item(@item.id, 1)
# Redraw item window item
@item_window.draw_item(@item_window.index)
end
# Remake target window contents
@target_window.refresh
# If all party members are dead
if $game_party.all_dead?
# Switch to game over screen
$scene = Scene_Gameover.new
return
end
# If common event ID is valid
if @item.common_event_id > 0
# Common event call reservation
$game_temp.common_event_id = @item.common_event_id
# Switch to map screen
$scene = Scene_Map.new
return
end
end
# If item wasn't used
unless used
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
end
return true
end
#--------------------------------------------------------------------------
# * Frame Update (settingu up the transfer window)
#--------------------------------------------------------------------------
def update_item_decision_transfer
@transfer_window.x = (@item_window.index + 1) % 2 * 304
@transfer_window.visible = true
@transfer_window.active = true
@transfer_window.index = 0
end
#--------------------------------------------------------------------------
# * Frame Update (when transfer window is active)
#--------------------------------------------------------------------------
def update_transfer
return if update_transfer_cancel?
return if update_transfer_decision?
end
#--------------------------------------------------------------------------
# * Frame Update (when cancelling within the transfer item window)
#--------------------------------------------------------------------------
def update_transfer_cancel?
# If B button was pressed
return false unless Input.trigger?(Input::B)
# Play cancel SE
$game_system.se_play($data_system.cancel_se)
# Erase target window
@item_window.active = true
@transfer_window.visible = false
@transfer_window.active = false
return true
end
#--------------------------------------------------------------------------
# * Frame Update (when deciding within the transfer item window)
#--------------------------------------------------------------------------
def update_transfer_decision?
# If C button was pressed
return false unless Input.trigger?(Input::C)
# Defining required variables
target = $game_party.actors[@transfer_window.index]
number = $game_party.actors[@transfer_window.index].item_number(@item.id)
@data = []
for i in 1...$data_items.size
if target.item_number(i) > 0
item = $data_items[i]
@data.push($data_items[i]) unless item.nil?
end
end
amount = @data.size
# Checking the limits
if number >= BattleItems::STACK_LIMIT
$game_system.se_play($data_system.buzzer_se)
return
end
if number == 0
if amount >= BattleItems::ITEM_LIMIT
$game_system.se_play($data_system.buzzer_se)
return
end
end
# Adding the item
# Play decision SE
$game_system.se_play($data_system.decision_se)
target.gain_item(@item.id, 1)
@actor.lose_item(@item.id, 1)
@item_window.refresh
amount = 0
if @actor.item_number(@item.id) == 0
@item_window.active = true
@transfer_window.visible = false
@transfer_window.active = false
else
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when returning item back to party bag)
#--------------------------------------------------------------------------
def update_item_decision_return
# Play decision SE
$game_system.se_play($data_system.decision_se)
$game_party.gain_item(@item.id, 1)
@actor.lose_item(@item.id, 1)
@item_window.refresh
@item_window.active = true
return
end
end