Bargain / negotiation mechanic on prices

Hello everyone. I've been pondering the idea of implementing a little bargain / negotiation mechanic aside from the usual buy and sell RPGM offers.

I don't know if something like this is possible with eventing alone, that's why I'm asking here. I have tried, but I have only achieved basic conditional choices that are fixed, not fun to play. However, If someone could explain to me step by step something like the example below with eventing I would gladly take it! Or, if a similar script already exists, it would be great if you could share the link.

Bargain mechanic:

Basically I have this NPC with whom you have the option to open his shop or bargain. Upon selecting bargain, the dialogue box appears with the merchant asking "Which item do you want to bargain?". A window should appear to choose the quantity of the item you want (you can buy in bulk but only of the same item) and after confirming, the merchant says "Tell me a price", and the input code screen opens.

I imagine the "math" for the negotiation phase would be something like this: the merchant is always going to be willing to sell items at a 5% discount. That's an instantaneous sell. However, depending on the item you are trading and their secret "mood" bar, you can get them to sell items cheaply. I will call this segment of possibility "negotiable area", where the trader offers prices back.
  • The default range of the "negotiable area" varies by item ID, yet gets affected in the negotiation phase by the "mood" of the merchant.
  • The merchant has a secret "mood" bar which starts at 50 (the middle, 100 is max mood).
  • With each bad offer, they lose "mood" (let's say -10) and in doing so the price to which they are willing to lower gets limited, that is, the "negotiable area" shrinks towards higher prices. With each good offer, the "negotiable area" becomes more flexible towards the lowest prices and they gain "mood" (let's say +10).
  • The merchant will accept the bargain when their mood gets at 80, or won't accept more lower offers when their mood gets at 20, to put some numbers.
  • As I said, depending on the item the "negotiable area" is bigger or smaller by default, but gets also affected by the trader's mood. The NPC of course has a minimum price limit they will accept.
  • If more than one item is being negotiated, the sum is used as a reference, with the same corresponding "negotiable areas'. Ex.: if a ring costs 300 and you bargain two of them, the reference price is 600 (insta-sell would be the 5% of 600, and the "negotiable area" and lowest price are proportional, based on the item).
  • You can only bargain when a certain switch is on.

In a nutshell, Genshin Impact's bargain system, but the shopkeeper can bargain prices back.

That's all folks. If someone could help me with this by making a script or showing me a tutorial for the eventing it would be greatly appreciated. It doesn't need to be exactly like description above, just have the ability of the shopekeeper to counter offer and be fun.
I think I got most of what you wanted. Please give it a try and let me know if there are any changes required.
Spoiler: Shop Bargain v1.02
Ruby:
# ╔═══════════════════════════════════════════════╦════════════════════╗
# ║ Title: Shop Bargain                           ║  Version: 1.02     ║
# ║ Author: Roninator2                            ║                    ║
# ╠═══════════════════════════════════════════════╬════════════════════╣
# ║ Function:                                     ║   Date Created     ║
# ║                                               ╠════════════════════╣
# ║   Set bargaining for shop items               ║    12 Jun 2024     ║
# ╚═══════════════════════════════════════════════╩════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Requires: nil                                                      ║
# ║                                                                    ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Brief Description:                                                 ║
# ║       Haggle with the shop owner for paying a lower price          ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Instructions:                                                      ║
# ║   Detail notes in Module settings below                            ║
# ║                                                                    ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Updates:                                                           ║
# ║ 1.00 - 12 Jun 2024 - Script finished                               ║
# ║ 1.01 - 13 Jun 2024 - Fixed bug and added shop keep face            ║
# ║ 1.02 - 13 Jun 2024 - Fixed bug and added shop text in module       ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Credits and Thanks:                                                ║
# ║   Roninator2                                                       ║
# ║                                                                    ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Terms of use:                                                      ║
# ║  Follow the original Authors terms of use where applicable         ║
# ║    - When not made by me (Roninator2)                              ║
# ║  Free for all uses in RPG Maker except nudity                      ║
# ║  Anyone using this script in their project before these terms      ║
# ║  were changed are allowed to use this script even if it conflicts  ║
# ║  with these new terms. New terms effective 03 Apr 2024             ║
# ║  No part of this code can be used with AI programs or tools        ║
# ║  Credit must be given                                              ║
# ╚════════════════════════════════════════════════════════════════════╝

#==============================================================================
# ** R2_Bargain_Shop
#==============================================================================
module R2_Bargain_shop
  SHOP_VARIABLE = 10 # variable used to control which shop keeper
  # mood config to use.
  BARGAIN_SWITCH = 10 # switch used to run bargain scene. turn on when
  # you want to enter the bargain shop.
  BARGAIN_TITLE = "Bargain with the Shopkeep"
  # Do not touch
  BARGAIN_ITEM = /<bargain:[ ]*(\d+)>/i # do not touch
  # pass is for when the purchase is successful
  # the mood will increase for the shopkeeper
  PASS = 5  # will increase by multiples of amounts below
  FAIL = 10 # will decrease by this amount
  MORE = 5  # will decrease by this amount when offer is not favorable (random)
  LOW = 1   # PASS times LOW when offer is higher than the minimum
  MID = 2   # PASS times MID when the offer is higher than the low + item bargain
  FULL = 3  # PASS times FULL when the offer is higher than the original cost
  # minimum is calculated by Full price - item variance - mood adjustment
  # mid is calculated by low plus mood variance
  # full is the item listed price
  #
  # Variance is calculated by the item bargain price times item number
  # <Bargain: 10> and buying 2 potions, means 10 * 2 = 20
  # if item has no note tag, variance is 0.05 * item price * item number
  #
  # Mood is calculated by variance * mood value / 100
  # 20 * 50 / 100 = 10
  # 
  # Bargain Digits
  DIGITS = 6 # 6 is for numbers as high as 999,999
  # Shop keeper image filename
  SHOPKEEP_IMAGE = "Actor5"
  # shop keep images are configured on lines 480 -520
  # using the offer conditions to change the image
  # they can be changed the in code so you don't have to change the image file.
  #
  # Price text shown after selecting how many items to buy
  PRICE_TEXT = "Asking Price"
  # text for what you are gong to offer
  OFFER = "Offer"
  # Message when offer is good
  GOOD_DEAL = "That's a good deal"
  # message when negotiating
  BETTER_OFFER = "I think you can do better"
  # message when not enough money
  NO_MONEY = "Invalid Funds"
  # message when offer is too low
  BAD_DEAL = "I don't like your offer"
end
  
# ╔════════════════════════════════════════════════════════════════════╗
# ║                      End of editable region                        ║
# ╚════════════════════════════════════════════════════════════════════╝

$imported = {} if $imported.nil?
$imported[:r2_bargain_shop] = 1.02

#==============================================================================
# ** DataManager Load Notetag
#==============================================================================
module DataManager
  class <<self; alias load_database_r2_bargain_load_database load_database; end
  def self.load_database
    load_database_r2_bargain_load_database
    load_notetags_bargain_items
  end
  def self.load_notetags_bargain_items
    groups = [$data_items, $data_weapons, $data_armors]
    for group in groups
      for obj in group
        next if obj.nil?
        obj.load_notetags_bargain_items
      end
    end
  end
end

#==============================================================================
# ** Load Item Notetag
#==============================================================================
class RPG::Item < RPG::UsableItem
  attr_accessor :bargain
  def load_notetags_bargain_items
    @bargain = 0
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when R2_Bargain_shop::BARGAIN_ITEM
        @bargain = $1.to_i
      end
    }
  end
end

#==============================================================================
# ** Load Item Notetag
#==============================================================================
class RPG::Weapon < RPG::EquipItem
  attr_accessor :bargain
  def load_notetags_bargain_items
    @bargain = 0
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when R2_Bargain_shop::BARGAIN_ITEM
        @bargain = $1.to_i
      end
    }
  end
end

#==============================================================================
# ** Load Item Notetag
#==============================================================================
class RPG::Armor < RPG::EquipItem
  attr_accessor :bargain
  def load_notetags_bargain_items
    @bargain = 0
    self.note.split(/[\r\n]+/).each { |line|
      case line
      when R2_Bargain_shop::BARGAIN_ITEM
        @bargain = $1.to_i
      end
    }
  end
end

#--------------------------------------------------------------------------
# * Game Interpreter - Overwrite shop call method
#--------------------------------------------------------------------------
class Game_Interpreter
  def command_302
    return if $game_party.in_battle
    goods = [@params]
    while next_event_code == 605
      @index += 1
      goods.push(@list[@index].parameters)
    end
    if $game_switches[R2_Bargain_shop::BARGAIN_SWITCH]
      SceneManager.call(Scene_Bargain_Shop)
      SceneManager.scene.prepare(goods)
    else
      SceneManager.call(Scene_Shop)
      SceneManager.scene.prepare(goods, @params[4])
    end
    Fiber.yield
  end
end
 
#==============================================================================
# ** Game_Party
#==============================================================================
class Game_Party
  attr_accessor :shop_mood
  alias :r2_party_init_bargain_shop   :initialize
  def initialize
    r2_party_init_bargain_shop
    @shop_mood = []
  end
end


#==============================================================================
# ** Window_Help
#------------------------------------------------------------------------------
#  This window shows skill and item explanations along with actor status.
#==============================================================================

class Window_BargainHelp < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(line_number = 2)
    super(0, Graphics.height - fitting_height(line_number), Graphics.width, fitting_height(line_number))
  end
  #--------------------------------------------------------------------------
  # * Set Text
  #--------------------------------------------------------------------------
  def set_text(text)
    if text != @text
      @text = text
      refresh
    end
  end
  #--------------------------------------------------------------------------
  # * Clear
  #--------------------------------------------------------------------------
  def clear
    set_text("")
  end
  #--------------------------------------------------------------------------
  # * Set Item
  #     item : Skills and items etc.
  #--------------------------------------------------------------------------
  def set_item(item)
    set_text(item ? item.description : "")
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_text_ex(4, 0, @text)
  end
end

#==============================================================================
# ** Window_Title
#==============================================================================
class Window_BargainTitle < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, window_width, fitting_height(1))
    refresh
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return Graphics.width
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_text(0, 0, Graphics.width, 24, R2_Bargain_shop::BARGAIN_TITLE, 1)
  end
end

#==============================================================================
# ** Window_BargainGold
#==============================================================================

class Window_BargainGold < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, window_width, fitting_height(1))
    refresh
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return Graphics.width / 2
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_currency_value(value, currency_unit, 4, 0, contents.width - 8)
  end
  #--------------------------------------------------------------------------
  # * Get Party Gold
  #--------------------------------------------------------------------------
  def value
    $game_party.gold
  end
  #--------------------------------------------------------------------------
  # Get Currency Unit
  #--------------------------------------------------------------------------
  def currency_unit
    Vocab::currency_unit
  end
  #--------------------------------------------------------------------------
  # * Open Window
  #--------------------------------------------------------------------------
  def open
    refresh
    super
  end
end

#==============================================================================
# ** Window_ShopCommand
#------------------------------------------------------------------------------
#  This window is for selecting buy/sell on the shop screen.
#==============================================================================

class Window_BargainShopCommand < Window_HorzCommand
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(window_width)
    @window_width = window_width
    super(0, 0)
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    @window_width
  end
  #--------------------------------------------------------------------------
  # * Get Digit Count
  #--------------------------------------------------------------------------
  def col_max
    return 2
  end
  #--------------------------------------------------------------------------
  # * Create Command List
  #--------------------------------------------------------------------------
  def make_command_list
    add_command(Vocab::ShopBuy,    :buy)
    add_command(Vocab::ShopCancel, :cancel)
  end
end

#==============================================================================
# ** Window_BargainShopNumber
#==============================================================================

class Window_BargainShopNumber < Window_Selectable
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :number                   # quantity entered
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(x, y, height)
    super(x, y, window_width, height)
    @item = nil
    @max = 1
    @price = 0
    @number = 1
    @currency_unit = Vocab::currency_unit
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return 300
  end
  #--------------------------------------------------------------------------
  # * Set Item, Max Quantity, Price, and Currency Unit
  #--------------------------------------------------------------------------
  def set(item, max, currency_unit = nil)
    @item = item
    @max = max
    @currency_unit = currency_unit if currency_unit
    @number = 1
    refresh
  end
  #--------------------------------------------------------------------------
  # * Set Currency Unit
  #--------------------------------------------------------------------------
  def currency_unit=(currency_unit)
    @currency_unit = currency_unit
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_item_name(@item, 0, item_y)
    draw_number
  end
  #--------------------------------------------------------------------------
  # * Draw Quantity
  #--------------------------------------------------------------------------
  def draw_number
    change_color(normal_color)
    draw_text(cursor_x - 28, item_y, 22, line_height, "×")
    draw_text(cursor_x, item_y, cursor_width - 4, line_height, @number, 2)
  end
  #--------------------------------------------------------------------------
  # * Y Coordinate of Item Name Display Line
  #--------------------------------------------------------------------------
  def item_y
    contents_height / 2 - line_height * 3 / 2
  end
  #--------------------------------------------------------------------------
  # * Y Coordinate of Price Display Line
  #--------------------------------------------------------------------------
  def price_y
    contents_height / 2 + line_height / 2
  end
  #--------------------------------------------------------------------------
  # * Get Cursor Width
  #--------------------------------------------------------------------------
  def cursor_width
    figures * 10 + 12
  end
  #--------------------------------------------------------------------------
  # * Get X Coordinate of Cursor
  #--------------------------------------------------------------------------
  def cursor_x
    contents_width - cursor_width - 4
  end
  #--------------------------------------------------------------------------
  # * Get Maximum Number of Digits for Quantity Display
  #--------------------------------------------------------------------------
  def figures
    return 2
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    if active
      last_number = @number
      update_number
      if @number != last_number
        Sound.play_cursor
        refresh
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Update Quantity
  #--------------------------------------------------------------------------
  def update_number
    change_number(1)   if Input.repeat?(:RIGHT)
    change_number(-1)  if Input.repeat?(:LEFT)
    change_number(10)  if Input.repeat?(:UP)
    change_number(-10) if Input.repeat?(:DOWN)
  end
  #--------------------------------------------------------------------------
  # * Change Quantity
  #--------------------------------------------------------------------------
  def change_number(amount)
    @number = [[@number + amount, @max].min, 1].max
  end
  #--------------------------------------------------------------------------
  # * Update Cursor
  #--------------------------------------------------------------------------
  def update_cursor
    cursor_rect.set(cursor_x, item_y, cursor_width, line_height)
  end
end

#==============================================================================
# ** Window_BargainShopNumber
#==============================================================================

class Window_BargainNumber < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height)
    super(x, y, width, height)
    @number = 0
    @digits_max = 1
    @index = 0
    @currency_unit = Vocab::currency_unit
  end
  #--------------------------------------------------------------------------
  # * Start Input Processing
  #--------------------------------------------------------------------------
  def start
    @digits_max = R2_Bargain_shop::DIGITS
    @number = [[@number, 0].max, 10 ** @digits_max - 1].min
    @index = 0
    create_contents
    refresh
    open
    activate
  end
  #--------------------------------------------------------------------------
  # * Set Item, Max Quantity, Price, and Currency Unit
  #--------------------------------------------------------------------------
  def set(price, num)
    @price = price
    @num = num
    refresh
  end
  #--------------------------------------------------------------------------
  # * Draw Total Price
  #--------------------------------------------------------------------------
  def draw_total_price
    width = contents_width - 8
    text = R2_Bargain_shop::PRICE_TEXT
    draw_text(0,0,width,24, text)
    draw_currency_value(@price * @num, @currency_unit, 4, 0, width)
  end
  #--------------------------------------------------------------------------
  # * Message
  #--------------------------------------------------------------------------
  def message(type)
    width = contents_width - 8
    mood = $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]]
    case type
    when :pass
      change_color(normal_color)
      text = R2_Bargain_shop::GOOD_DEAL
      draw_text(0,50,width,24, text)
      draw_shopkeep(mood, 10)
    when :more
      change_color(tp_cost_color)
      text = R2_Bargain_shop::BETTER_OFFER
      draw_text(0,80,width,24, text)
      draw_shopkeep(mood, 5)
    when :gold
      change_color(system_color)
      text = R2_Bargain_shop::NO_MONEY
      draw_text(0,80,width,24, text)
      draw_shopkeep(mood, 0)
    when :fail
      change_color(crisis_color)
      text = R2_Bargain_shop::BAD_DEAL
      draw_text(0,80,width,24, text)
      draw_shopkeep(mood, -10)
    end
  end
  #--------------------------------------------------------------------------
  # new method: draw_shopkeep
  #--------------------------------------------------------------------------
  def draw_shopkeep(mood, adjust=0)
    name = R2_Bargain_shop::SHOPKEEP_IMAGE
    if adjust > 5
      index = 3
    elsif adjust > 0
      index = 2
    elsif adjust < 0
      index = 1
    else
      index = 0
    end
    draw_face(name, index, 40, 120)
  end
  #--------------------------------------------------------------------------
  # * Move Cursor Right
  #     wrap : Wraparound allowed
  #--------------------------------------------------------------------------
  def cursor_right(wrap)
    if @index < @digits_max - 1
      @index = @index + 1
    else
      @index = 0
    end
  end
  #--------------------------------------------------------------------------
  # * Move Cursor Left
  #     wrap : Wraparound allowed
  #--------------------------------------------------------------------------
  def cursor_left(wrap)
    if @index > 0
      @index = @index - 1
    else
      @index = @digits_max - 1
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    process_digit_change
    process_handling
    update_cursor
  end
  #--------------------------------------------------------------------------
  # * Cursor Movement Processing
  #--------------------------------------------------------------------------
  def process_cursor_move
    return unless active
    last_index = @index
    cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
    cursor_left (Input.trigger?(:LEFT))  if Input.repeat?(:LEFT)
    Sound.play_cursor if @index != last_index
  end
  #--------------------------------------------------------------------------
  # * Change Processing for Digits
  #--------------------------------------------------------------------------
  def process_digit_change
    return unless active
    if Input.repeat?(:UP) || Input.repeat?(:DOWN)
      Sound.play_cursor
      place = 10 ** (@digits_max - 1 - @index)
      n = @number / place % 10
      @number -= n * place
      n = (n + 1) % 10 if Input.repeat?(:UP)
      n = (n + 9) % 10 if Input.repeat?(:DOWN)
      @number += n * place
      refresh
    end
  end
  #--------------------------------------------------------------------------
  # * Handling Processing for OK and Cancel
  #--------------------------------------------------------------------------
  def process_handling
    return unless active
    set_number
    return process_ok     if Input.trigger?(:C)
    return process_cancel if Input.trigger?(:B)
  end
  #--------------------------------------------------------------------------
  # * Saving the final number
  #--------------------------------------------------------------------------
  def set_number
    @final_price = @number
  end
  #--------------------------------------------------------------------------
  # * returning final number
  #--------------------------------------------------------------------------
  def get_number
    @final_price
  end
  #--------------------------------------------------------------------------
  # * Get Rectangle for Displaying Item
  #--------------------------------------------------------------------------
  def item_rect(index)
    Rect.new(index * 15, 0, 15, line_height)
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    change_color(normal_color)
    s = sprintf("%0*d", @digits_max, @number)
    text = R2_Bargain_shop::OFFER
    draw_text(5, 48, 50, 24,text)
    @digits_max.times do |i|
      rect = item_rect(i)
      rect.x += 80
      rect.y += 48
      draw_text(rect, s[i,1], 1)
      change_color(system_color) if i == @digits_max - 1
      draw_text(rect.x+24, rect.y, rect.width, rect.height,@currency_unit) if i == @digits_max - 1
    end
    draw_total_price
    mood = $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]]
    draw_shopkeep(mood)
  end
  #--------------------------------------------------------------------------
  # * clear
  #--------------------------------------------------------------------------
  def clear
    @digits_max = 0
    @index = -1
    contents.clear
  end
  #--------------------------------------------------------------------------
  # * Update Cursor
  #--------------------------------------------------------------------------
  def update_cursor
    cursor_rect.set(item_rect(@index))
    cursor_rect.x += 80
    cursor_rect.y += 48
    cursor_rect.empty if @index == -1
  end
end

#==============================================================================
# ** Scene_Bargain_Shop
#==============================================================================

class Scene_Bargain_Shop < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Prepare
  #--------------------------------------------------------------------------
  def prepare(goods)
    @goods = goods
    @purchase_only = true
  end
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
    super
    create_help_window
    create_title_window
    create_gold_window
    create_command_window
    create_dummy_window
    create_number_window
    create_buy_window
    create_bargain_window
  end
  #--------------------------------------------------------------------------
  # * Create Help Window
  #--------------------------------------------------------------------------
  def create_help_window
    @help_window = Window_BargainHelp.new
    @help_window.viewport = @viewport
  end
  #--------------------------------------------------------------------------
  # * Create Title Window
  #--------------------------------------------------------------------------
  def create_title_window
    @title_window = Window_BargainTitle.new
    @title_window.viewport = @viewport
  end
  #--------------------------------------------------------------------------
  # * Create Gold Window
  #--------------------------------------------------------------------------
  def create_gold_window
    @gold_window = Window_BargainGold.new
    @gold_window.viewport = @viewport
    @gold_window.x = Graphics.width - @gold_window.width
    @gold_window.y = @title_window.height
  end
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  def create_command_window
    @command_window = Window_BargainShopCommand.new(@gold_window.x)
    @command_window.viewport = @viewport
    @command_window.y = @title_window.height
    @command_window.set_handler(:buy,    method(:command_buy))
    @command_window.set_handler(:cancel, method(:return_scene))
  end
  #--------------------------------------------------------------------------
  # * Create Dummy Window
  #--------------------------------------------------------------------------
  def create_dummy_window
    wy = @command_window.y + @command_window.height
    wh = Graphics.height - wy - @help_window.height
    @dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
    @dummy_window.viewport = @viewport
  end
  #--------------------------------------------------------------------------
  # * Create Quantity Input Window
  #--------------------------------------------------------------------------
  def create_number_window
    wy = @dummy_window.y
    wh = @dummy_window.height
    @number_window = Window_BargainShopNumber.new(0, wy, wh)
    @number_window.viewport = @viewport
    @number_window.z = 200
    @number_window.hide
    @number_window.set_handler(:ok,     method(:on_number_ok))
    @number_window.set_handler(:cancel, method(:on_number_cancel))
  end
  #--------------------------------------------------------------------------
  # * Create Purchase Window
  #--------------------------------------------------------------------------
  def create_buy_window
    wy = @dummy_window.y
    wh = @dummy_window.height
    @buy_window = Window_ShopBuy.new(0, wy, wh, @goods)
    @buy_window.viewport = @viewport
    @buy_window.help_window = @help_window
    @buy_window.status_window = @status_window
    @buy_window.hide
    @buy_window.set_handler(:ok,     method(:on_buy_ok))
    @buy_window.set_handler(:cancel, method(:on_buy_cancel))
  end
  #--------------------------------------------------------------------------
  # * Create Status Window
  #--------------------------------------------------------------------------
  def create_bargain_window
    wx = @buy_window.width
    wy = @buy_window.y
    ww = Graphics.width - wx
    wh = @buy_window.height
    @bargain_window = Window_BargainNumber.new(wx, wy, ww, wh)
    @bargain_window.viewport = @viewport
    @bargain_window.hide
    @bargain_window.set_handler(:ok,     method(:on_bargain_ok))
    @bargain_window.set_handler(:cancel, method(:on_bargain_cancel))
  end
  #--------------------------------------------------------------------------
  # * Activate Purchase Window
  #--------------------------------------------------------------------------
  def activate_buy_window
    @buy_window.money = money
    @buy_window.show.activate
    @bargain_window.show
  end
  #--------------------------------------------------------------------------
  # * [Buy] Command
  #--------------------------------------------------------------------------
  def command_buy
    @dummy_window.hide
    activate_buy_window
  end
  #--------------------------------------------------------------------------
  # * Buy [OK]
  #--------------------------------------------------------------------------
  def on_buy_ok
    @item = @buy_window.item
    @number_window.set(@item, max_buy, currency_unit)
    @number_window.show.activate
  end
  #--------------------------------------------------------------------------
  # * Buy [Cancel]
  #--------------------------------------------------------------------------
  def on_buy_cancel
    @command_window.activate
    @dummy_window.show
    @buy_window.hide
    @bargain_window.hide
    @help_window.clear
  end
  #--------------------------------------------------------------------------
  # * Quantity Input [OK]
  #--------------------------------------------------------------------------
  def on_number_ok
    @bargain_window.set(buying_price, @number_window.number)
    @bargain_window.activate
    @bargain_window.start
    @number_window.hide
  end
  #--------------------------------------------------------------------------
  # * Quantity Input [Cancel]
  #--------------------------------------------------------------------------
  def on_number_cancel
    Sound.play_cancel
    @number_window.hide
    activate_buy_window
  end
  #--------------------------------------------------------------------------
  # * Price Input [OK]
  #--------------------------------------------------------------------------
  def on_bargain_ok
    do_buy(@bargain_window.get_number)
  end
  #--------------------------------------------------------------------------
  # * Quantity Input [Cancel]
  #--------------------------------------------------------------------------
  def on_bargain_cancel
    @number_window.set(@item, max_buy, currency_unit)
    @number_window.show.activate
    @bargain_window.clear
  end
  #--------------------------------------------------------------------------
  # * Execute Purchase
  #--------------------------------------------------------------------------
  def do_buy(number)
    # buy mechanic
    mood = $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]]
    if mood == nil
      mood = 50
      $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] = 50
    end
    # do mood calculation
    full = buying_price * @number_window.number
    min = (full / 2).to_i
    variance = 0
    if @item.bargain != 0
      variance = @item.bargain * @number_window.number
    else
      variance = (@item.price * 0.05).to_i * @number_window.number
    end
    adjust = (variance * mood  / 100).to_i
    low = full - adjust - variance
    mid = low + adjust
    # check for price accepted
    bonus = 0
    if number >= full
      bonus = 3
    elsif number >= mid
      bonus = 2
    elsif number >= low
      bonus = 1
    else
      bonus = -1
    end
    odds = 0
    success = false
    cost_compare = (full * 0.95).to_i
    if bonus > 0
      if $game_party.gold >= number
        if number >= cost_compare
          success = true
        elsif mood >= 95
          success = true
        else
          odds = rand(100)
        end
        if odds > mood
          @bargain_window.message(:more)
          @bargain_window.activate
        else
          success = true
        end
        if success
          @bargain_window.clear
          @bargain_window.message(:pass)
          Sound.play_shop
          $game_party.lose_gold(number)
          $game_party.gain_item(@item, @number_window.number)
          @bargain_window.deactivate
          $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] += bonus * R2_Bargain_shop::PASS
          $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] = 100 if 
          $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] > 100
          activate_buy_window
          @gold_window.refresh
        else
          $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] += bonus * R2_Bargain_shop::MORE
          $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] = 0 if 
          $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] < 0
        end
      else
      # not enough gold
        @bargain_window.activate
        @bargain_window.message(:gold)
        return
      end
    else
      # fail and return to amount
      @bargain_window.activate
      @bargain_window.message(:fail)
      $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] += bonus * R2_Bargain_shop::FAIL
      $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] = 0 if 
      $game_party.shop_mood[$game_variables[R2_Bargain_shop::SHOP_VARIABLE]] < 0
    end
  end
  #--------------------------------------------------------------------------
  # * Exit Quantity Input
  #--------------------------------------------------------------------------
  def end_bargain_input
    @bargain_window.clear
    activate_buy_window
  end
  #--------------------------------------------------------------------------
  # * Get Maximum Quantity Buyable
  #--------------------------------------------------------------------------
  def max_buy
    max = $game_party.max_item_number(@item) - $game_party.item_number(@item)
  end
  #--------------------------------------------------------------------------
  # * Get Party Gold
  #--------------------------------------------------------------------------
  def money
    @gold_window.value
  end
  #--------------------------------------------------------------------------
  # Get Currency Unit
  #--------------------------------------------------------------------------
  def currency_unit
    @gold_window.currency_unit
  end
  #--------------------------------------------------------------------------
  # * Get Purchase Price
  #--------------------------------------------------------------------------
  def buying_price
    @buy_window.price(@item)
  end
  #--------------------------------------------------------------------------
  # * Return Scene
  #--------------------------------------------------------------------------
  alias :r2_return_bargain_shop_custom  :return_scene
  def return_scene
    $game_switches[R2_Bargain_shop::BARGAIN_SWITCH] = false
    r2_return_bargain_shop_custom
  end
end
Hello Roninator! First of all, woah 😢 I didn't expect someone to take the trouble to do this after so long. Thank you for your kindness!

Gave it a quick test it and it works smoothly, just a little question: how can I make this not happen? Maybe putting a limit on the difference with the asking price? (the asking price is 250 but even offering 250 asks me to offer more. I don't remember if I considered that in my calculations, whoops).

Captura de pantalla (882).png


Second, not necessary although highly wanted since my original request included using the dialogue box on the shopkeeper. That depending on the answers their face changes. Maybe like in the (very crusty) mockup below?

Captura de pantalla (882) - copia.png


That would be all. Again, thank you so much for your help!
the asking price is 250 but even offering 250 asks me to offer more
that should not have happened. but looks like I forgot to put an = sign in there
Maybe like in the (very crusty) mockup below?
So you want a faceset as well. It might be better to put it below the offer number.
I can also lower the counter number size to 6 digits.
Let me try that.

*update
script above updated. Will you be using different shopkeeps for bargaining?
As of right now it has the one filename configured in the script.
Please review the changes.
The issue about the price seems to be fixed. As for the number of shopkeeps, I'll be using only one. Thanks for adding the faceset!

Captura de pantalla (883).png
Had to update again. found a critical flaw. I didn't have the note tags working for weapons and armors.
Also moved the text into the module so you can change it easier.
Alright! Gave it more testing, but for some reason the shopkeeper doesn't say the BETTER_OFFER anymore.

I also was wondering how to make the text not shrink and instead make a new line? Thanks in advance.

Captura de pantalla (884).png
for some reason the shopkeeper doesn't say the BETTER_OFFER anymore.
It's completely random. you can select a price that is the minimum price that will be accepted and it may say it, three times, but will eventually agree to the purchase as the mood is actually increased with each offer that is at the minimum.

If you want to change the shopkeeper from gaining mood for this and for the text question you need to go into the code.
Change the values for the draw_shopkeep

As you are using long phrases, you have two options.
Option 1: make new draw_text commands. - this preserves the colour of the text.
Option 2: change them all to draw_text_ex commands. - then you just need a \n in the string to make a new line.

Both of these option will require you to adjust the y position of all the lines and maybe the face to make it all fit.

def message)type) on line 531 is the start.

Choose which way you want to go.
Option 1 is to make new lines and add a new draw_text while increasing the y value.
draw_text(0,80,width,24, text1)
draw_text(0,104,width,24, text2)

Option two is to convert to draw_text_ex
draw_text_ex(0,80, text) - this does not require the width or height. then just add \n to the sting text in the module.

both will likely require changing the position of the face or text lines.
If you use 640x480 then you can just move the face down a bit.

The face draw is on line 572 of draw_shopkeep, the y value is currently 120.

If you move the text up a bit higher then lower the y value of 80 (maybe 72), for the draw text lines and add the new draw_text or draw_text_ex.

Then down in def refresh is the price drawn. line 660
change the rect.y part and hte draw_text above that (48)

Original thread: https://forums.rpgmakerweb.com/threads/bargain-negotiation-mechanic-on-prices.168062/