RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Random Shop Generator

0 Members and 1 Guest are viewing this topic.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
Random Shop Generator
Version: 1.0
Author: cozziekuns
Date: January 22, 2012

Version History


  • <Version 1.0> 2012.01.22 - Original Release

Planned Future Versions

  • None. Please suggest some features.

Description


Made for Roguelike-type games, this script enables you to easily create a random shop.

Features

  • Ability to cache certain shops.
  • Easy to create random shops.
  • Almost no configuration.

Instructions

To create a random shop, insert a comment where the random shop is needed containing:
 
\random_shop[[item_type, item_id, special_price?, price],...]
 
item_type:
  0 => Item,
  1 => Weapon,
  2 => Armour

item_id: This can be found in the Database, at the left of the name value. For example, the item_id of Potion is 001.
 
special_price?:
  0 => No special price,
  1 => Special price (price override)
 
price: Price overriding the regular price of the item.

CACHE_SHOP: If false, the events' shop will randomize each time the map is loaded. If true, throughout the game, the events' shop will be the same in the same save file.

Example

Code: [Select]
@>Display Text: -, -, Normal, Down
:             : Hello. How may I help you?
@>Comment: \random_shop[[0, 1, 0, 0], [0, 2, 1, 100]]
@>Display Text: -, -, Normal, Down
:             : Thank you for your patronage!

Would result in an event that would first greet the player, create a shop that could contain either a regular-priced Potion or a High Potion priced at 100 gold (or the shop could contain both), and then thank the player. The shop will never contain no items, and the minimum amount of items is half of the size of the shop items (e.g. if you set the random shop to have a pick of 6 items, it could have anywhere from 3 to 6 items).

Script


Code: [Select]
#===============================================================================
# [VXA] Random Shop Generator
#-------------------------------------------------------------------------------
# Version: 1.0
# Author: cozziekuns (rmrk)
# Last Date Updated: 1/22/2012 (MM/DD/YYYY)
#===============================================================================
# Description:
#-------------------------------------------------------------------------------
# Made for Roguelike-type games, this script enables you to easily create a
# random shop.
#===============================================================================
# Updates
# ------------------------------------------------------------------------------
# o 1/22/2012 - Started Script
#===============================================================================
# Instructions
#-------------------------------------------------------------------------------
# To create a random shop, insert a comment where the random shop is needed
# containing:
#
# \random_shop[[item_type, item_id, special_price?, price],...]
#
# item_type:
#   0 => Item,
#   1 => Weapon,
#   2 => Armour
#
# item_id: This can be found in the Database, at the left of the name value. For
#          example, the item_id of Potion is 001.
#
# special_price?:
#   0 => No special price,
#   1 => Special price (price override)
#
# price: Price overriding the regular price of the item.
#
# CACHE_SHOP: If false, the events' shop will randomize each time the map is
#             loaded. If true, throughout the game, the events' shop will be
#             the same in the same save file.
#===============================================================================
# Example
#-------------------------------------------------------------------------------
# @>Display Text: -, -, Normal, Down
# :             : Hello. How may I help you?
# @>Comment: \random_shop[[0, 1, 0, 0], [0, 2, 1, 100]]
# @>Display Text: -, -, Normal, Down
# :             : Thank you for your patronage?
#
# Would result in an event that would first say "Hello. How may I help you?",
# create a shop that could contain either a regular-priced Potion or a
# High Potion priced at 100 gold, or the shop could contain both. The shop will
# never contain no items, and the minimum amount of items is half of the size of
# the shop items (e.g. if you set the random shop to have a pick of 6 items, it
# could have anywhere from 3 to 6 items).
#===============================================================================

#==============================================================================
# ** Cozziekuns
#==============================================================================

module COZZIEKUNS
 
  module RANDOM_SHOP
   
    CACHE_SHOP = false
   
  end
 
end

include COZZIEKUNS

#==============================================================================
# ** Game_System
#==============================================================================

class Game_System
 
  attr_accessor :events_cache
 
  alias coz_rds_vxa_gs_initialize initialize
  def initialize(*args)
    coz_rds_vxa_gs_initialize(*args)
    @events_cache = {}
  end
 
end


#==============================================================================
# ** Game_Event
#==============================================================================

class Game_Event
 
  alias coz_rds_vxa_ge_setup_page_settings setup_page_settings
  def setup_page_settings(*args)
    coz_rds_vxa_ge_setup_page_settings(*args)
    check_for_random_shop
  end
 
  def check_for_random_shop
    @page.list.each { |i|
      next unless [108, 408].include?(i.code)
      comment = i.parameters.to_s
      index = @page.list.index(i)
      if comment[/\\random_shop\[[(\[\d+,\s+\d+,\s+\d+,\s+\d+\])]+\]/i]
        base_comment = comment[/\\random_shop\[[(\[\d+,\s+\d+,\s+\d+,\s+\d+\])]+\]/i]
        string = base_comment[/(\[\d+,\s+\d+\,\s+\d+,\s+\d+],?\s?)+/i]
        base_array = string.split(/,\s+/i)
        string_array = []
        for i in 0...base_array.size / 4
          val = base_array[i * 4][/\d+/]
          string_array.push([val.to_i, base_array[i * 4 + 1].to_i, base_array[i * 4 + 2].to_i, base_array[i * 4 + 3].to_i])
        end
        create_random_shop(string_array, index)
      end
    }
  end
 
  def create_random_shop(array, index)
    key = [@map_id, @event.id]
    if not $game_system.events_cache[key] or not RANDOM_SHOP::CACHE_SHOP
      commands = []
      shop_items = []
      item_shopnum = rand(array.size) + 1
      while item_shopnum > 0
        item_shopnum -= 1
        new_item = array[rand(array.size)]
        shop_items.push(new_item)
        array.delete(new_item)
      end
      for i in 0...shop_items.size
        item = shop_items[i]
        if i == 0
          commands.push(RPG::EventCommand.new(302, 1, item + [false]))
        else
          commands.push(RPG::EventCommand.new(605, 1, item))
        end
      end
      commands.reverse!
      $game_system.events_cache[key] = commands
    end
    @page.list.delete_at(index)
    $game_system.events_cache[key].each { |i| @page.list.insert(index, i) }
    @list = @page.list
  end 

end

Credit


  • cozziekuns

Support


Please post in this topic at RMRK to report any errors or to ask any questions regarding this script.

Known Compatibility Issues

None, currently.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
This is a neat script! It looks very nicely done. I will take a closer look soon.

*
Rep: +0/-0Level 64
RMRK Junior
This would fit perfect for a part in my game.
I'm not sure how difficult this would be, but my recommendation for a feature is setting up a secondary currency for the shop.
For example. Most merchants take gold, this merchant is rich so he doesn't need gold and only does trades with banana peels or etc.
I would appreciate this feature very much xP