#===============================================================================
# +++ GALV'S RANDOM LOOT +++
#===============================================================================
# + Original Script by Galv
# + Extended by Fhizban (also known as Malagar)
# + Updated by Mobius_XVI
# + Version 1.5
# + Updated February 2019
# + For RPGMaker VX Ace
# + Free for Non-Commercial and Commercial use
# + Requires no other scripts
#===============================================================================
# DESCRIPTION
#===============================================================================
# This script allows you to have a script call to gain random loot from chests.
# Add notetags to items to specify level requirements and rarity values.
# A notetag can also be added to items that you want to increase the chance to
# find rarer loot. Random loot can be limited to certain types of items too.
#===============================================================================
# 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 chest or other container to your map.
# + Add a script call to the event that will generate random loot (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 (chests). If any items do not have
# these tags, they will just not appear in a random chest 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.
#
# 2) Using the script call:
# By using this script call, you can randomly obtain an item. 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_item(0, 1, 10, 50, 1, 1)
#
# SYNTAX:
#
# random_item(type, rarity_min, rarity_max, subtype=0, monster_id=0, family=0)
#
# type # The type of item to be found:
# # 0 = Random/any type (you can also use numbers 4+)
# # 1 = Item
# # 2 = Armor
# # 3 = Weapon
#
# 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.
#
# 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)
#
# monster_id # OPTIONAL. This ID is used to decide what TROPP id
# # will be used when a monster-in-a-box is encountered.
# # Otherwise the standard troop will be used. Ignored
# # if encounter chance is set to zero.
#
# 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
# loot spawn to create 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.
#===============================================================================
$imported = {} if $imported.nil?
$imported["Random_Loot"] = true
module Random_Loot
#===============================================================================
# CONFIGURATION
#===============================================================================
GET_MESSAGE = "Found " # Text before item name.
GET_MESSAGE_AFTER = "!" # Text after item name.
FAIL_MESSAGE = "It's empty!" # Text when random item comes up nothing.
SOUND_EFFECT = ["Coin", 90, 100] # Sound effect of gaining an item.
# ["SE Name", volume, pitch]
# Make "SE Name" = "" for no sound.
DEFAULT_MONSTER = 1 # Default Monster ID if none stated.
MONSTER_CHANCE = 10 # % Chance that if no item is found, a
# battle will happen instead.
ESCAPE_MONSTER = true # Can you escape it? true or false
MONSTER_MESSAGE = "Monster in a box!" # Message when a monster appears.
# Make it "" to disable.
#===============================================================================
# END CONFIGURATION
#===============================================================================
end
#===============================================================================
module Random_Loot_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
end # Random_Loot_Notetags
#===============================================================================
class RPG::Item
include Random_Loot_Notetags
end
class RPG::Armor
include Random_Loot_Notetags
end
class RPG::Weapon
include Random_Loot_Notetags
end
#===============================================================================
class Game_Interpreter
def random_item(type, rarity_min, rarity_max, subtype=0, monster_id=0, family=0)
# Input Check
unless type == 2 or type == 3
subtype = 0
end
if rarity_max < rarity_min
rarity_max = rarity_min
end
if subtype < 0 || subtype > 99
subtype = 0
end
if family < 0 || family > 99
family = 0
end
if monster_id < 1
monster_id = Random_Loot::DEFAULT_MONSTER
end
# Check for Monster Trigger
monster_chance = rand(100) + 1
if monster_chance <= Random_Loot::MONSTER_CHANCE
random_loot_battle(monster_id)
else
random_loot_get_item(type, rarity_min, rarity_max, subtype, family)
#$game_message.add(Random_Loot::FAIL_MESSAGE)
#wait_for_message
end
end
def random_loot_battle(monster_id)
if Random_Loot::MONSTER_MESSAGE != ""
$game_message.add("\\>" + Random_Loot::MONSTER_MESSAGE + "\\.\\.\\.\\^")
wait_for_message
end
BattleManager.setup(monster_id, Random_Loot::ESCAPE_MONSTER, false)
SceneManager.call(Scene_Battle)
end
def random_loot_get_item(type, rarity_min, rarity_max, subtype, family)
# Get loot list
@loot = random_loot_get_loot_list(type)
# Determine Party Luck Bonus
luck_bonus = random_loot_luck_bonus()
# Determine Rarity Chance
rare_chance = rand(rarity_max - rarity_min) + rarity_min + luck_bonus + 1
# Filter loot
random_loot_debug_print_loot("ALL LOOT")
random_loot_filter_loot(type, subtype, family, rare_chance)
random_loot_debug_print_loot("SELECTED LOOT")
# Give Random Item
random_loot_give_treasure
end
def random_loot_get_loot_list(type)
#--- Determine Type
if type == 1
loot = $data_items
elsif type == 2
loot = $data_armors
elsif type == 3
loot = $data_weapons
else
loot = $data_items + $data_armors + $data_weapons
end
# Remove nil items
loot = loot.select do |thing|
not (thing.nil?)
end
return loot
end
def random_loot_luck_bonus
luck_bonus = 0
$game_party.members.each do |member|
member.equips.each do |equip|
unless equip.nil?
luck_bonus += equip.loot_lucky
end
end
end
return luck_bonus
end
def random_loot_filter_loot(type, subtype, family, rare_chance)
# If subtype selection is used
if subtype > 0
# If type is armors
if type == 2
# Select based on subtype
@loot = @loot.select do |thing|
thing.atype_id == subtype
end
end
# If type is weapons
if type == 3
# Select based on subtype
@loot = @loot.select do |thing|
thing.wtype_id == subtype
end
end
end
# If family selection is used
if family > 0
# Select based on family
@loot = @loot.select do |thing|
thing.loot_family == family
end
end
# Filter based on level
@loot = @loot.select do |thing|
(thing.loot_level_min <= $game_party.leader.level) and
($game_party.leader.level <= thing.loot_level_max)
end
# Filter based on rarity
@loot = @loot.select do |thing|
thing.loot_rarity <= rare_chance
end
end
def random_loot_give_treasure
reward = @loot.sample()
$game_party.gain_item(reward, 1)
RPG::SE.new(Random_Loot::SOUND_EFFECT[0], Random_Loot::SOUND_EFFECT[1], Random_Loot::SOUND_EFFECT[2]).play
$game_message.add(Random_Loot::GET_MESSAGE + "\\I[" + reward.icon_index.to_s + "]" + reward.name.to_s + Random_Loot::GET_MESSAGE_AFTER)
wait_for_message
return
end
end # Game_Interpreter
#===============================================================================
# END OF SCRIPT
#===============================================================================