Code:
################################################################################
# Random_Item_Script #
# Found By Gamer Aof #
####################################################################################
#
#Put the following in chest through script commands to create random chests:
#Random_Box.gain_item(<box_id>,<min>,<max>,<[gold_min,gold_max]>,gold_chance)
#E.g Random_Box.gain_item(4,1,1,0,0)
#box_id = E.g if 1 Anything with <BOX1(amount)> in their not field will be
#included in this box
#min = minimum amount of DIFFERENT ITEMS not amount same items
#max = maximum amount of DIFFERENT ITEMS not amount same items
#gold = amount of gold written as [min,max] or as a fix number
#gold_odds = chance of getting gold e.g. 50 means 50%
#
#
#Known Bugs: If you have less items in a box than the max it will create an error
#CONFIG
module VitalIce_RB
#DO NOT REMOVE THIS ONE
BOX_ITEM = []
#To make a Random Box that you use in the inventory do:
#BOX_ITEM[item_id] = [<box_id>,<min>,<max>,<[gold_min,gold_max]>,gold_chance]
#item_id = the random box item
#box_id = E.g if 1 Anything with <BOX1(amount)> in their not field will be
#included in this box
#min = minimum amount of DIFFERENT ITEMS not amount same items
#max = maximum amount of DIFFERENT ITEMS not amount same items
#gold = amount of gold written as [min,max] or as a fix number
#gold_odds = chance of getting gold e.g. 50 means 50%
#Random Box1 : Gives Gold and healing Items
BOX_ITEM[21] = [1,2,5,[20,100],50]
#Random Box2 : Gives Gold and healing Items and box items
BOX_ITEM[22] = [2,2,5,0,0]
#Random Box3 : Gives Weapons
BOX_ITEM[23] = [3,2,5,0,0]
#Random Box4 : Gives Armor
BOX_ITEM[24] = [4,2,5,0,0]
#Random Box5 : Gives Weapons and Armors
BOX_ITEM[25] = [5,2,5,0,0]
#Random Box6 : Gives Money
BOX_ITEM[26] = [5,0,0,[1,100],100]
#DO NOT CHANGE, SCRIPT TO READ THE NOTE FIELDS
BOX_AMOUNT = /<(?:BOX|box)(\d+)\(([0-9]+)\-([0-9]+)\)\>/i
BOX_AMOUNT_FIXED = /<(?:BOX|box)(\d+)\(([0-9]+)\)\>/i
#Change Fontsize
FONTSIZE = 16
#Change Freeze time when getting an item
FREEZE = 50
end
#~~~~~~~~~~~~~~~~~~~~~~SCRIPT~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~
################################################################################
##
#CATEGROIZES THE ITEM IN TO BOXES AND DETRMINES THE AMOUNTS
################################################################################
class RPG::BaseItem
def create_box_cache
@box_amount = []
@note.split(/[\r\n]+/).each { |line|
case line
when VitalIce_RB::BOX_AMOUNT_FIXED
box = $1.to_i
amount = $2.to_i
@box_amount[box] = amount
when VitalIce_RB::BOX_AMOUNT
box = $1.to_i
min = $2.to_i
max = $3.to_i
diff = rand(max - min + 1)
amount = max - diff
@box_amount[box] = amount
end
}
end
def box_amount
create_box_cache
return @box_amount
end
end
################################################################################
##
# THE GAIN ITEM MESSAGE SCRIPT
################################################################################
##
class Window_Gain_Item < Window_Base
def self.message_group(width, height,items,amounts,gold)
gold >= 1 ? gold_h = height : gold_h = 0
@window = Window_Base.new(80, 175-(height/2)*items.size,width,height*items.size+gold_h)
@window.contents.clear
@window.contents.font.size = VitalIce_RB::FONTSIZE
Sound.play_use_item
for i in 0..items.size-1
@window.contents.draw_text(0, 0+i*height, 352, 24, items[i].name + ' gained' + " x " + amounts[i].to_s, 1)
@window.draw_icon(items[i].icon_index, 30, 0+i*height, enabled = true)
end
if gold != 0
contents = true
@window.draw_icon(205, 30, 0+items.size*height, enabled = true)
@window.contents.draw_text(0, 0+items.size*height, 352, 24, gold.to_s + Vocab::gold + ' gained' , 1)
end
contents = true if items[0].is_a?(RPG::BaseItem)
Graphics.wait(VitalIce_RB::FREEZE) if contents == true
@window.dispose
end
def self.msg_item(width,height,item_id,type,amount)
@window = Window_Base.new(80, 175,width,height)
case type
when 1
item = $data_items[item_id]
when 2
item = $data_weapons[item_id]
when 3
item = $data_armors[item_id]
end
@window.contents.draw_text(0, 0, 352, 24, item.name + ' gained' + " x " + amount.to_s, 1)
@window.draw_icon(item.icon_index, 30, 0, enabled = true)
Graphics.wait(VitalIce_RB::FREEZE)
@window.dispose
end
end
################################################################################
#RANDOM BOX SCRIPT
###############################################################################
class Random_Box
def self.gain_item(box_id,min,max,gold_range,gold_odds)
item_array = []
for weapon in $data_weapons
next if weapon == nil
next unless weapon.box_amount[box_id] != nil
item_array.push(weapon)
end
for armor in $data_armors
next if armor == nil
next unless armor.box_amount[box_id] != nil
item_array.push(armor)
end
for item in $data_items
next if item == nil
next unless item.box_amount[box_id] != nil
item_array.push(item)
end
diff = rand(max - min + 1)
item_amount = max - diff
item_amount = 0 if item_amount <= 0
item_gained = []
for i in 0..item_amount - 1
id = rand(item_array.size)
item_gained[i] = item_array[id]
item_array.delete_at(id)
end
gained_array = []
for item in item_gained
next if item == nil
gained = item.box_amount[box_id]
gained_array.push(item.box_amount[box_id])
$game_party.gain_item(item, gained)
end
if gold_range.is_a?(Array)
diff = rand(gold_range[1] - gold_range[0]+1)
gold = gold_range[1] - diff
gold = 0 if gold <= 0
else
gold = gold_range
end
gold = 0 if gold_odds < rand(100)
$game_party.gain_gold(gold)
Window_Gain_Item.message_group(384, 56,item_gained,gained_array,gold)
end
end
################################################################################
##
#DEALS WITH RANDOM BOXES IN INVENTORY
################################################################################
####
class Scene_Item
alias vitalice_uin use_item_nontarget
def use_item_nontarget
vitalice_uin
box = VitalIce_RB::BOX_ITEM[@item.id]
if box != nil
Random_Box.gain_item(box[0],box[1],box[2],box[3],box[4])
$scene = Scene_Item.new
end
end
end