Shop Buy Window Categories

Discussion in 'RGSS3 Script Requests' started by dubiousdeeds, May 31, 2019.

  1. dubiousdeeds

    dubiousdeeds Villager Member

    Messages:
    16
    Likes Received:
    0
    First Language:
    English
    It's driving me crazy that when I open a shop and go to "Sell" that all the categories of items open up and I can cycle through them, but this does not happen for "Buy".

    I have many merchants in my game that sell a variety of items and I would love to have them separated out in the categories, like "Weapon", "Armor", "Item".

    I saw someone seems to have made a plugin for MV, https://forums.rpgmakerweb.com/inde...on-categories-to-buy-items.86387/#post-841521 , that I believe does what I'm hoping to achieve. Alas I am in VX Ace and need a ruby script.

    I highly appreciate anyone who can help me out with this conundrum.
     
    #1
  2. Roninator2

    Roninator2 Gamer Veteran

    Messages:
    1,709
    Likes Received:
    376
    Location:
    Canada
    First Language:
    English
    Primarily Uses:
    RMVXA
     
    #2
    Ebanyle and Wavelength like this.
  3. dubiousdeeds

    dubiousdeeds Villager Member

    Messages:
    16
    Likes Received:
    0
    First Language:
    English
    This is fantastic thank you. I am using Yanfly's Shop Options so I'm going to need to tailor it to fit but this gives me a starting point. Actually Roninator2 I see you've had some experience with Yanfly's scripts. I was wondering if I could trouble you a bit further. In Yanfly's Shop script the Category Window becomes the Command window when sell is selected. Do you know how to get this Buy Category window into the same position? Nevermind with a few adjustments I got it to work with Yanlfy's Shop. Oh the joys of my scattered brain, Thanks again!
     
    Last edited: May 31, 2019
    #3
  4. bgillisp

    bgillisp Global Moderators Global Mod

    Messages:
    12,105
    Likes Received:
    12,290
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMVXA

    I've moved this thread to RGSSx Script Requests. Please be sure to post your threads in the correct forum next time. Thank you.

     
    #4
  5. Roninator2

    Roninator2 Gamer Veteran

    Messages:
    1,709
    Likes Received:
    376
    Location:
    Canada
    First Language:
    English
    Primarily Uses:
    RMVXA
    Interesting how it was so easy for you. I'm still working on it.

    Finished
    Code:
    # modifies the shop option for yanfly to include categories for buying.
    
    class Window_ShopBuy < Window_Selectable
     
      def category=(category)
        return if @category == category
        @category = category
        refresh
        self.oy = 0
      end
    
      def make_item_list
        @data = []
        @price = {}
        categories = { :item => 0,:weapon => 1 ,:armor => 2, :key_item => 0 }
        @shop_goods.each do |goods|
          next unless goods[0] == categories[@category]
          case goods[0]
          when 0;  item = $data_items[goods[1]]
          when 1;  item = $data_weapons[goods[1]]
          when 2;  item = $data_armors[goods[1]]
          end
          if item
            next if (@category == :item && item.key_item?)
            next if (@category == :key_item && !item.key_item?)
            @data.push(item)
            @price[item] = goods[2] == 0 ? item.price : goods[3]
          end
        end
      end
    end
    
    class Scene_Shop < Scene_MenuBase
    
      alias scene_shop_start_r2 start
      def start
        scene_shop_start_r2
        create_buy_category_window
      end
     
      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
    
      def command_buy
        @dummy_window.hide
        @buy_category_window.x = 0
        @buy_category_window.select(0)
        @command_window.x = Graphics.width
        @buy_window.x = 0
        @sell_window.x = Graphics.width
        @buy_window.unselect
        @buy_window.refresh
        @data_window.item_window = @buy_window
        @buy_window.show
        @status_window.show
        @buy_category_window.show.activate
        @buy_category_window.item_window = @buy_window
      end
     
      def activate_buy_window
        @buy_window.show
        @buy_window.select(0)
        @buy_window.money = money
        @buy_window.show.activate
        @status_window.show
      end
     
      def on_buy_cancel
        @dummy_window.show
        @status_window.item = nil
        @buy_window.unselect
        @help_window.clear
        @buy_category_window.activate
      end
     
      def create_buy_category_window
        @buy_category_window = Window_ShopCategory.new
        @buy_category_window.viewport = @viewport
        @buy_category_window.help_window = @help_window
        @buy_category_window.y = @category_window.y
        @buy_category_window.hide.deactivate
        @buy_category_window.set_handler(:ok,     method(:on_buy_category_ok))
        @buy_category_window.set_handler(:cancel, method(:on_buy_category_cancel))
      end
    
      def on_buy_category_ok
        activate_buy_window
        @buy_window.select(0)
      end
     
      def on_buy_category_cancel
        @dummy_window.show
        @buy_category_window.unselect
        @buy_category_window.hide
        @buy_window.deactivate
        on_category_cancel
        @status_window.item = nil
        @help_window.clear
      end
    
    end
     
    Last edited: Jun 3, 2019
    #5
  6. dubiousdeeds

    dubiousdeeds Villager Member

    Messages:
    16
    Likes Received:
    0
    First Language:
    English
    Oh it wasn't easy (I was about to give up at one point). I can't really make scripts on my own but after some trial and error and figuring out what each of the different parts are controlling I figured out how to adjust it to make it work. You definitely gave me all the pieces I needed, thanks.

    Plus I had to tweak Yanfly's script because his has a snippet that remembers the index of the item in the buy window.

    @last_buy_index = @buy_window.index

    That was problematic if you went from a lower position on a category page with multiple items, and then backed out and tried to go back into buy and then a category with less items. It would put the selection box in empty spaces of some times just missing from the page entirely. I had to delete that also to get this working.
     
    Last edited: Jun 1, 2019
    #6
  7. Roninator2

    Roninator2 Gamer Veteran

    Messages:
    1,709
    Likes Received:
    376
    Location:
    Canada
    First Language:
    English
    Primarily Uses:
    RMVXA
    Just tested that now. The selection cursor shows on the item that you had last selected, but with my edit, it will select item[0] every time when you select the category.
    Care to share your edit?
     
    #7
  8. dubiousdeeds

    dubiousdeeds Villager Member

    Messages:
    16
    Likes Received:
    0
    First Language:
    English
    So I went back through to find exactly what I changed, because like I said trial and error (my coding knowledge is high school level visual basic so very rudimentary). Anyway, I found in Yanfly's Shop Script I made 2 removals

    Around line 1282 in the command_buy section I removed
    @buy_window.select(@last_buy_index)

    Also Around Line 1304 from the on_buy_cancel section I removed
    @last_buy_index = @buy_window.index

    Then here is how I edited yours, along with the note at the top to remind me that it needed to be above the Yanfly Shop Script to function properly (sections disappeared when it was below in the load order)

    I'm sure I put some unnecessary bits in there and did it inefficiently, but I'm a newb.

    So my edits were somewhat knit picky, but they were to make it function like the sell options.

    Like I mentioned previously for example
    I would go to buy armor and there were 5 armors. If I were to move my selection down to the 5th armor and then back out twice which would take me back to the Buy or Sell option window. Then go back into buy and go to the category of weapon (not into it just move the selection over that category) that only had 1 weapon, but the window that lists the weapons would show the selection box unactivated and 5 slots down floating over nothing.

    Also when just selecting Buy and before selecting the category, that selection box was showing unactivated down on the first item.

    I had found that in Yanfly's script when selling and scrolling through the categories that the selection box was never visible on the items, armors, etc. until you chose the category to drop down to the list. So I was changing alot of things and "trial and erroring" your script to get that floating selection box to go away.

    I'm not really sure how the dummy window functions, my guess was it was showing the last created buy window and I was thinking that was why the selection box wasn't disappearing like I wanted it too. I could be totally wrong on that, but that was part of my thought process. Anyway for not knowing exactly what I was doing I was fairly proud of myself for even being able to tweak your code to get what I wanted out of it. So even though my games are just my own personal hobby and will never see the light of day I greatly appreciate your help and the help of others across these forums to get me through the roadblocks I encounter.

    One more question to pose to you. Is it easily achievable (or possible) for the initial window (the one before you select Buy) to show all the things the vendor has for sale (or no items at all, if the previous is not possible)? That's the only thing I miss. Now that the categories are there that initial window just shows the first category instead of everything. I have a feeling that's asking more then is doable from this.
     
    Last edited: Jun 1, 2019
    #8
  9. Roninator2

    Roninator2 Gamer Veteran

    Messages:
    1,709
    Likes Received:
    376
    Location:
    Canada
    First Language:
    English
    Primarily Uses:
    RMVXA
    The first post with the code is not my code. I found it and pasted a link to it. But the forums coding makes links to pastebin show up as a code box as you see it.

    It may be possible to make all the items show up. It was a step that I was at at one point until I got it working like it is now.
    I'll see what I can do.

    Also note that the edit I made goes below yanfly's script and yanfly's script is not edited at all.

    *EDIT..

    Having all items show up seems to be difficult. Having no items show up is easier.
    Turns out all you need to do it comment out the @categories = : item line near the top.

    I updated my code above.
    Selection is fixed.
     
    Last edited: Jun 2, 2019
    #9
  10. dubiousdeeds

    dubiousdeeds Villager Member

    Messages:
    16
    Likes Received:
    0
    First Language:
    English
    That worked great thank you very much!

    I made a little donation on your homepage to say thanks also.
     
    #10
  11. Roninator2

    Roninator2 Gamer Veteran

    Messages:
    1,709
    Likes Received:
    376
    Location:
    Canada
    First Language:
    English
    Primarily Uses:
    RMVXA
    Much appreciated. Completely unexpected. Your the first to make a donation to me.
    Thank you for the support.
     
    #11

Share This Page