[VX] Pick-Up Script and Event Cloning

Discussion in 'RGSSx Script Support' started by Erangot, Mar 27, 2015.

  1. Erangot

    Erangot Veteran Veteran

    Messages:
    56
    Likes Received:
    68
    Location:
    Philippines
    First Language:
    Filipino
    Hi everyone! I was hoping someone would help me out regarding the scripts I use for this game I'm developing.

    For my farming system I am using Sinmora's Gift & Pickup Script and FlipelyFlip's/Kread-Ex's Cloning Script which I will post later at the bottom (since I can't find the original links any longer). Here are the following problems
     

    • Would it be possible to add a script call to delete a cloned event from the map?
       
    • The cloned events have the same ID from the original, right? I'm not entirely sure if around these lines I should add a condition where an event cannot be stacked above another event that has its same ID. (Those with different ID nos. can be stacked, however)
      if Flipely.passable? == true $game_map.add_event($game_variables[id],$game_variables[id],$game_variables[id],$game_variables[id]) $scene = Scene_Map.new else
    Scripts:
    Pick-up Script

    Code:
    #==============================================================================# ** 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 = [99]GIFT_GIVEN_VAR = [100]#--------------------------------------------------------------------------# ** Switches#------------------------# GIFT_GIVEN_SWITCH : the switch that turns on when a gift is given#------------------------GIFT_GIVEN_SWITCH = 12# 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 - 40sprite.z = obj.screen_zelsesprite.x = obj.screen_xsprite.y = obj.screen_ysprite.z = obj.screen_zendsprite.updateendendend
    Cloning Event Script
    Code:
    #==============================================================================# ** Events Cloning Script V1.1#------------------------------------------------------------------------------# by FlipelyFlip#------------------------------------------------------------------------------# thx goes to: Kread-EX#===============================================================================beginThis little script allows you to copy an event from another map to set it on thelocated coordinates. You can also call it by variables. You have to config theVariables under the module Flipely. So you can set the x and y coordinate at thevariables to random. If the coordinates are on an impassable place, they will beset one place right and one place down. If this place is also impassable, it willadd again the one place right and one place down.This Feature is only at the variable available.To call the script you can chose between$game_map.add_event(map_id,event_id,x,y)or you will do it with variables, then you have to set up the variables beforecalling it with Flipely.koordinaten .greetings FlipelyFlip=endclass Spriteset_Map  def refresh    $game_map.need_refresh = true    unless @character_sprites == nil       for sprite in @character_sprites         sprite.dispose       end     end    @character_sprites = []     for i in $game_map.events.keys.sort       sprite = Sprite_Character.new(@viewport1, $game_map.events[i])       @character_sprites.push(sprite)     end     @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))  endendclass Game_Map  def add_event(map_id,id,x,y)    s = 1    (1..@events.size + 1).each{|s|break unless @events.keys.include?(s)}    map = load_data(sprintf("Data/Map%03d.rvdata", map_id))     ev = map.events[id]     ev.id = s     @events[s] = Game_Event.new(@map_id, ev)    @events[s].moveto(x, y)    ## Kread    $game_party.cloned_events = {} if $game_party.cloned_events.nil?    if $game_party.cloned_events[@map_id].nil?      $game_party.cloned_events[@map_id] = []    end    unless $game_party.cloned_events[@map_id].include?([map_id, id, x, y])      $game_party.cloned_events[@map_id].push([map_id, id, x, y])    end ##    return @events[s].id  end  ## Kread  alias_method(:krx_clonev_gm_se, :setup_events)  def setup_events    krx_clonev_gm_se    unless $game_party.cloned_events.nil? ||    $game_party.cloned_events[@map_id].nil?      $game_party.cloned_events[@map_id].each do |array|        add_event(array[0], array[1], array[2], array[3])      end    end  end ##endmodule Flipely  def self.passable?    return $game_map.passable?($game_variables[id], $game_variables[id], flag = 0x01)  endendmodule Flipely  def self.koordinaten    if Flipely.passable? == true      $game_map.add_event($game_variables[id],$game_variables[id],$game_variables[id],$game_variables[id])      $scene = Scene_Map.new    else      $game_variables[id] += 1 # change it if you want      $game_variables[id] += 1 # change it if you want      Flipely.koordinaten    end  endend## Kreadclass Game_Party < Game_Unit  attr_accessor  :cloned_eventsend ##
    That's all for now, but I'll probably ask more questions in the future. Thank you so much in advance if anyone will try to help me out. It's going to be a huge help for me.
     
    Last edited by a moderator: Mar 28, 2015
    #1

Share This Page