Script Call through pressing button

(Keep in mind that this is a 'VX' request.)

Can someone please help change this script. I want it to be a 'button pressing' script call.

So by calling the script to activate you'll need to press a button on your keyboard.

Example: pressing "S" on your keyboard will call/activate this script.

I'm not really sure how to describe it. Sorry.

 

This is the script:

Spoiler
Code:
#===============================================================================
# 
# Shanghai Simple Script - Pick Item Event
# Last Date Updated: 2010.05.25
# Level: Easy
# 
# This script prompts open a window to allow the player to select an item,
# weapon, or armor from the inventory to give the NPC, show the NPC, or whatever
# floats your boat. Works only on the map.
#===============================================================================
# Instructions
# -----------------------------------------------------------------------------
# To install this script, open up your script editor and copy/paste this script
# to an open slot below â–¼ Materials but above â–¼ Main. Remember to save.
# 
# These commands go into the script call event. Use any one of these.
#   $game_variables[1] = pick_item_event
#   $game_variables[1] = pick_weapon_event
#   $game_variables[1] = pick_armor_event
# 
# This will return the selected item's item ID, weapon ID, or armor ID to the
# game variable you stored. 0 is returned if the player cancels.
# 
# <key item>
# Place this tagin the noteboxes of your items, weapons, or armors to make
# you unable to select those items for the pick item event.
#===============================================================================
 
$imported = {} if $imported == nil
$imported["PickItemEvent"] = true
 
module SSS
  # This sets how many items will be shown by rows and columns.
  PICK_ITEM_ROWS = 8
  PICK_ITEM_COLS = 8
end
 
#==============================================================================
# RPG::BaseItem
#==============================================================================
 
class RPG::BaseItem
  #--------------------------------------------------------------------------
  # key_item
  #--------------------------------------------------------------------------
  def key_item
    return @key_item if @key_item != nil
    @key_item = false
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when /<(?:KEY_ITEM|key item)>/i
        @key_item = true
      end
    }
    return @key_item
  end
end
 
#==============================================================================
# ** Game_Interpreter
#==============================================================================
 
class Game_Interpreter
  #--------------------------------------------------------------------------
  # * Pick Item Event
  #--------------------------------------------------------------------------
  def pick_item_event
    return 0 unless $scene.is_a?(Scene_Map)
    return $scene.pick_item_event(:item)
  end
  #--------------------------------------------------------------------------
  # * Pick Weapon Event
  #--------------------------------------------------------------------------
  def pick_weapon_event
    return 0 unless $scene.is_a?(Scene_Map)
    return $scene.pick_item_event(:weapon)
  end
  #--------------------------------------------------------------------------
  # * Pick Armor Event
  #--------------------------------------------------------------------------
  def pick_armor_event
    return 0 unless $scene.is_a?(Scene_Map)
    return $scene.pick_item_event(:armor)
  end
end
 
#==============================================================================
# ** Window_Pick_Item
#==============================================================================
 
class Window_Pick_Item < Window_Selectable
  #--------------------------------------------------------------------------
  # * initialize
  #--------------------------------------------------------------------------
  def initialize(type)
    @type = type
    w = SSS::PICK_ITEM_COLS * 24 + 32
    x = Graphics.width - w
    h = [SSS::PICK_ITEM_ROWS * 24 + 32, Graphics.height - 184].min
    y = Graphics.height - h - 128
    super(x, y, w, h)
    self.index = 0
    self.openness = 0
    @column_max = SSS::PICK_ITEM_COLS
    @spacing = 0
    refresh
  end
  #--------------------------------------------------------------------------
  # * Item
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    @data = []
    case @type
    when :item, :items
      for item in $game_party.items
        next unless item.is_a?(RPG::Item)
        @data.push(item) if include?(item)
      end
    when :weapon, :weapons
      for item in $game_party.items
        next unless item.is_a?(RPG::Weapon)
        @data.push(item) if include?(item)
      end
    when :armor, :armors, :armour, :armours
      for item in $game_party.items
        next unless item.is_a?(RPG::Armor)
        @data.push(item) if include?(item)
      end
    end
    @item_max = @data.size
    create_contents
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  # * Include?
  #--------------------------------------------------------------------------
  def include?(item)
    return false if item.nil?
    return true
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #--------------------------------------------------------------------------
  def draw_item(index)
    rect = item_rect(index)
    self.contents.clear_rect(rect)
    item = @data[index]
    unless item.nil?
      icon = item.icon_index
      draw_icon(icon, rect.x, rect.y, enabled?(item))
      draw_item_amount(item, rect.clone)
    end
  end
  #--------------------------------------------------------------------------
  # * Enabled?
  #--------------------------------------------------------------------------
  def enabled?(item)
    return false if item.nil?
    return false if item.key_item
    return true
  end
  #--------------------------------------------------------------------------
  # * Draw Item Amount
  #--------------------------------------------------------------------------
  def draw_item_amount(item, rect)
    self.contents.font.size = 12
    number = $game_party.item_number(item)
    self.contents.font.color.alpha = enabled?(item) ? 255 : 128
    self.contents.draw_text(rect.x, rect.y + WLH/3, 24, WLH * 2/3, number, 2)
  end
end
 
#==============================================================================
# ** Window_Pick_Item_Help
#==============================================================================
 
class Window_Pick_Item_Help < Window_Base
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------
  def initialize(pick_item_window)
    @pick_item_window = pick_item_window
    y = @pick_item_window.y - 56
    w = [@pick_item_window.width, 200].max
    x = Graphics.width - w
    super(x, y, w, 56)
    self.openness = 0
    refresh
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
    super
    refresh if @last_item != @pick_item_window.item
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    item = @last_item = @pick_item_window.item
    draw_icon(item.icon_index, 0, 0)
    self.contents.draw_text(24, 0, contents.width - 24, WLH, item.name)
  end
end
 
#==============================================================================
# ** Scene_Map
#==============================================================================
 
class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  alias terminate_sss_pick_item_event terminate unless $@
  def terminate
    unless @pick_item_window.nil?
      @pick_item_window.dispose
      @pick_item_window = nil
      @pick_item_help.dispose
      @pick_item_help = nil
    end
    terminate_sss_pick_item_event
  end
  #--------------------------------------------------------------------------
  # * Pick Item Event
  #--------------------------------------------------------------------------
  def pick_item_event(type = :item)
    case type
    when :item, :items, :weapon, :weapons, :armor, :armors, :armour, :armours
      @pick_item_window = Window_Pick_Item.new(type)
      @pick_item_help = Window_Pick_Item_Help.new(@pick_item_window)
    else
      return 0
    end
    value = 0
    @pick_item_window.open
    @pick_item_help.open
    loop do
      update_basic
      @pick_item_window.update
      @pick_item_help.update
      if Input.trigger?(Input::
        Sound.play_cancel
        value = 0
        break
      elsif Input.trigger?(Input::C)
        item = @pick_item_window.item
        if @pick_item_window.enabled?(item)
          Sound.play_decision
          value = item.id
          break
        else
          Sound.play_buzzer
        end
      end
    end
    @pick_item_window.close
    @pick_item_help.close
    loop do
      update_basic
      @pick_item_window.update
      @pick_item_help.update
      break if @pick_item_window.openness == 0
    end
    @pick_item_window.dispose
    @pick_item_window = nil
    @pick_item_help.dispose
    @pick_item_help = nil
    return value
  end
end
 
#===============================================================================
# 
# END OF FILE
# 
#===============================================================================

 

This script haves nothing to do with what i'm saying but this is kinda like how i want it.

Spoiler
Code:
#####################################################
# On-Screen Equip                                   #
# by new (momo)                                     #
# for My Lazy Afternoon                             #  
# plug and play                                     #
# insert under �–� Materials,  above �–� Main Process   #
# date created: 2/23/2013                           #    
#####################################################
 
class Scene_Map < Scene_Base
#--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    $game_map.interpreter.update      # Update interpreter
    $game_map.update                  # Update map
    $game_player.update               # Update player
    $game_system.update               # Update timer
    @spriteset.update                 # Update sprite set
    @message_window.update            # Update message window
    unless $game_message.visible      # Unless displaying a message
      update_transfer_player
      update_encounter
      update_call_menu
      update_call_debug
      update_scene_change
      call_equip
    end
  end
  #--------------------------------------------------------------------------
  # �—� call equip
  #--------------------------------------------------------------------------
  def call_equip
    return if $game_system.menu_disabled            # Menu forbidden?
    if Input.press?(Input::X)         # when L button is pressed
    Sound.play_decision
    $game_temp.next_scene = nil 
    Sound.play_decision
    $scene = Scene_OSEquip.new
    end
  end
  
end
 
#==============================================================================
# ** Window_OSEquip
#------------------------------------------------------------------------------
#  This window displays items the actor is currently equipped with on the
# equipment screen.
#==============================================================================
 
class Window_OSEquip < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     x     : window X coordinate
  #     y     : window Y corrdinate
  #     actor : actor
  #--------------------------------------------------------------------------
  def initialize(x, y, actor)
    super(x, y, 272, WLH + 32)
    @item_max = 1
    @actor = actor
    refresh
    self.index = 0
  end
      
  #--------------------------------------------------------------------------
  # * Get Item
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    @data = []
    for item in @actor.weapons do @data.push(item) end
    @item_max = @data.size
    self.contents.font.color = system_color
    draw_item_name(@data[0], 4, WLH * 0)
  end
  #--------------------------------------------------------------------------
  # * Update Help Text
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(item == nil ? "" : item.description)
  end
end
 
#==============================================================================
# ** Scene_OSEquip
#------------------------------------------------------------------------------
#  This class performs the equipment screen processing.
#==============================================================================
 
class Scene_OSEquip < Scene_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     actor_index : actor index
  #     equip_index : equipment index
  #--------------------------------------------------------------------------
  def initialize(actor_index = 0, equip_index = 0)
    @actor_index = actor_index
    @equip_index = equip_index
  end
  #--------------------------------------------------------------------------
  # * Start processing
  #--------------------------------------------------------------------------
  def start
    super
    create_menu_background
    @actor = $game_party.members[@actor_index]
    @help_window = Window_Help.new
    @equip_window = Window_OSEquip.new(136, 112, @actor)
    @equip_window.help_window = @help_window
    @equip_window.index = @equip_index
    @item_window = Window_EquipItem.new(0, 208, 544, 208, @actor, 0)
    @item_window.help_window = @help_window
    @item_window.active = false
    @item_window.index = -1
  end
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  def terminate
    super
    dispose_menu_background
    @help_window.dispose
    @equip_window.dispose
    dispose_item_windows
  end
  #--------------------------------------------------------------------------
  # * Return to Original Screen
  #--------------------------------------------------------------------------
  def return_scene
    $scene = Scene_Map.new
  end
  #--------------------------------------------------------------------------
  # * Update Frame
  #--------------------------------------------------------------------------
  def update
    super
    update_menu_background
    @help_window.update
    update_equip_window
    update_item_windows
    if @equip_window.active
      update_equip_selection
    elsif @item_window.active
      update_item_selection
    end
  end
  #--------------------------------------------------------------------------
  # * Dispose of Item Window
  #--------------------------------------------------------------------------
  def dispose_item_windows
    @item_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Update Item Window
  #--------------------------------------------------------------------------
  def update_item_windows
    @item_window.visible = true
    @item_window.update
  end
  #--------------------------------------------------------------------------
  # * Update Equipment Window
  #--------------------------------------------------------------------------
  def update_equip_window
    @equip_window.update
  end
  #--------------------------------------------------------------------------
  # * Update Equip Region Selection
  #--------------------------------------------------------------------------
  def update_equip_selection
    if Input.trigger?(Input::
      Sound.play_cancel
      return_scene
    elsif Input.trigger?(Input::C)
        Sound.play_decision
        @equip_window.active = false
        @item_window.active = true
        @item_window.index = 0
    end
  end
  #--------------------------------------------------------------------------
  # * Update Item Selection
  #--------------------------------------------------------------------------
  def update_item_selection
    if Input.trigger?(Input::
      Sound.play_cancel
      @equip_window.active = true
      @item_window.active = false
      @item_window.index = -1
    elsif Input.trigger?(Input::C)
      Sound.play_equip
      @actor.change_equip(0, @item_window.item)
      @equip_window.active = true
      @item_window.active = false
      @item_window.index = -1
      @equip_window.refresh
      @item_window.refresh
    end
  end
end
Can you explain how you activate it now? Do you have a link to the original script (or to its topic, where it's probably explained in more detail)? I'd also like to see a screenshot of how it looks now - I want to know what's so special about it that it's not contained in its own scene. Is it just like the Select Key Item event command that's new with Ace?


It's really not nice to have a script that adds a couple of loops within Scene_Map. If I were doing this, I'd rewrite that whole method so it uses the default update cycle, with no loops. But that's beside the point.
The Topic.

http://www.rpgmakervx.net/index.php?showtopic=31022&hl=SSS

Original Script:

http://www.rpgmakervx.net/index.php?showtopic=45901

Pic: Sorry it's so blurry. I was too lazy to make and upload my own.

url_zps08f3c9fb.jpg
Even if you have it called by pressing a button, you still need to specify what variable will take the item/armor/weapon id.


So just use a parallel process common event (ugh! Can't believe I'm saying this) that does a Conditional Branch for Button <whatever> is being Pressed, and have it do the $game_variables[x] = pick_item_event call.
That's what I did, but whenever I press the button it says error and crashes
Then it means your script call is wrong in some way. Post a pic of your event, as well as a pic of the error.
The Event I made is made up of 2 switches 4 Common Events and 4 Events.

You know what, never mind about this.

This script request was just a test I was experimenting. But I don't think it'll work.

Unless you have some other idea?
I am not giving up. If you want to, it's up to you. But you can't say "it doesn't work, I need to try something different" every time you get an error or a bug - at some point you're going to have to sit down and figure out WHY it's not working, and actually fix it. I bet you've got it almost working, and it's probably just a typo or some other little thing that's causing the crash.


I just need you to provide the information I asked for in order to locate the issue. In this case, a screenshot of your event so we can see the whole thing. The particular event I want to see is the one that contains the script call that's causing the crash.
Do you own VX? Can I send you a project of it.
Yes. Just zip it up somewhere and send me a link.


Put the starting point (or give me a save file) so I can call it right away, if it depends on location. And let me know what to do to make the error happen.
Okay, you'll have to wait a while. 🙂
no worries.


But a screenshot of the event, showing where it calls the script, is REALLY all I need to see .
https://www.dropbox.com/s/fnmoeojwt9lus56/Project1.exe
Yeah, I've got it. It's because of all the loops you have in the parallel process event, among other things.


I also noticed an error in that you change the sprite BEFORE a gift has been chosen, and if you escape without making a choice, the sprite stays the same (with the gift).


I HAVE solved both of these problems, so you can trigger it with the S button. But I have to duck away from the PC for a while and don't have time to go into the explanations and write up the solution for you.


I'll do that as soon as I get back. But know that your events are going to be a LOT more simple than you currently have them.


edit: mmm ... if you choose a gift, then press ESC before giving it to the girl, the gift disappears. Is that what you want to happen? Or is the ESC ONLY to be monitored while the item window is up?
I got rid of every loop but it still crashes. I'll wait for your solution then...
I posted another question while you were typing.


If you choose a gift, then hit ESC before you give the gift to the girl, you lose the gift. Is that meant to happen? Or should it only cancel with ESC while you're in the gift-choosing screen?
That's what I wanted to happen.

When you select a gift and press "X Key" the item will go back into your inventory.

I updated the project with the fixed bugs.

So you can check it out if you if you want.
Okay ... here's what I did.

Your parallel process (map) event should look like this:

PAGE 1 - Trigger = Parallel Process

Conditional Branch: The Y Button is Being Pressed Control Switches: [0002: Common Event 2, Activate] = ON Script: $game_variables[1] = pick_item_event Conditional Branch: Variable [0001: Pick Item] != 0 Set Move Route: Player (Wait) : $>Graphic: 'Actor1', 1 Branch EndBranch EndPAGE 2 - Trigger = Action ButtonConditions = Switch 0002: Common Event 2, Activate is ON

no event commands.

Then in your Common Event 2, remove the Set Move Route command.

That's it.

---------------------------------------

I think your errors were because of all the loops and break loops you had inside a parallel process event, the fact that the parallel process event was still running while the item select window was open, and that you were doing a Call Common Event to call a parallel processing event that was already active because the switch had already been turned on.
https://www.dropbox.com/s/fnmoeojwt9lus56/Project1.exe

I didn't do the exact thing you made but what I did fixed the crashing. The only problem left is that, when you select an item and try to press 'B' the menu screen appears.

Original thread: https://forums.rpgmakerweb.com/threads/script-call-through-pressing-button.20357/