this script is by deke. this script allows you to let the monsters give random items after battles, depending on a "value" status. read the script comments by deke to understand. i asked deke if i could post his script in my page, and the answer was positive, so here the cool script. the following message is by deke: here's my update to the this should be a little intuitive. all you have scene_battle 4 and call then copy and paste the
random loot script i posted a couple of days ago. more user friendly and also a little more to do is create a new class directly underneath it scene_battle 5. following code into it.
code#=========================================================== #class scene_battle 5 #--------------------------------------------------------------------------------------------------------------------#-written by deke #--------------------------------------------------------------------------------------------------------------------# # the purpose of this class is to generate random loot drops at the end of winning battles. #this script work independently of the item drops programed in for monsters. this script allows #easy customization of the frequency and quality of loots by simple modifications of the configure #method-see description below (how this script works) to see what each value does. # #optional feature a-don't drop weapons/armors/items with price 0 # this option makes it so that equipment with price 0 is excluded from being dropped by monsters # at random. some of the items in the database have a default price of zero and have no effect. # they are really only for event processing purposes, they really should be dropped at random. # this also creates an easy way to designate an weapon/armor/item as "non" droppable. simply # set the price of the equipment to 0. by default this option is set to true. # #optional feature b- don't drop "flagged" items #credit rpg advocate for creating the elemental taggin trick # certain weapons/armors/ and items can be designated as unique (random monsters won't drop # them). this option requires some addition script modification. it is only recommended if you # want to have non droppable items that the player can sell back at a later time for profit. by default # this option is set to off. see comments at the very end of this script for information on how
# to implement this option. # #optional feature c-debug mode # this option is allows the game tester to see what weapons/items/armor have a potential of being # dropped. after a victory, the list of possible weapons/items/armors is displayed. this allows the # tester to determine if the value of the "quality percentage" should be modified. by default this # option is off. # #============================================================ # how this script works #---------------------------------------------------------------------------------------------------------------------# basically this script creates sorted list of weapons, armor, and items from cheapest to most #expensive. (actually the list are of the equipment i.d.'s) it also creates a list of experience from #monster from the fewest eqperience to the most experience. then the program determines a #percentile of difficultly" based on the experience gained versus the possible experienced gained from #any monster. # next, the program generats some random numbers to determine if you the party gains any #weapons/armors/items. if the party gains equipment the "percentile cost" of that equipment should #roughly correlate with the percentile of difficulty. basically, what this mean is that if you kill a monster #that gives you more exp than 30% of the monsters and you succeed at getting equipment, the cost #of the equipments will be higher than approximatley 30% of that equipment of that type. of course, #there are some random variations thrown to create variety. # here's a list of the variables to edit to customize loot dropping. # @option_a and option_b: see above # @weapon_per, @armor_per, @item_per # the percentage change that the equipment drops after a succesful battle # remember that armor also includes shields and accesories, so the percentage should # proabably be higher. # @weapon_quality_per,@armor_quality_per,@item_quality_per # this value determines how much variance there is loot drops. # the lower the number, the closer the loot cost percentile correlates with the difficulty percentile. # @two_weapon_per,@two_armor_per,@two_item_per # the percentage change that two of that type of equipment drop. # @loot_size # the maximum number of loots allowable after a battle including monster specific drops #note: if this program starts to lag- it doesn't with the standard size equipment list. you may want # to change @weapon_set, @armor_set, and @item_set, and @exp_set
to global variables. # just use the find and replace feature and change @weapon_set to $weapon_set... also change # the statements if @weapon_set==nil to $weapon_set==[]. finally, in the scene_title class # add the following lines of code right after the begining of the main method: # $weapon_set=[] # $armor_set=[] # $item_set=[] # $exp_set=[] #making this change will mean that the sort funcitons only run the once in the game. sorting functions #have the potential to take up a lot of time if the size of the equipment arrays get larg.e #========================================================== class scene_battle #------------------------------------------------------------------------------------------------------------------#-------------------------------------------------------------------------------------------------------------#this method sets the values for such thing as dropped percentages. def configure @option_a=true @option_b=false if @option_b @unique=20 end @option_c=false @weapon_prob=10 @two_weapon_prob=1 @armor_prob = 20 @two_armor_prob=2 @item_prob=12 @two_item_prob=2 @weapon_quality_per=12 @armor_quality_per=12 @item_quality_per=18 @loot_size=5 end
#---------------------------------------------------------------------------------------------------------#this metod overwrite start_phase5 from scene_battle 2. it is nearly identidcal, except that #it call the methods to create random loot drops. def start_phase5 @phase = 5 $game_system.me_play($game_system.battle_end_me) $game_system.bgm_play($game_temp.map_bgm) exp = 0 gold = 0
highest_exp=0 treasures = [] for enemy in $game_troop.enemies unless enemy.hidden exp += enemy.exp if enemy.exp > highest_exp highest_exp=enemy.exp end gold += enemy.gold if rand(100) < enemy.treasure_prob if enemy.item_id > 0 treasures.push($data_items[enemy.item_id]) end if enemy.weapon_id > 0 treasures.push($data_weapons[enemy.weapon_id]) end if enemy.armor_id > 0 treasures.push($data_armors[enemy.armor_id]) end end end end loot=random_treasure(highest_exp) treasures +=loot treasures = treasures[0..@loot_size] for i in 0...$game_party.actors.size actor = $game_party.actors[i] if actor.cant_get_exp? == false last_level = actor.level actor.exp += exp if actor.level > last_level @status_window.level_up(i) end end end $game_party.gain_gold(gold) for item in treasures case item when rpg::item $game_party.gain_item(item.id, 1) when rpg::weapon $game_party.gain_weapon(item.id, 1) when rpg::armor $game_party.gain_armor(item.id, 1) end end @result_window = window_battleresult.new(exp, gold, treasures) @phase5_wait_count = 100 end #---------------------------------------------------------------------------------------------------------def random_treasure(exp) configure loot=[] num=0 max=0 if @weapon_set == nil
weapon_set end if @armor_set==nil armor_set end if @item_set==nil item_set end if @exp_set == nil exp_set end rank=0 for i in 0...@exp_set.size if exp >= @exp_set[i] rank=i end end @percentile = (rank *100) /@exp_set.size n=rand(100) if n <= @weapon_prob weapon=weapon_drop loot.push(weapon) end if n <= @two_weapon_prob weapon=weapon_drop loot.push(weapon) end n=rand(100) if n <= @armor_prob armor=armor_drop loot.push(armor) end if n <= @two_armor_prob armor=armor_drop loot.push(armor) end n=rand(100) if n <= @item_prob item=item_drop loot.push(item) end if n <= @two_item_prob item=item_drop loot.push(item) end return loot end #-----------------------------------------------------------------------------------------#this method, if called, determins what weapon should be dropped based on the difficulty of the #battle and the settings in the configure method. def weapon_drop min=(@percentile-@weapon_quality_per)*@weapon_set.size max=(@percentile+@weapon_quality_per)*@weapon_set.size max=(max/100).ceil min=(min/100).floor
if min <0 min=0 end if max > @weapon_set.size max=@weapon_set.size end weapons_possible=@weapon_set[min..max] if weapons_possible.size != 0 if @option_c for i in 0...weapons_possible.size-1 weapon=$data_weapons[weapons_possible[i]] print weapon.name end end index=rand(weapons_possible.size) return $data_weapons[weapons_possible[index]] else mid = @percentile*@weapon_set.size mic=(mid/100).ceil return$data_weapons[mid] end end #-----------------------------------------------------------------------------------------#this method, if called, determins what armor should be dropped based on the difficulty of the #battle and the settings in the configure method. def armor_drop min=(@percentile-@armor_quality_per)*@armor_set.size max=(@percentile+@armor_quality_per)*@armor_set.size max=(max/100).ceil min=(min/100).floor if min <0 min=0 end if max > @armor_set.size max=@armor_set.size end armors_possible=@armor_set[min..max] if armors_possible.size != 0 if @option_c for i in 0...armors_possible.size-1 armor=$data_armors[armors_possible[i]] print armor.name end end index=rand(armors_possible.size) return $data_armors[armors_possible[index]] else mid = @percentile*@armor_set.size mic=(mid/100).ceil return$data_armors[mid] end end #---------------------------------------------------------------------------
---------------#this method, if called, determins what item should be dropped based on the difficulty of the #battle and the settings in the configure method. def item_drop min=(@percentile-@item_quality_per)*@item_set.size max=(@percentile+@item_quality_per)*@item_set.size max=(max/100).ceil min=(min/100).floor if min <0 min=0 end if max > @item_set.size max=@item_set.size end items_possible=@item_set[min..max] if items_possible.size != 0 if @option_c for i in 0...items_possible.size item=$data_items[items_possible[i]] print item.name end end index=rand(items_possible.size) return $data_items[items_possible[index]] else mid = @percentile*@item_set.size mic=(mid/100).ceil return$data_items[mid] end end #------------------------------------------------------------------------------------------------------------#this method creates an array of weapon indexes from the cheapest to the most expensive, if #they are not excluded by @option_a or @option_b. def weapon_set @weapon_set=[] cheap_index=nil for i in 1...$data_weapons.size cheap_index=nil cheapest=9999999 for j in 1...$data_weapons.size eligible=true weapon=$data_weapons[j] if @weapon_set.include?(j) eligible =false end if weapon.element_set.include?(@unique) and @option_b eligible=false end if weapon.price ==0 and @option_a eligible=false end if weapon.price < cheapest and eligible cheapest=$data_weapons[j].price cheap_index=j
end end if cheap_index != nil @weapon_set.push(cheap_index) end end end #------------------------------------------------------------------------------------------------------------#this method creates an array of armor indexes from the cheapest to the most expensive, if #they are not excluded by @option_a. def armor_set @armor_set=[] cheap_index=nil for i in 1...$data_armors.size cheap_index=nil cheapest=9999999 for j in 1...$data_armors.size eligible=true armor=$data_armors[j] if @armor_set.include?(j) eligible =false end if armor.guard_element_set.include?(@unique) and @option_b eligible=false end if armor.price == 0 and @option_a eligible=false end if armor.price < cheapest and eligible cheapest=$data_armors[j].price cheap_index=j end end if cheap_index != nil @armor_set.push(cheap_index) end end end #------------------------------------------------------------------------------------------------------------#this method creates an array of item indexes from the cheapest to the most expensive, if #they are not excluded by @option_a or @option_b. def item_set @item_set=[] cheap_index=nil for i in 1...$data_items.size cheap_index=nil cheapest=9999999 for j in 1...$data_items.size eligible=true item=$data_items[j] if @item_set.include?(j) eligible =false
end if item.element_set.include?(@unique) and @option_b eligible=false end if item.price == 0 and @option_a eligible=false end if item.price < cheapest and eligible cheapest=$data_items[j].price cheap_index=j end end if cheap_index != nil @item_set.push(cheap_index) end end end #-----------------------------------------------------------------------------------------#this array creates a list of possible experience gained from all the monsters in the database, #sorted from least experience to most experience. def exp_set @exp_set=[] weak_index=nil for i in 1...$data_enemies.size weak_index=nil weakest=9999999 for j in 1...$data_enemies.size eligible=true enemy=$data_enemies[j] if @exp_set.include?(j) eligible =false end if enemy.exp < weakest and eligible weakest=enemy.exp weak_index=j end end if weak_index != nil @exp_set.push(weak_index) end end if @exp_set.size != 0 for i in 0...@exp_set.size enemy = $data_enemies[@exp_set[i]] @exp_set[i] = enemy.exp end end end end # of class definition #-----------------------------------------------------------------------------------------------------------#further instructions for elemental tagging. first, read the description here: #http://www.phylomortis.com/resource/script/tut001.html
#add a new effect called "no drop" or "unique" then add the proper elements.delete command #as instructed in code sample 2. #finally, set the value of @unique to the number of effect (probalby 17) if you didn't add any other effects. if the worst hasn't happened yet, it is because you have not tried everything yet.