[XP] Moghunter Item Limit Problem

So I have a big problem with Moghunter Item Limit script, which limits the number of items you could have. The problem occurs when I buy items. It ignores the money I have, allowing me to buy

max number of items. For sample, if I have only 100$ and each potion costs 50$, it allow me to buy 99 potions, even considering that I don't have enough money, the purchase is completed.  

I have also looked in the forum and found a suggestion to put Item Limit above scene_shop, but it didn't worked. It gives me an error message: "undefined method 'update' for class 'scene_shop´". If anyone has solved this problem, it would be of great help, because my project is stuck here due to this problem. Also I've posted bellow the Moghunter Item Limit:

Code:
#_______________________________________________________________________________# MOG Item Limit V1.7#_______________________________________________________________________________# By Moghunter# [URL="http://www.atelier-rgss.com#_______________________________________________________________________________%23"]http://www.atelier-rgss.com#_______________________________________________________________________________#[/URL] Portuguese:# Permite definir o limite maximo para cada item, armas# ou armaduras.## English:# Set the maximum limit for each item, weapons# Or armor.#_______________________________________________________________________________module MOG#-------------------------------------------------------------------------------# Definição do limite padrão.# Items Limit Definition#-------------------------------------------------------------------------------DEFAULT_LIMIT = 99#-------------------------------------------------------------------------------# A => B## A = ID do item, armadura ou arma (ID of the item, weapon or armor).# B = Quantidade de itens maximo (amount of items).##-------------------------------------------------------------------------------#Definição do limite maximo de Itens.#Definition of Item maximum limit.#-------------------------------------------------------------------------------ITEM_LIMIT = {1=>20, #Potion}#-------------------------------------------------------------------------------#Definição do limite maximo de armas.#Definition of weapons maximum limit.#-------------------------------------------------------------------------------WEAPON_LIMIT = {}#-------------------------------------------------------------------------------#Definição do limite maximo de armaduras.#Definition of armors maximum limit.#-------------------------------------------------------------------------------ARMOR_LIMIT = {}#-------------------------------------------------------------------------------#Definição do limite maximo de dinheiro#Definition of maximum money limit.#-------------------------------------------------------------------------------GOLD_LIMIT = 1000000000#-------------------------------------------------------------------------------end$mogscript = {} if $mogscript == nil$mogscript["Item_Limit"] = true############### Game_Party ###############class Game_Partyalias mog45_gain_item gain_itemdef gain_item(item_id, n)if item_id > 0item_limit = MOG::ITEM_LIMIT[item_id]if item_limit != nil@items[item_id] = [[item_number(item_id) + n, 0].max, item_limit].minelse@items[item_id] = [[item_number(item_id) + n, 0].max, MOG::DEFAULT_LIMIT].minendendreturnmog45_gain_item(item_id, n)endalias mog45_gain_weapon gain_weapondef gain_weapon(weapon_id, n)if weapon_id > 0weapon_limit = MOG::WEAPON_LIMIT[weapon_id]if weapon_limit !=nil@weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, weapon_limit].minelse@weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, MOG::DEFAULT_LIMIT].minendendreturnmog45_gain_weapon(weapon_id, n)endalias mog45_gain_armor gain_armordef gain_armor(armor_id, n)if armor_id > 0armor_limit = MOG::ARMOR_LIMIT[armor_id]if armor_limit != nil@armors[armor_id] = [[armor_number(armor_id) + n, 0].max, armor_limit].minelse@armors[armor_id] = [[armor_number(armor_id) + n, 0].max, MOG::DEFAULT_LIMIT].minendendreturnmog45_gain_armorenddef gain_gold(n)@gold = [[@gold + n, 0].max, MOG::GOLD_LIMIT].minendend############### Scene_Shop ###############class Scene_Shopalias mog45_update updatedef updateif @sell_window.active == true$sell = trueelse$sell = falseendmog45_updateendalias mog45_update_buy update_buydef update_buyif Input.trigger?(Input::C)@item = @buy_window.itemcase @itemwhen RPG::Itemnumber = $game_party.item_number(@item.id)item_limit = MOG::ITEM_LIMIT[@item.id]if item_limit != nilif number >= item_limit$game_system.se_play($data_system.buzzer_se)returnendelseif number == MOG::DEFAULT_LIMIT$game_system.se_play($data_system.buzzer_se)returnendendwhen RPG::Weaponnumber = $game_party.weapon_number(@item.id)weapon_limit = MOG::WEAPON_LIMIT[@item.id]if weapon_limit != nilif number >= weapon_limit$game_system.se_play($data_system.buzzer_se)returnendelseif number == MOG::DEFAULT_LIMIT$game_system.se_play($data_system.buzzer_se)returnendendwhen RPG::Armornumber = $game_party.armor_number(@item.id)armor_limit = MOG::ARMOR_LIMIT[@item.id]if armor_limit != nilif number >= armor_limit$game_system.se_play($data_system.buzzer_se)returnendelseif number == MOG::DEFAULT_LIMIT$game_system.se_play($data_system.buzzer_se)returnendendendendmog45_update_buyendend###################### Window_ShopNumber ######################class Window_ShopNumber < Window_Basealias mog45_set setdef set(item, max, price)@item = itemcase @itemwhen RPG::Itemnumber = $game_party.item_number(@item.id)item_limit = MOG::ITEM_LIMIT[@item.id]if item_limit!= nilif $sell == truevalor = item_limit - number@max = item_limit - valorelse@max = item_limit - numberendelseif $sell == truevalor = MOG::DEFAULT_LIMIT - number@max = MOG::DEFAULT_LIMIT - valorelse@max = MOG::DEFAULT_LIMIT - numberendendwhen RPG::Weaponnumber = $game_party.weapon_number(@item.id)weapon_limit = MOG::WEAPON_LIMIT[@item.id]if weapon_limit!= nilif $sell == truevalor = weapon_limit - number@max = weapon_limit - valorelse@max = weapon_limit - numberendelseif $sell == truevalor = MOG::DEFAULT_LIMIT - number@max = MOG::DEFAULT_LIMIT - valorelse@max = MOG::DEFAULT_LIMIT - numberendendwhen RPG::Armornumber = $game_party.armor_number(@item.id)armor_limit = MOG::ARMOR_LIMIT[@item.id]if armor_limit!= nilif $sell == truevalor = armor_limit - number@max = armor_limit - valorelse@max = armor_limit - numberendelseif $sell == truevalor = MOG::DEFAULT_LIMIT - number@max = MOG::DEFAULT_LIMIT - valorelse@max = MOG::DEFAULT_LIMIT - numberendendend@price = price@number = 1refreshreturnmog45_set set(item, max, price)endend################ Window_Item ################class Window_Item < Window_Selectabledef draw_item(index)item = @data[index]case itemwhen RPG::Itemnumber = $game_party.item_number(item.id)item_number = MOG::ITEM_LIMIT[item.id]when RPG::Weaponnumber = $game_party.weapon_number(item.id)item_number = MOG::WEAPON_LIMIT[item.id]when RPG::Armornumber = $game_party.armor_number(item.id)item_number = MOG::ARMOR_LIMIT[item.id]endif item.is_a?(RPG::Item) and$game_party.item_can_use?(item.id)self.contents.font.color = normal_colorelseself.contents.font.color = disabled_colorendx = 4 + index % 2 * (288 + 32)y = index / 2 * 32rect = Rect.new(x, y, self.width / @column_max - 32, 32)self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))bitmap = RPG::Cache.icon(item.icon_name)opacity = self.contents.font.color == normal_color ? 255 : 128self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)if item_number != nilself.contents.draw_text(x + 220, y, 60, 32, number.to_s + " / " + item_number.to_s, 2)elsemax_limit = MOG::DEFAULT_LIMITself.contents.draw_text(x + 220, y, 60, 32, number.to_s + " / " + max_limit.to_s, 2)endendend
Couple of things. First, you should use spoiler tags when posting large amounts of code. Just put "[ spoiler ]" before it and "[ /spoiler ]" after it without the spaces or quotes. Second, the mods usually prefer that you link to the script you're using rather than posting the code directly. Now, on to your problem.
 
There actually is a bug in MOG's code that lets you do what you're describing. I've fixed it. Just paste the below code into your script editor below MOG's script.

Spoiler
Code:
# MOG Item Limit Bugfix# code by MobiusXVI# This fix prevents you from buying more than you are ableclass Window_ShopNumber < Window_Base#--------------------------------------------------------------------------# set#--------------------------------------------------------------------------       alias mog45_set set  def set(item, max, price)    @item = item    case @item    when RPG::Item      number = $game_party.item_number(@item.id)      item_limit = MOG::ITEM_LIMIT[@item.id]      if item_limit!= nil        if $sell == true          valor = item_limit - number          @max = item_limit - valor        else          @max = item_limit - number        end      else        if $sell == true          valor = MOG::DEFAULT_LIMIT - number            @max = MOG::DEFAULT_LIMIT - valor        else          @max = MOG::DEFAULT_LIMIT - number        end      end    when RPG::Weapon    number = $game_party.weapon_number(@item.id)    weapon_limit = MOG::WEAPON_LIMIT[@item.id]    if weapon_limit!= nil      if $sell == true        valor = weapon_limit - number         @max = weapon_limit - valor      else        @max = weapon_limit - number      end    else      if $sell == true          valor = MOG::DEFAULT_LIMIT - number            @max = MOG::DEFAULT_LIMIT - valor      else        @max = MOG::DEFAULT_LIMIT - number      end    end        when RPG::Armor    number = $game_party.armor_number(@item.id)    armor_limit = MOG::ARMOR_LIMIT[@item.id]      if armor_limit!= nil        if $sell == true          valor = armor_limit - number           @max = armor_limit - valor        else          @max = armor_limit - number        end      else        if $sell == true          valor = MOG::DEFAULT_LIMIT - number              @max = MOG::DEFAULT_LIMIT - valor          else          @max = MOG::DEFAULT_LIMIT - number        end      end     end    # Bugfix line - Take smaller of item limit/max buyable    @max = [@max, max].min    @price = price    @number = 1    refresh  end  end 
Thanks for looking in to my problem, but it didn't worked. I have placed it bellow Mog Item Limit, and it didn't worked at all, still I could buy the max limit of items without having the money for it.

Edit: Ok it worked, sorry for my foolishness, I didn't pay attention on where I was placing the Bug Fix, I usually place a BACKUP field bellow main with all scripts I would tap, to prevent me losing importation things. 

My thanks good man for solving my problem, everything is ok now. Also I would take note that when I made the post, I could not find a template showing me how to make a request in the forum, or I didn't look for it in the right place, all I could find was the standard ['code]['/code]. I'll take note for future, thank you again.

Original thread: https://forums.rpgmakerweb.com/threads/xp-moghunter-item-limit-problem.45201/