Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # +++ SIMPLE RANDOM SHOP +++
- #===============================================================================
- # + Original Script by Fhizban (also known as Malagar)
- #
- # + Version 1.0
- # + Updated August 2015
- # + For RPGMaker VX Ace
- # + Free for Non-Commercial and Commercial use
- # + Requires no other scripts
- #===============================================================================
- # DESCRIPTION
- #===============================================================================
- # This script allows you to use a script call to randomly generate a shop. Add
- # notetags to items to specify level requirements and rarity values. The shop
- # inventory will be generated automatically according to the party level and
- # the notetags provided for items. Shops can sell items of specific types,
- # subtypes or custom defined families.
- #===============================================================================
- # INSTALLATION
- #===============================================================================
- # + Put this script after Material but before main.
- # + Add some of the notetags (described below) to the items in the database.
- # + Add a new event that represents a shop to your map.
- # + Add a script call to the event that will generate a random shop (see below).
- #===============================================================================
- # DOCUMENTATION
- #===============================================================================
- # You are required to setup two different parts to make this script work:
- # 1) Add Notetags to your items in the database.
- # 2) Add the script call to your events (chests).
- # 3) Optionally you can change the configuration below to your taste.
- #
- # 1) Editing Notetags:
- # You must specify the following notetags for all ITEMS, WEAPONS and ARMOR that
- # you want to randomly appear in your events (shops). If any items do not have
- # these tags, they will just not appear in a random shops at all.
- #
- # <family: x> # The group or family the item belongs to
- # # You define these families yourself (1-99)
- # <rarity: x> # The rarity value (1+ higher is rarer)
- # <level-min: x> # Min level of player for item to show (1-99)
- # <level-max: x> # Max level of player for item to show (1-99)
- #
- # Optional notetag for ARMORS and WEAPONS only:
- #
- # <lucky: x> # All equipped lucky items of the party are added to
- # # calculate the total chance to get rarer items.
- #
- # New Optional notetags for all item types:
- #
- # <noshop> # Item does never appear in a random shop (requires Simple Random Shop 1.0+)
- # <noloot> # Item is never found as random loot (requires Simple Random Loot 1.4+)
- # <nodrop> # Item is never dropped from an enemy (requires Simple Random Drop 1.0+)
- #
- # 2) Using the script call:
- # By using this script call, you can randomly populate a shop. Go to your event and add
- # a new command to it, choose script from the very last command tab and insert the
- # following line.
- #
- # EXAMPLE:
- #
- # random_shop(0, 1, 10, 50, 1, 1)
- #
- # SYNTAX:
- #
- # random_shop(type, rarity_min, rarity_max, price=0, amount=0, subtype=0, family=0)
- #
- # type # The type of item to be found:
- # # 0 = All Types, determined randomly
- # # 1 = Item
- # # 2 = Armor
- # # 3 = Weapon
- # # 4 = One randomly determined Type
- #
- # rarity_min # Min and Max Rareness determine the item rarity that
- # rarity_max # the script call will obtain when successful. You can
- # # state any number that you also use on the notetags
- # # of your items. Example:
- # # rarity_min=10, rarity_max=50
- # # The script call will generate a random number 1-50.
- # # An item can only be obtained if it has a rarity
- # # EQUAL or LESS than the generated number.
- #
- # price # OPTIONAL. This will alter the price of all items in
- # # the shop by X percent. It is also possible to set
- # # this to a negative number, lowering the prices.
- #
- # amount # OPTIONAL. This limites the shop inventory to X items.
- # # If not set, the default maximum amount limit is used.
- #
- # subtype # OPTIONAL. This only applies to WEAPONS or ARMOR and
- # # will be ignored otherwise. Filters the random loot
- # # to drop only items of the stated type.
- # # (e.g. 1 = General Armour)
- #
- # family # OPTIONAL. Family can be any number or 0.
- # # 0 = drops any item of the stated type/subtype
- # # x = drops only items of the stated type/subtype that
- # # share the family.
- #
- # Using a clever combination of type, subtype and families - you can tailor the random
- # shop to offer only items of a very specific type. Like only Armors of the Small
- # Shield type, or just Weapons of the Sword type and so on.
- #===============================================================================
- # COMPATABILITY
- #===============================================================================
- # + Should be compatible with most other scripts (like YANFLY engine).
- # + Can be combined with my other scripts to form the complete ITEM SUITE:
- # + Simple Random Loot
- # + Simple Random Shop
- # + Simple Random Drop
- # + Simple Random Rarities
- #===============================================================================
- $imported = {} if $imported.nil?
- $imported["Random_Shop"] = true
- module Random_Shop
- #===============================================================================
- # CONFIGURATION
- #===============================================================================
- DEFAULT_AMOUNT = 5 # Maximum number of different, available
- # Items if nothing was stated.
- #===============================================================================
- # END CONFIGURATION
- #===============================================================================
- end
- #===============================================================================
- module Random_Shop_Notetags
- def loot_rarity
- if @loot_rarity.nil?
- if @note =~ /<rarity: (.*)>/i
- @loot_rarity = $1.to_i
- else
- @loot_rarity = 0
- end
- end
- @loot_rarity
- end
- def loot_level_min
- if @loot_level_min.nil?
- if @note =~ /<level-min: (.*)>/i
- @loot_level_min = $1.to_i
- else
- @loot_level_min = 0
- end
- end
- @loot_level_min
- end
- def loot_level_max
- if @loot_level_max.nil?
- if @note =~ /<level-max: (.*)>/i
- @loot_level_max = $1.to_i
- else
- @loot_level_max = 0
- end
- end
- @loot_level_max
- end
- def loot_lucky
- if @loot_lucky.nil?
- if @note =~ /<lucky: (.*)>/i
- @loot_lucky = $1.to_i
- else
- @loot_lucky = 0
- end
- end
- @loot_lucky
- end
- def loot_family
- if @loot_family.nil?
- if @note =~ /<family: (.*)>/i
- @loot_family = $1.to_i
- else
- @loot_family = 0
- end
- end
- @loot_family
- end
- def loot_noshop
- if @loot_noshop.nil?
- if @note =~ /<noshop>/i
- @loot_noshop = true
- else
- @loot_noshop = false
- end
- end
- @loot_noshop
- end
- def loot_noloot
- if @loot_noloot.nil?
- if @note =~ /<noloot>/i
- @loot_noloot = true
- else
- @loot_noloot = false
- end
- end
- @loot_noloot
- end
- def loot_nodrop
- if @loot_nodrop.nil?
- if @note =~ /<nodrop>/i
- @loot_nodrop = true
- else
- @loot_nodrop = false
- end
- end
- @loot_nodrop
- end
- end # Random_Shop_Notetags
- #===============================================================================
- class RPG::Item
- include Random_Shop_Notetags
- end
- class RPG::Armor
- include Random_Shop_Notetags
- end
- class RPG::Weapon
- include Random_Shop_Notetags
- end
- #===============================================================================
- class Game_Interpreter
- def random_shop(type, rarity_min, rarity_max, price=0, amount=0, subtype=0, family=0)
- @goods = []
- @loot = []
- #--- Determine Type
- if type == 0
- @loot = $data_items + $data_armors + $data_weapons
- subtype = 0
- elsif type == 1
- @loot = $data_items
- @itemtype = 0
- subtype = 0
- elsif type == 2
- @loot = $data_armors
- @itemtype = 2
- elsif type == 3
- @loot = $data_weapons
- @itemtype = 1
- else
- @loot = $data_items | $data_armors | $data_weapons
- subtype = 0
- end
- #--- Preperations
- @loot.shuffle
- rarity_max = rarity_min if rarity_max < rarity_min
- amount = Random_Shop::DEFAULT_AMOUNT if amount < 1
- subtype = 0 if subtype < 0 || subtype > 99
- subtype = 0 if family < 0 || family > 99
- #--- Determine Party Luck Bonus
- mem = 0
- eqs = 0
- luck_bonus = 0
- i = 0
- no_equips = $game_party.members.count * $game_party.members[0].equips.count
- $game_party.members.each do |mem|
- mem.equips.each do |eq|
- next if eq.nil?
- luck_bonus += eq.loot_lucky
- end
- end
- #--- Determine Rarity Chance
- checked = 0
- inventory = 0
- itemprice = 0
- duplicates = []
- restart = false
- continue = true
- no_items = @loot.count - 1
- rare_chance = rand(rarity_max - rarity_min) + rarity_min + luck_bonus + 1
- random_item = rand(no_items) + 1
- begin_count = rand(no_items) + 1
- #--- Determine Random Item
- no_items.times do |i|
- i = i + random_item
- begin_count += 1 if restart
- if i > no_items
- i = i - i + rand(no_items) + 1
- restart = true
- end
- #--- Get Random Item
- if family != 0 && @loot[i].loot_family != family
- continue = false
- end
- if subtype != 0 && type == 2
- if @loot[i].atype_id == subtype
- continue = false
- end
- end
- if subtype != 0 && type == 3
- if @loot[i].wtype_id == subtype
- continue = false
- end
- end
- #--- Setup Shop Inventory
- if continue
- next if @loot[i].nil?
- next if @loot[i].loot_noshop
- if @loot[i].loot_level_max >= $game_party.leader.level && @loot[i].loot_level_min <= $game_party.leader.level
- if @loot[i].loot_rarity <= rare_chance
- if checked < no_items && inventory < amount
- if !duplicates.include?(@loot[i].id)
- #--- Recheck Item Type
- if @loot[i].is_a?(RPG::Item)
- @itemtype = 0
- elsif @loot[i].is_a?(RPG::Weapon)
- @itemtype = 1
- elsif @loot[i].is_a?(RPG::Armor)
- @itemtype = 2
- end
- #--- Check Item Price
- if price != 0
- itemprice = @loot[i].price + (@loot[i].price * (price/100))
- end
- if price <= 0
- @goods.push([@itemtype, @loot[i].id, 0])
- else
- @goods.push([@itemtype, @loot[i].id, 1, itemprice])
- end
- duplicates.push(@loot[i].id)
- inventory += 1
- end
- else
- break
- end
- end
- end
- end
- checked += 1
- end
- if @goods.size > 0
- @goods.shuffle
- SceneManager.call(Scene_Shop)
- SceneManager.scene.prepare(@goods, true)
- end
- end
- end # Game_Interpreter
- #===============================================================================
- # END OF SCRIPT
- #===============================================================================
RAW Paste Data