
#==============================================================================# ** Throw, Gifting, Pick-up, Etc#------------------------------------------------------------------------------# Author : Sinmora# Version : 1.0#==============================================================================# Instructions:#------------------------# SETTING UP THE EVENTS:#-------------------------------------## To specify that an item can be picked up, place this in the event's name:## <pickup>## To specify the type an item that is being picked up, place this in the # event's name:## <item#> : when the event is an item# <armor#> : when the event is an armor# <weapon#> : when the event is a weapon## * Note: The '#' represents the ID of the item/armor/weapon in the database.## For an event that CANNOT be picked up, simply leave the '<pickup>' tag out# of the event's name. ## To create an event that acts as a waste basket for other items, place this# in the event's name:## <dispose_item>## Items that cannot be disposed are tagged with an element in the database. The# ability to specify the element is located below.##==============================================================================#==============================================================================# ** Script Configuration#==============================================================================module PickupThrowGift_Setup#--------------------------------------------------------------------------# ** Inputs#------------------------# C => Enter/Space/Z# B => X, Esc# L => Q# R => W# A => Shift#--------------------------------------------------------------------------# Pick-up Input and SFX# * Note: Set SFX to nil if no SE playsPICKUP_INPUT = Input::CPICKUP_SFX = RPG::SE.new("001-System01", 80, 50)# Put held item into inventory Input and SFX POCKET_INPUT = Input::LPOCKET_SFX = RPG::SE.new("003-System03", 80, 100)# Take item out of inventory Input and SFX TAKEOUT_INPUT = Input::RTAKEOUT_SFX = RPG::SE.new("001-System01", 80, 500)# Throw held item Input and SFX THROW_INPUT = Input::CTHROW_SFX = RPG::SE.new("063-Swing02", 80, 100)# The SFX used when an item is disposed ITEM_DISPOSED_SFX = RPG::SE.new("Ice9", 80, 100)# Element ID for items that can't be disposed and the SFXCANT_DISPOSE_ID = 18CANT_DISPOSE_SFX = RPG::SE.new("Buzzer1", 80, 100)#--------------------------------------------------------------------------# ** Variables#------------------------# GIFT_TYPE_VAR : the variable used to store an item's type# 1 => item# 2 => armor# 3 => weapon## GIFT_GIVEN_VAR : the ID of the item gifted##--------------------------------------------------------------------------GIFT_TYPE_VAR = 99GIFT_GIVEN_VAR = 100#--------------------------------------------------------------------------# ** Switches#------------------------# GIFT_GIVEN_SWITCH : the switch that turns on when a gift is given#------------------------GIFT_GIVEN_SWITCH = 4# Giftable item typesCAN_GIFT_ITEMS = trueCAN_GIFT_ARMOR = falseCAN_GIFT_WEAPON = falseend#==============================================================================# ** End Script Configuration#==============================================================================#==============================================================================# ** Game_Temp#==============================================================================class Game_Temp#--------------------------------------------------------------------------# * Public Instance Variables#--------------------------------------------------------------------------attr_accessor :move_waitattr_accessor :refresh_pickup_spritesattr_accessor :takeout_item_index#--------------------------------------------------------------------------# * Object Initialization#--------------------------------------------------------------------------alias :broken_ptg_gametemp_initialize :initializedef initializebroken_ptg_gametemp_initialize@move_wait = 0@refresh_pickup_sprites = false@takeout_item_index = 0 endend#==============================================================================# ** Game_System#==============================================================================class Game_System#--------------------------------------------------------------------------# * Object Initialization#--------------------------------------------------------------------------def check_giftreturn if $game_player.held_object.nil?obj = $game_player.held_objectitem = obj.get_itemcase itemwhen RPG::Itemif PickupThrowGift_Setup::CAN_GIFT_ITEMS$game_variables[PickupThrowGift_Setup::GIFT_TYPE_VAR] = 1$game_variables[PickupThrowGift_Setup::GIFT_GIVEN_VAR] = item.id$game_map.delete_puitem(obj)$game_player.held_object = nil$game_temp.refresh_pickup_sprites = true$game_switches[PickupThrowGift_Setup::GIFT_GIVEN_SWITCH] = true$game_party.remember_item_listendwhen RPG::Armorif PickupThrowGift_Setup::CAN_GIFT_ARMOR$game_variables[PickupThrowGift_Setup::GIFT_TYPE_VAR] = 2$game_variables[PickupThrowGift_Setup::GIFT_GIVEN_VAR] = item.id$game_map.delete_puitem(obj)$game_player.held_object = nil$game_temp.refresh_pickup_sprites = true$game_switches[PickupThrowGift_Setup::GIFT_GIVEN_SWITCH] = true$game_party.remember_item_listendwhen RPG::Weaponif PickupThrowGift_Setup::CAN_GIFT_WEAPON$game_variables[PickupThrowGift_Setup::GIFT_TYPE_VAR] = 3$game_variables[PickupThrowGift_Setup::GIFT_GIVEN_VAR] = item.id$game_map.delete_puitem(obj)$game_player.held_object = nil$game_temp.refresh_pickup_sprites = true$game_switches[PickupThrowGift_Setup::GIFT_GIVEN_SWITCH] = true$game_party.remember_item_listendendendend#==============================================================================# ** Game_Party#==============================================================================class Game_Party < Game_Unit#--------------------------------------------------------------------------# * Public Instance Variables#--------------------------------------------------------------------------attr_accessor :force_remember#--------------------------------------------------------------------------# * Object Initialization#--------------------------------------------------------------------------alias :broken_ptg_gameparty_initialize :initializedef initializebroken_ptg_gameparty_initialize@remembered_item_list = []@force_remember = trueend#--------------------------------------------------------------------------# * Remember Item List#--------------------------------------------------------------------------def remember_item_list@remembered_item_list = itemsend#--------------------------------------------------------------------------# * Get Remembered Item List#--------------------------------------------------------------------------def get_remembered_item_listreturn @remembered_item_listend#--------------------------------------------------------------------------# * Gain Items (or lose)#--------------------------------------------------------------------------alias :broken_ptg_gameparty_gainitem :gain_itemdef gain_item(item, n, include_equip = false)broken_ptg_gameparty_gainitem(item, n, include_equip)remember_item_list if @force_rememberend#--------------------------------------------------------------------------# * Gain Items (or lose), but don't remember it#--------------------------------------------------------------------------def gain_item_dont_remember(item, n, include_equip = false)@force_remember = falsegain_item(item, n, include_equip)@force_remember = trueend#--------------------------------------------------------------------------# * Lose items, but don't remember it#--------------------------------------------------------------------------def lose_item_dont_remember(item, n, include_equip = false)@force_remember = falsegain_item(item, -n, include_equip)@force_remember = trueendend#==============================================================================# ** Game_Map#==============================================================================class Game_Map#--------------------------------------------------------------------------# * Public Instance Variables#--------------------------------------------------------------------------attr_reader :puitems#--------------------------------------------------------------------------# * Object Initialization#--------------------------------------------------------------------------alias :broken_ptg_gamemap_initialize :initializedef initializebroken_ptg_gamemap_initialize@remembered_puitems = {}@copied_events = {}end#--------------------------------------------------------------------------# * Setup#--------------------------------------------------------------------------alias :broken_ptg_gamemap_setup :setupdef setup(map_id)broken_ptg_gamemap_setup(map_id)@remembered_puitems[@map_id] = [] if @remembered_puitems[@map_id].nil?@copied_events[@map_id] = [] if @copied_events[@map_id].nil?setup_pickup_items@added_puitems = []end#--------------------------------------------------------------------------# * Puck-up Item Setup#--------------------------------------------------------------------------def setup_pickup_items@puitems = []for event in @events.valuesif event.pickup_item? and not @copied_events[@map_id].include?(event.id)item = Game_PickupItem.new(event.get_item, event.x, event.y)@remembered_puitems[@map_id].push(item)@copied_events[@map_id].push(event.id)endendfor item in @remembered_puitems[@map_id]@puitems.push(item) endend#--------------------------------------------------------------------------# * Add Pick-up Item#--------------------------------------------------------------------------def add_puitem(item, x, y)new_puitem = Game_PickupItem.new(item, x, y)@remembered_puitems[@map_id].push(new_puitem)setup_pickup_itemsend#--------------------------------------------------------------------------# * Delete Pick-up Item#--------------------------------------------------------------------------def delete_puitem(item)for i in 0...@remembered_puitems[@map_id].sizeold_puitem = @remembered_puitems[@map_id][i]if item == old_puitem@remembered_puitems[@map_id].delete_at(i)setup_pickup_itemsbreakendendend#--------------------------------------------------------------------------# * Get Pick-up Item#--------------------------------------------------------------------------def get_puitem(x, y)for item in @puitemsif item.x == x and item.y == yreturn itemendendreturn nilend#--------------------------------------------------------------------------# * Frame Update#--------------------------------------------------------------------------alias :broken_ptg_gamemap_update :updatedef updatebroken_ptg_gamemap_updateupdate_pickup_itemsend#--------------------------------------------------------------------------# * Update Pickup Items#--------------------------------------------------------------------------def update_pickup_itemsfor item in @puitemsitem.updateendend#--------------------------------------------------------------------------# * Save Pickup Items#--------------------------------------------------------------------------def save_pickup_items(new_map_id)return if $game_player.held_object.nil?puitem = $game_player.held_objectclone = puitem.cloneif @remembered_puitems[new_map_id].nil?@remembered_puitems[new_map_id] = []end@remembered_puitems[new_map_id].push(clone)delete_puitem(puitem)$game_player.held_object = cloneendend#==============================================================================# ** Game_Character#==============================================================================class Game_Character#--------------------------------------------------------------------------# * Determine if Passable#--------------------------------------------------------------------------alias :broken_ptg_gamecharacter_passable :passable?def passable?(x, y)my_x = $game_map.round_x(x) my_y = $game_map.round_y(y) puitem = $game_map.get_puitem(my_x, my_y)return false unless puitem.nil?broken_ptg_gamecharacter_passable(x, y)endend#==============================================================================# ** Game_PickupItem#==============================================================================class Game_PickupItem < Game_Character#--------------------------------------------------------------------------# * Public Instance Variables#--------------------------------------------------------------------------attr_accessor :xattr_accessor :yattr_accessor :being_heldattr_accessor :being_thrownattr_accessor :dispose_after_throw#--------------------------------------------------------------------------# * Object Initialization#--------------------------------------------------------------------------def initialize(item, x, y)super()@item = item@being_held = false@being_thrown = false@dispose_after_throw = falsemoveto(x, y)end#--------------------------------------------------------------------------# * Object Initialization#--------------------------------------------------------------------------def fix_real_xy@real_x = @x * 256@real_y = @y * 256end#--------------------------------------------------------------------------# * Get Screen X-Coordinates#--------------------------------------------------------------------------def screen_xsx = superreturn sx - 12end#--------------------------------------------------------------------------# * Get Screen Y-Coordinates#--------------------------------------------------------------------------def screen_ysy = superreturn sy - 20end#--------------------------------------------------------------------------# * Get Screen Z-Coordinates#--------------------------------------------------------------------------def screen_zsz = super + 10sz += 10 if jumping?return szend#--------------------------------------------------------------------------# * Frame Update#--------------------------------------------------------------------------def updateif @dispose_after_throw and not @being_thrown$game_map.delete_puitem(self)$game_temp.refresh_pickup_sprites = trueunless PickupThrowGift_Setup::ITEM_DISPOSED_SFX.nil?PickupThrowGift_Setup::ITEM_DISPOSED_SFX.playendreturnend@being_thrown = false unless jumping?superend#--------------------------------------------------------------------------# * Get Item#--------------------------------------------------------------------------def get_itemreturn @itemend#--------------------------------------------------------------------------# * Item Can't Be Disposed?#--------------------------------------------------------------------------def cant_dispose?return @item.element_set.include?(PickupThrowGift_Setup::CANT_DISPOSE_ID)endend#==============================================================================# ** Game_Event#==============================================================================class Game_Event < Game_Character#--------------------------------------------------------------------------# * Public Instance Variables#--------------------------------------------------------------------------attr_reader :id#--------------------------------------------------------------------------# * Dispose Item?#--------------------------------------------------------------------------def dispose_item?return @event.name =~ /<(?:dispose_item)>/iend#--------------------------------------------------------------------------# * Can item be picked up? #--------------------------------------------------------------------------def pickup_item? return @event.name =~ /<(?:pickup)>/iend#--------------------------------------------------------------------------# * Get Item #--------------------------------------------------------------------------def get_itemitem = nilif @event.name =~ /<item(\d+)>/iitem = $data_items[$1.to_i]elsif @event.name =~ /<weapon(\d+)>/iitem = $data_weapons[$1.to_i]elsif @event.name =~ /<armor(\d+)>/iitem = $data_armors[$1.to_i]endreturn itemendend#==============================================================================# ** Game_Player#==============================================================================class Game_Player < Game_Character#--------------------------------------------------------------------------# * Public Instance Variables#--------------------------------------------------------------------------attr_accessor :held_object#--------------------------------------------------------------------------# * Object Initialization#--------------------------------------------------------------------------alias :broken_ptg_gameplayer_initialize :initializedef initializebroken_ptg_gameplayer_initialize@held_object = nilend#--------------------------------------------------------------------------# * Player Transfer Reservation#--------------------------------------------------------------------------alias :broken_ptg_gameplayer_reservetransfer :reserve_transferdef reserve_transfer(map_id, x, y, direction)broken_ptg_gameplayer_reservetransfer(map_id, x, y, direction)$game_map.save_pickup_items(map_id)end#--------------------------------------------------------------------------# * Processing of Movement via input from the Directional Buttons#--------------------------------------------------------------------------alias :broken_ptg_gameplayer_movebyinput :move_by_inputdef move_by_inputif $game_temp.move_wait > 0$game_temp.move_wait -= 1returnendbroken_ptg_gameplayer_movebyinputend#--------------------------------------------------------------------------# * Processing when not moving#--------------------------------------------------------------------------alias :broken_ptg_gameplayer_updatenonmove :update_nonmovingdef update_nonmoving(last_moving)unless $game_message.visible or moving?ptg = PickupThrowGift_Setupreturn if Input.trigger?(ptg::PICKUP_INPUT) and check_item_pickupreturn if Input.trigger?(ptg::POCKET_INPUT) and check_item_pocketreturn if Input.trigger?(ptg::TAKEOUT_INPUT) and check_item_takeoutreturn if Input.trigger?(ptg::THROW_INPUT) and check_throw_itemendbroken_ptg_gameplayer_updatenonmove(last_moving)end#--------------------------------------------------------------------------# * Check Item Pick-up#--------------------------------------------------------------------------def check_item_pickupreturn false if $game_map.interpreter.running?return false unless @held_object.nil?return false if $game_temp.move_wait > 0result = falsefront_x = $game_map.x_with_direction(@x, @direction)front_y = $game_map.y_with_direction(@y, @direction)item = $game_map.get_puitem(front_x, front_y)unless item.nil?jump_x = @direction == 4 ? 2 : @direction == 6 ? -2 : 0jump_y = @direction == 2 ? 2 : @direction == 8 ? -2 : 0item.jump(jump_x, jump_y)item.x = @xitem.y = @yitem.being_held = true@held_object = item$game_temp.move_wait = 0.5 * Graphics.frame_rateunless PickupThrowGift_Setup::PICKUP_SFX.nil?PickupThrowGift_Setup::PICKUP_SFX.play endresult = trueendreturn resultend#--------------------------------------------------------------------------# * Check Pocket Item#--------------------------------------------------------------------------def check_item_pocketreturn false if $game_map.interpreter.running?return false if @held_object.nil?return false if $game_temp.move_wait > 0$game_party.gain_item(@held_object.get_item, 1)$game_map.delete_puitem(@held_object)$game_temp.refresh_pickup_sprites = trueunless PickupThrowGift_Setup::POCKET_SFX.nil?PickupThrowGift_Setup::POCKET_SFX.playend@held_object = nilreturn trueend#--------------------------------------------------------------------------# * Check Item Takeout#--------------------------------------------------------------------------def check_item_takeoutreturn false if $game_map.interpreter.running?return false if $game_temp.move_wait > 0result = falseall_items = $game_party.get_remembered_item_listif @held_object.nil?$game_temp.takeout_item_index = 0elseif $game_temp.takeout_item_index > all_items.size - 1$game_temp.takeout_item_index = 0endenditem = all_items[$game_temp.takeout_item_index]unless item.nil?unless @held_object.nil?$game_party.gain_item_dont_remember(@held_object.get_item, 1) end$game_map.delete_puitem(@held_object)$game_party.lose_item_dont_remember(item, 1)$game_map.add_puitem(item, $game_player.x, $game_player.y)new_puitem = $game_map.get_puitem($game_player.x, $game_player.y)new_puitem.being_held = true@held_object = new_puitem$game_temp.refresh_pickup_sprites = true$game_temp.takeout_item_index += 1unless PickupThrowGift_Setup::TAKEOUT_SFX.nil?PickupThrowGift_Setup::TAKEOUT_SFX.playendresult = trueendreturn resultend#--------------------------------------------------------------------------# * Check Throw Item#--------------------------------------------------------------------------def check_throw_itemreturn false if $game_map.interpreter.running?return false if @held_object.nil?return false if $game_temp.move_wait > 0result = falsefront_x = $game_map.x_with_direction(@x, @direction)front_y = $game_map.y_with_direction(@y, @direction)events = $game_map.events_xy(front_x, front_y)if events.empty?if passable?(front_x, front_y)do_item_jump(front_x, front_y)result = trueendelsefor event in eventsif event.dispose_item?item = @held_objectif item.cant_dispose?unless PickupThrowGift_Setup::CANT_DISPOSE_SFX.nil?PickupThrowGift_Setup::CANT_DISPOSE_SFX.playendelsedo_item_jump(front_x, front_y)item.dispose_after_throw = trueresult = trueendelsif event.pickup_item?puitem_there = $game_map.get_puitem(event.x, event.y)if puitem_there.nil?do_item_jump(front_x, front_y) result = trueendendendendreturn resultend#--------------------------------------------------------------------------# * Do Item Jump#--------------------------------------------------------------------------def do_item_jump(x, y)jump_x = @direction == 4 ? -2 : @direction == 6 ? 2 : 0jump_y = @direction == 2 ? -2 : @direction == 8 ? 2 : 0item = @held_objectitem.fix_real_xyitem.jump(jump_x, jump_y)item.x = xitem.y = yitem.being_held = falseitem.being_thrown = true$game_party.remember_item_list@held_object = nil$game_temp.move_wait = 0.5 * Graphics.frame_rateunless PickupThrowGift_Setup::THROW_SFX.nil?PickupThrowGift_Setup::THROW_SFX.play endendend#==============================================================================# ** Spriteset_Map#==============================================================================class Spriteset_Map#--------------------------------------------------------------------------# * Create Character Sprite#--------------------------------------------------------------------------alias :broken_ptg_spritesetmap_creactecharacters :create_charactersdef create_charactersbroken_ptg_spritesetmap_creactecharacterscreate_pickup_itemsend#--------------------------------------------------------------------------# * Create Pick-up Item Sprite#--------------------------------------------------------------------------def create_pickup_items@pickup_sprites = []for pickup_item in $game_map.puitemssprite = Sprite.new(@viewport1)sprite.bitmap = Cache.system("IconSet")index = pickup_item.get_item.icon_indexsprite.src_rect = Rect.new(index % 16 * 24, index / 16 * 24, 24, 24)@pickup_sprites.push([pickup_item, sprite])endend#--------------------------------------------------------------------------# * Dispose#--------------------------------------------------------------------------alias :broken_ptg_spritesetmap_dispose :disposedef disposebroken_ptg_spritesetmap_disposedispose_pickup_itemsend#--------------------------------------------------------------------------# * Dispose Pick-up Item Sprites#--------------------------------------------------------------------------def dispose_pickup_itemsfor array in @pickup_spritessprite = array[1]sprite.disposeendend#--------------------------------------------------------------------------# * Frame Update#--------------------------------------------------------------------------alias :broken_ptg_spritesetmap_update :updatedef updatebroken_ptg_spritesetmap_updateif $game_temp.refresh_pickup_spritesdispose_pickup_itemscreate_pickup_items$game_temp.refresh_pickup_sprites = falseendupdate_pickup_itemsend#--------------------------------------------------------------------------# * Update Pick-up Items#--------------------------------------------------------------------------def update_pickup_itemsfor array in @pickup_spritesobj = array[0]sprite = array[1]if obj.being_held and not obj.jumping? obj.x = $game_player.xobj.y = $game_player.ysprite.x = $game_player.screen_x - 12sprite.y = $game_player.screen_y - 30sprite.z = obj.screen_zelsesprite.x = obj.screen_xsprite.y = obj.screen_y - 10sprite.z = obj.screen_zendsprite.updateendendend