Galv’s Use Item on Event V.1.5

Demo – Version 1.4 > (demo uses old version)

#------------------------------------------------------------------------------#
#  Galv's Use Item on Event
#------------------------------------------------------------------------------#
#  For: RPGMAKER VX ACE
#  Version 1.5
#------------------------------------------------------------------------------#
#  2013-01-10 - version 1.5 - added a hopeful fix for strange issue
#  2012-12-13 - version 1.4 - added ability to set what happens when item is
#                             used on nothing (or an event with no <key> tag).
#                           - added a check for just category
#  2012-12-07 - version 1.3 - bug where sometimes item doesn't register
#  2012-12-07 - version 1.2 - fix indexing bug when changing categories
#  2012-12-07 - version 1.1 - fixed bug when only using 1 category
#  2012-12-07 - version 1.0 - release
#------------------------------------------------------------------------------#
#  This script allows you to bring up the "Use Key Item" box on the press of a
#  button. When you select an item, it then activates the event directly in
#  front of the player.
#  Using EVENTING knowledge, you can set up conditional branches that contain
#  'script' condition to tell the event what to do when the item the player
#  selected was used on that event.
#------------------------------------------------------------------------------#
#  SCRIPTS for CONDITIONAL BRANCHES
#------------------------------------------------------------------------------#
#
#  use_key?            # Returns true if you activated the event using an item.
#
#  key?(:category,item_id)    # Checks if that item was used.
#                             # :category can be any from CATEGORIES below.
#                             # item_id is the ID of the item from that category
#
#  keyc?(:category)           # Check if any item from that category was used
#
#------------------------------------------------------------------------------#
#  SCRIPT call for ENDING an item-initiated event (IMPORTANT)
#------------------------------------------------------------------------------#
#
#  end_key      # Use this instead of "Exit Event Processing" event command in
#               # your item activated events to clear the item ID if you want
#               # to end the event early like in the demo examples.
#
#------------------------------------------------------------------------------#
#  COMMENT TAG FOR EVENTS
#------------------------------------------------------------------------------#
#
#  <key>
#
#  Place a COMMENT in the event page with only this tag in it. Make sure the
#  comment is BELOW all conditional branches checking for item used on the event
#
#  Any event that has this comment will be activated when using an item on it
#  (just like if you used the action key). Any event without this tag will not
#  be activated at all and will revert to the common event id (selected below).
#
#------------------------------------------------------------------------------#
 
($imported ||= {})["Galvs_Use_Item_on_Event"] = true
module Galv_Key
 
#------------------------------------------------------------------------------#
#  SCRIPT SETTINGS
#------------------------------------------------------------------------------#  
 
  DISABLE_SWITCH = 1
 
  BUTTON = :X       # Button to call Key Item window (:X is "a")
 
  VARIABLE = 1      # Stores item ID in this variable to use in conditions
 
  NO_TARGET = 1     # Common event ID. This is called when the player uses an
                    # item on nothing and can be used to set what happens for
                    # each item/category in this event.
                    # IMPORTANT: Set to 0 if not used. Common event MUST have
                    # the key_end script call at the end of the event and end
                    # of any branch as normal.
 
  CATEGORIES = [                 # Categories of items that can be used on an
                                 # event. Cycle through these categories with
    [:key_item, "Key Items"],    # Q and W. Remove any you do not want to use
    [:item, "Items"],            # in your game.
    [:weapon, "Weapons"],
    [:armor, "Armor"],
 
    ] # don't touch
 
  CHANGE_CAT_LEFT = "S <  "      # Text before the heading
  LEFT_BUTTON = :Y               # Button to swap category to the left
  CHANGE_CAT_RIGHT = "  > D"     # Text after the heading
  RIGHT_BUTTON = :Z              # Button to swap category to the right
 
#------------------------------------------------------------------------------#
#  END SCRIPT SETTINGS
#------------------------------------------------------------------------------#  
 
end
 
class Game_Interpreter
 
  alias galv_key_item_interpreter_execute_command execute_command
  def execute_command
    if !@list[@index].nil?
      if @list[@index].code == 108
        $game_variables[Galv_Key::VARIABLE] = 0 if @list[@index].parameters[0] == "<key>"
      end
    end
    galv_key_item_interpreter_execute_command
  end
 
  def end_key
    @index = @list.size
    $game_variables[Galv_Key::VARIABLE] = 0
  end
 
  def use_key?
    $game_variables[Galv_Key::VARIABLE] > 0
  end
 
  def key?(cat,item_id)
    if cat == $game_system.key_item_cat && $game_variables[Galv_Key::VARIABLE] == item_id
      return true
    else
      return false
    end
  end
 
  def keyc?(cat)
    if cat == $game_system.key_item_cat && $game_variables[Galv_Key::VARIABLE] > 0
      return true
    else
      return false
    end
  end
 
end # Game_Interpreter
 
class Game_Player < Game_Character
 
  alias galv_key_item_move_by_input move_by_input
  def move_by_input
    galv_key_item_move_by_input
    if Input.trigger?(Galv_Key::BUTTON)
      return if $game_switches[Galv_Key::DISABLE_SWITCH] || jumping?
      $game_message.item_choice_variable_id = Galv_Key::VARIABLE if !$game_map.interpreter.running?
    end
  end
 
  def use_on_event
    case @direction
    when 2; dirx = 0; diry = 1
    when 4; dirx = -1; diry = 0
    when 6; dirx = 1; diry = 0
    when 8; dirx = 0; diry = -1
    end
 
    @enable_event = false
    for event in $game_map.events_xy(@x+dirx, @y+diry)
      event.list.count.times { |i|
        if event.list[i].code == 108 && event.list[i].parameters[0] == "<key>"
          @enable_event = true
        end
      }
    end
 
    if @enable_event
      event.start
    else
      if Galv_Key::NO_TARGET > 0
        $game_temp.reserve_common_event(Galv_Key::NO_TARGET)
      else
        $game_variables[Galv_Key::VARIABLE] = 0
      end
    end
  end
end # Game_Player < Game_Character
 
class Window_KeyItem < Window_ItemList
 
  alias galv_key_item_key_window_on_ok on_ok
  def on_ok
    galv_key_item_key_window_on_ok
    $game_player.use_on_event
    clear_heading
  end
 
  alias galv_key_item_key_window_on_cancel on_cancel
  def on_cancel
    galv_key_item_key_window_on_cancel
    clear_heading
  end
 
  alias galv_key_item_key_window_start start
  def start
    if !$game_switches[Galv_Key::DISABLE_SWITCH]
      self.category = $game_system.key_item_cat
      draw_heading
      update_placement
      refresh
      select(0)
      open
      activate
    else
      galv_key_item_key_window_start
    end
  end
 
  def draw_heading
    return if @heading != nil
    @heading = Sprite.new
    @heading.bitmap = Bitmap.new(Graphics.width, 25)
    @heading.bitmap.font.size = 25
    @heading.bitmap.font.color.set(text_color(0))
    @position = 0 if @position.nil?
    if Galv_Key::CATEGORIES.count > 1
      text = Galv_Key::CHANGE_CAT_LEFT + Galv_Key::CATEGORIES[@position][1] + Galv_Key::CHANGE_CAT_RIGHT
    else
      text = Galv_Key::CATEGORIES[@position][1]
    end
 
    @heading.bitmap.draw_text(@heading.bitmap.rect, text, 1)
 
    if @message_window.y >= Graphics.height / 2
      @heading.y = @message_window.height
    else
      @heading.y = Graphics.height - height + @message_window.height
    end
 
    @heading.z = z + 1
    @heading.opacity = 0
  end
 
  def clear_heading
    @heading.dispose
    @heading.bitmap.dispose
    @heading = nil
  end
 
  def enable?(item)
    if !$game_switches[Galv_Key::DISABLE_SWITCH]
      true
    else
      super
    end
  end
 
  def update
    super
    @heading.opacity = openness if !@heading.nil?
    if self.active && Galv_Key::CATEGORIES.count > 1
      if Input.trigger?(Galv_Key::LEFT_BUTTON)
        Galv_Key::CATEGORIES.each_with_index do |c,i|
          @position = i if c[0] == $game_system.key_item_cat
        end
        @position -= 1
        @position = Galv_Key::CATEGORIES.count - 1 if @position < 0
        self.category = $game_system.key_item_cat = Galv_Key::CATEGORIES[@position][0]
        clear_heading
        draw_heading
        select(0)
      end
      if Input.trigger?(Galv_Key::RIGHT_BUTTON)
        Galv_Key::CATEGORIES.each_with_index do |c,i|
          @position = i if c[0] == $game_system.key_item_cat
        end
        @position += 1
        @position = 0 if @position >= Galv_Key::CATEGORIES.count
        self.category = $game_system.key_item_cat = Galv_Key::CATEGORIES[@position][0]
        clear_heading
        draw_heading
        select(0)
      end
    end
  end
 
end # Window_KeyItem < Window_ItemList
 
class Game_System
  attr_accessor :key_item_cat
 
  alias galv_key_item_system_initialize initialize
  def initialize
    galv_key_item_system_initialize
    @key_item_cat = Galv_Key::CATEGORIES[0][0]
  end
end

75 thoughts on “Galv’s Use Item on Event V.1.5

  1. leoxfael16 says:

    I loved this man, is like the same sistem of the Crono Cross, very cool, nice work. But i have a bug to report, when you put a flash effect on the map, the script crash… Can you fix that?

    • Galv says:

      Can you please give more details like steps to duplicate the crash? Also, can you test it in a new project with no other scripts as the script shouldn’t affect the flash screen event command.

  2. leoxfael16 says:

    I put a parallel process with a flash effect of the engine, for simulate a storm, but when this gonna happen, the script crash, is like a incompatibility with the flash… Look, i made the same event on your example and this happen to… I uploaded for you sir, here: http://www.mediafire.com/file/f48u4lngo3ibvvx/Use_Item_on_Event_v.1_bug.exe

    • Galv says:

      Just looked at your game. Does it crash every time for you? It crashed the first time only in your file but I cannot get it to do it again… very strange. I’ve made a small update to the script (grab it again from this page) see if that fixes yours. I’ve tried like 50 more times and cannot crash it again :/

      • leoxfael16 says:

        The game crashed every time later, so i made a little modification in this line:
        “if @list[@index].parameters[0] == “” I just changed parameters[0] for parameters[1],
        and it worked without problems, but i do not have any idea of what i have done hahaha. But now i used this new version and works perfectly, thank you very much :D

  3. Justilizer017 says:

    I have spent a lot of time trying to make this script work, if possible could you send me a demo or a screenshot of the event using a key on a chest.

  4. Noir says:

    error occurs when I tent the window. I tried leoxfael16’s idea and the error stops and the game plays, but the tint doesn’t execute.

  5. Noir says:

    Maybe its this day/night script? sorry.

  6. Clubber says:

    I think the link for the demo is bad, it tells me that my browser cannot view the page to download the demo

  7. Hackazer says:

    can’t download the demo version, it says required authenticate when trying to download

  8. Marcos says:

    Sorry to bother you Galv… It is possible to use the normal item processing? I want to use the “A” key for something else…
    Excuse me for my bad English and thanks you very much for this great script.

    • Galv says:

      I don’t understand what you mean by the normal item processing. You can change the key used in the script if you want to use the “a” key for something else.

  9. Razvan says:

    Hey Galv, thanks for the script. I have a problem in which the bring up menu key (the “a” key) is not working. Do you know what could cause this?

  10. Razvan says:

    It worked! Thank you so much! :)

  11. I cannot get the npc to say anything after I give an item to them.

  12. Patrick says:

    Hello Galv, you said you could change the button input and I see where to do that. where it says X is a… so what if I want to use e? Because I looked at your older scripts, and there doesn’t seem to be any rhyme or reason to what the variable maps on the keyboard. For instance, Y and Z are two keys next to each other, but so are L and R.

    • Galv says:

      It’s how rpgmaker sets up keys.

      Test play your rpg and press F1 and look at the keyboard controls to see which keys are associated with which letter. By default rpgmaker doesn’t use the whole keyboard.

  13. Patrick says:

    Ok. thanks for the help and the quick response. I’ll see if I can figure out a way to make it work.

  14. Lemon says:

    hey gav i have the key but it still says how is that going to help you unlock the chest what am i doing wrong?

    • Galv says:

      You’re doing it wrong, but I can’t see what you are doing to tell you what. Look at the demo and see the example. Look at the numbers used and make sure they match the ID of the item used

  15. Lemon says:

    yeah i tho that what i was doing wrong i just seen it but i suck at sprites

  16. Lemon says:

    btw what is the line number i need to go to?

  17. Lemon says:

    Nvm thanks ablot i got it working sorry for bugging you i been useing all your sprites they all work for me

  18. Juan says:

    Hello!!!! there is a way to made de window invisible???? thanks!!!!!! :)

    • Juan says:

      Oh!!!!! and also change the position of the window to the center!!!!!! thanks!!!!!!!! I love your scripts!!!!!

      • Galv says:

        Sorry, I’m real busy at the moment so I can’t do requests – I recommend asking in an rpgmaker forum for some help doing it :)

  19. Sheryl says:

    I am trying to use this script, I played the demo, but when I play my own game, I push A (which I checked and it is set to X) and the use item menu does not pop up…nothing happens. Not sure what to do.

  20. Silverfire says:

    where do you put the script in order for it to work?

  21. Silverfire says:

    i tried putting it under the material section but it doesn’t seem to work

  22. Aleks says:

    Script ‘Galv’s Use Item On Event’ line 103: TypeError occurred.
    can’t convert String into Tone
    Any idea why this is happening? It only occurs when I try to transfer to a map while changing the screen tone

  23. Aleks says:

    I’m using the script from the demo, only because for some reason I always get syntax errors whenever I try to copy your script straight from this page. Probably something wrong with my browser. Do you think it would be fine with version 1.5?

  24. azure_san says:

    what exactly does DISABLE_SWITCH do and is it okay to make it 0?

    love the script btw. Just curious, since I have an event that automatically turns off a switch after getting a key item. Having it as switch 1 messes the inventory call is all.

    • Galv says:

      You set it to whatever switch you want to use. Then you can turn that switch on in game to disable this script from working.

      You should be able to set it to 0, or set it to another switch and don’t use that switch.

  25. Patrick says:

    Hello again Galv. I had a question. Is there any way to get this script to pause like the menu screen does? I’ve tried several fixes and I just can’t stop that enemy from walking up and helping them self to my spleen while I try to rifle through my inventory XD. I’ve tried setting a conditional branch to where they only move when the menu isn’t up, but that doesn’t work too well, and there’s no way around hazardous events that are on a timer.

  26. Patrick says:

    Ok. Thank you for your quick reply. I’ll ask around and see if I can find anything.

  27. CM Franz says:

    your scripts as well as your demos is very helpful specially for me who is just beginning to learn RM ace.

  28. Patrick says:

    How difficult would it be to get the script to affect how items are used in the main menu rather than the side menu? For instance, when an item is used straight out of the item menu it activates your script instead of a normal use. Sorry for being so needy with this one, but it’s a very unique script, and I don’t see any others like it.

  29. Luana says:

    Hi, I really love this script, but I’m just wondering if it is possible to select the item from the regular items menu? Not the other menu that uses the ‘a’ button?
    Thank you! ^w^

  30. Patrick says:

    For everyone who wants this script to activate from the main menu, here’s a solution

    http://www.rpgmakervxace.net/topic/31525-for-all-of-those-looking-for-a-witchs-house-item-use-solution/

  31. DC says:

    Hey Galv,When i try to open my menu it does not open in this script.. Need some help. Screen shot of the list of scripts that i have http://prntscr.com/7lvm3p ..

    • Galv says:

      In the script settings where it has DISABLE_SWITCH = 1
      That means if you use Control Switches in game and turn Switch 1 ON… then the script is disabled. Change it to a different switch number or 0 if you dont want to use it

  32. thelegendofwolf says:

    I love your scripts, Galv! Just one thing: When there is an event that has only one event page, and on that page there is a condition switch, the game will crash when using an item on the event if the condition is not yet on.
    This can be helped of course by just making an empty page for the event to start with.
    There is no problem, I just wanted to say it.
    Wolf

  33. RedEon says:

    Awesome script ! I wanted to know. How can I change the size and the place of the window?
    I’m searching for hours now and I can’t find how to do that :s ( Sorry my english isn’t very well :x )
    Thanks for all !

    – RedEon

  34. Zen says:

    Heya Galv, I was just wondering, I’ve been playing around with the demo and created a consumable item that I’m trying to use on the player from the menu, but it doesn’t work and I’m told that “Nothing happened”; Is there a way that consumable items may be used on the player if you’re not standing next to an object that the item can be used on?

    Thank you for all your great work!

    • Galv says:

      You would have to event that.
      In the settings, a common event can run if no target… set using:
      NO_TARGET = 1

      And the item id is stored in the variable you choose with
      VARIABLE = 1

  35. esdricoxd says:

    After I use ” DISABLE SWITCH = ”
    how can I re-enable the script?

  36. Hello Galv, amazing script ^^
    IS there a way to call the items menu? For example make a condition in the event that makes the items menu pop up.

Leave a comment