Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Use/give items to NPCs

Status
Not open for further replies.
Basicly I want to be able to give NPCs gifts. Open the menu, choose the thing you want to give, use it and exit the menu. Then the NPC says thank you or whatever. I also want a certain variable to be set to +1 when you give them something they like. Each NPC would have a different variable and like different things. Is there any way to accomplish such a task?
 
This is a verrrrrrrrrry simple eventing process......I dont think someones gonna reply.
Go to set variables and set a variable to your item and use conditional branches in your npc event
 
I believe you misunderstood shannon's intention:
The request is for the whole item inventory to open, with all the items, and you choose one to give. This is as an action, not a quest.
 
Yeah, I want to make it so you can give an NPC just about anything from your inventory.

But maybe badmonur is onto something. The idea of setting a variable to the item did occur to me, but I never saw a cut and dry method of doing such a thing. I can make an item have a common event which I suppose could be used to trigger a variable but I could use the item a mile away from the target NPC and it would still set the variable. I'll try some ideas out and hopefully I can do this with eventing, but I will probably end up with something far from ideal.
 
You could set a few events that can only be used as gifts, or just select a few items that you could give. Then, upon talking to the NPC you could insert two options, namely to "Give gift" or not give anything at all. Selecting to give a gift would open up a new talk screen where you've selected a few items out of your inventory that can be given to the NPC. This is why it could be "gift" items, or just different items per NPC.
When you choose what item to give, you just remove one of that selected item from your inventory (using that item control thingy). And depending on which item you've chosen you can add a different amount of variables, even subtract some for some reason.
So technically, that would basically be like setting dialogue instead, but you just lose an item for it. I'm sure there are probably plenty of ideas much better than what I've suggested, cause this really limits everything down...
 

OS

Sponsor

Are you able to get items back?
If not, here is the script:
Code:
class Game_Event
  attr_accessor :items_gained
  alias os_init initialize
  def initialize(map_id, event)
    super()
    @items_gained = 0
    os_init
  end
  
  def items_gained?
    return true if @items_gained > 0
    return false
  end
end

#==============================================================================
# ** Scene_Item
#------------------------------------------------------------------------------
#  This class performs item screen processing.
#==============================================================================

class Scene_GiveItem
  def initialize(npc_id)
    @npc_id = npc_id
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make help window, item window
    @help_window = Window_Help.new
    @item_window = Window_Item.new
    # Associate help window
    @item_window.help_window = @help_window
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @help_window.dispose
    @item_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    @help_window.update
    @item_window.update
    # If item window is active: call update_item
    if @item_window.active
      update_item
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when item window is active)
  #--------------------------------------------------------------------------
  def update_item
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to menu screen
      $scene = Scene_Menu.new(0)
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Get currently selected data on the item window
      @item = @item_window.item
      # If not a use item
      unless @item.is_a?(RPG::Item)
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      $game_party.lose_item(@item.id,1)
      $game_map.events[@npc_id].items_gained += 1
      $scene = Scene_Map.new
      return
    end
  end
end

That was a quick edit, so I haven't tested it, but I'm fairly certain it will serve for your needs. It will only take a small edit to allow for the npc to know what is given to them, and to keep a database of those items given to them, so if you need me to, I can make the edit.

To use:
For checking the amount of items given to an npc, use:

amount = $game_map.events[event_id].items_gained

To activate the scene, use this in a Call Script command:

$scene = Scene_GiveItem.new(event_id)
 
Hey OptimistShadow. Could you help me out a bit?

I definitely would appreciate it if you edited the script to have as many different items as possible...well, not a million but at least twenty different "giveable" items, fifty would be even better but I'm not sure if I would actually use that many. I just want to make sure theres a few "dud" gifts that all NPCs will dislike along with some that only one NPC would like.

Also some more in-depth instructions as to how to use the script would really be helpful because I am pretty new to RMXP.

I assume the script would need the specific item name written in it. You can just give them generic names like "item01", and I can change all that later.

Anyway, thanks very much for your help. Please excuse me if this post is a bit incoherent. I just got home after partying and am a bit drunk.:D
 

OS

Sponsor

I think this will suit you better. You can have 0 giveable items, or 1000, or really any number you want.

Code:
#===============================================================================
# NPC Inventories
# By OS
#===============================================================================
# Use:
#
# All Events can be given items, but in order to do so, in the event you must
# Call Script: $scene = Scene_GiveItem.new(event_id), where event_id is the
# numerical id of the event.
#
# NEW
# In Module OS, in the Giveable array, you can put in the Item IDs of items
# that can be given to NPCs.
#
# NEW
# To check if a particular item has been given to an NPC, use
# Conditional Branch: Script: $game_map.events[id].items_include?(item_id),
# where event_id is the event's id, and item_id is the id of the particular
# item you are checking for.
#
# EDIT
# You can see how many items an NPC has by using Call Script:
# i = $game_map.events[event_id].item_count
#===============================================================================
module OS
  Giveable = [1,2,3,4,5,6,7,8,9,10]
end

class Game_Event
  attr_accessor :items
  alias os_init initialize
  def initialize(map_id, event)
    super()
    @items = []
    os_init
  end
  
  def items_gained?
    return true if @items.size > 0
    return false
  end
  
  def item_count
    return @items.size
  end
  
  def items_inlcude?(item_id)
    for i in 0..@items.size - 1
      if @items[i] == item_id
        return true
      end
    end
    return
  end
end

#==============================================================================
# ** Scene_Item
#------------------------------------------------------------------------------
#  This class performs item screen processing.
#==============================================================================

class Scene_GiveItem
  def initialize(npc_id)
    @npc_id = npc_id
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make help window, item window
    @help_window = Window_Help.new
    @item_window = Window_Item.new
    # Associate help window
    @item_window.help_window = @help_window
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @help_window.dispose
    @item_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    @help_window.update
    @item_window.update
    # If item window is active: call update_item
    if @item_window.active
      update_item
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when item window is active)
  #--------------------------------------------------------------------------
  def update_item
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to menu screen
      $scene = Scene_Menu.new(0)
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Get currently selected data on the item window
      @item = @item_window.item
      # If not a use item
      unless @item.is_a?(RPG::Item)
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      for i in 0..OS::Giveable.size - 1
        if @item.id == OS::Giveable[i]
          $game_party.lose_item(@item.id,1)
          $game_map.events[@npc_id].items << @item.id
        end
      end
      $scene = Scene_Map.new
      return
    end
  end
end

Peace!
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top