#===============================================================================
# NPC Inventories
# By OS
#===============================================================================
# Use:
#
# All Events can be given items, but in order to do so, in the event you must
# Call Script: $scene = Scene_GiveItem.new(event_id), where event_id is the
# numerical id of the event.
#
# NEW
# In Module OS, in the Giveable array, you can put in the Item IDs of items
# that can be given to NPCs.
#
# NEW
# To check if a particular item has been given to an NPC, use
# Conditional Branch: Script: $game_map.events[id].items_include?(item_id),
# where event_id is the event's id, and item_id is the id of the particular
# item you are checking for.
#
# EDIT
# You can see how many items an NPC has by using Call Script:
# i = $game_map.events[event_id].item_count
#===============================================================================
module OS
Giveable = [1,2,3,4,5,6,7,8,9,10]
end
class Game_Event
attr_accessor :items
alias os_init initialize
def initialize(map_id, event)
super()
@items = []
os_init(map_id, event)
end
def items_gained?
return true if @items.size > 0
return false
end
def item_count
return @items.size
end
def items_include?(item_id)
if @items.include?(item_id)
return true
end
return false
end
end
#==============================================================================
# ** Scene_Item
#------------------------------------------------------------------------------
# This class performs item screen processing.
#==============================================================================
class Scene_GiveItem
def initialize(npc_id)
@npc_id = npc_id
end
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Make help window, item window
@help_window = Window_Help.new
@item_window = Window_Item.new
# Associate help window
@item_window.help_window = @help_window
# 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
if $scene != self
break
end
end
# Prepare for transition
Graphics.freeze
# Dispose of windows
@help_window.dispose
@item_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update windows
@help_window.update
@item_window.update
# If item window is active: call update_item
if @item_window.active
update_item
return
end
end
#--------------------------------------------------------------------------
# * Frame Update (when item window is active)
#--------------------------------------------------------------------------
def update_item
# If B button was pressed
if 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
end
# If C button was pressed
if Input.trigger?(Input::C)
# Get currently selected data on the item window
@item = @item_window.item
# If not a use item
unless @item.is_a?(RPG::Item)
# Play buzzer SE
$game_system.se_play($data_system.buzzer_se)
return
end
for i in 0..OS::Giveable.size - 1
if @item.id == OS::Giveable[i]
$game_party.lose_item(@item.id,1)
$game_map.events[@npc_id].items << @item.id
end
end
$scene = Scene_Map.new
return
end
end
end