Confusing results with Galv's Random Loot 1.4

Ninjakillzu

Veteran
Veteran
Joined
Aug 19, 2013
Messages
265
Reaction score
223
First Language
English
Primarily Uses
RMVXA
So, I have just started using this script: https://forums.rpgmakerweb.com/index.php?threads/galvs-random-loot-v1-4.43741/ to create random loot in chests, but I get weird and unwanted results. In the script, you can separate gear into "families". For instance, I can set an item as family 1 (food), family 2 (drugs), family 3 (grenades), etc.

Let's say I want a chest to only give out 1 random drug of a certain rarity range. So, in the script format [random_item(type, rarity_min, rarity_max, subtype=0, monster_id=0, family=0)], I use random_item(1, 1, 10, 2) [the last number specifies the family ID]. It should only give 1 drug right? No, it seems to also include other items as well. If I wanted it to give other items, I would not specify a family. If I use random_item(1, 1, 10, 0 ,0, 2), then the chests are always empty. Anyone else know why I am getting these results?
 

MobiusXVI

Game Maker
Veteran
Joined
Mar 20, 2013
Messages
383
Reaction score
91
First Language
English
Primarily Uses
For your first problem, the order that you specify is important, so when you said
I use random_item(1, 1, 10, 2) [the last number specifies the family ID].
The last number actually specifies the subtype. I think an example is the easiest way to see how this works. Suppose I had the following method:
Code:
def foo(a,b,c=3,d=4,e=5)
    puts a
    puts b
    puts c
    puts d
    puts e
end
If we make some calls to it, we can see what it outputs:
Code:
foo(6,7) --> 6,7,3,4,5
foo(6,7,8) --> 6,7,8,4,5
foo(6,7,8,9) --> 6,7,8,9,5
foo(6,7,8,9,10) --> 6,7,8,9,10
Notice how it overwrites the optional parameters in the order that they show up. So you can't skip around (technically you can, but it requires the original script be written differently than it currently is and use a newer version of Ruby).

For your second problem, I'm not sure. The way you wrote it seems to me to be the correct way to specify it. If I had to guess, I'd say maybe there's an issue with your setup like notetags or customization options or something like that?
 
Last edited:

Ninjakillzu

Veteran
Veteran
Joined
Aug 19, 2013
Messages
265
Reaction score
223
First Language
English
Primarily Uses
RMVXA
For your second problem, I'm not sure. The way you wrote it seems to me to be the correct way to specify it. If I had to guess, I'd say maybe there's an issue with your setup like notetags or customization options or something like that?
After messing around with it some more, it seems like it does actually work, but the chance to get something is REALLY low, which I don't know if it's intentional within the script. It took around 12 tries (I averaged how many presses it took to get an item. Some took a low amount, like 3, while others took forever, like 26.) to get an item using random_item(1, 1, 10, 0, 0, 2). The items I am testing have a rarity between 2 and 8. I want it to always give items, not have a chance of nothing inside.
 

MobiusXVI

Game Maker
Veteran
Joined
Mar 20, 2013
Messages
383
Reaction score
91
First Language
English
Primarily Uses
So according to the script's own documentation, and my initial look through it. It should always give you an item between the rarities you specify -- provided one exists. So the only reason it wouldn't give you something is if it the chance was landing on 1 because your items are between 2 and 8, then it can't give you an item with a rarity of 1 or less. You could try adding items with a rarity of 1 or raising your rarity_min to 2 and see if the issue still persists.
 

Ninjakillzu

Veteran
Veteran
Joined
Aug 19, 2013
Messages
265
Reaction score
223
First Language
English
Primarily Uses
RMVXA
I changed all the item's rarities to 1, but the issue still persists, even if the rarity_min = 1. This is what my notetags look like for the items:

<family: 2>
<rarity: 1>
<level-min: 1>
<level-max: 99>
 

MobiusXVI

Game Maker
Veteran
Joined
Mar 20, 2013
Messages
383
Reaction score
91
First Language
English
Primarily Uses
Ok, I spent some time digging around in the script and the more I dug the more I found that was wrong with the script. Basically, the script was structured incorrectly. It would only trigger a monster (assuming you want that behavior) if it failed to find an item. It would frequently fail though because if the first randomly selected item didn't belong to the family you listed, then it would declare that it couldn't find anything. Then there were some other more minor issues.

Anyways... long story short. I just rewrote a good chunk of the script and called it v1.5. It's posted below. Do me a favor and test it out some. If it looks good, I'll post it over in the original thread so others can make use of it.
Code:
#===============================================================================
#                          +++ 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
#===============================================================================

Oh, one more thing, the way the rarity scale is set up causes higher linear rarities to be available on an exponentially decreasing basis. That is to say that an increase of 1 in rarity (like from 3 -> 4) will cause the odds of getting the item to decrease exponentially. Just something to keep in mind.
 

Ninjakillzu

Veteran
Veteran
Joined
Aug 19, 2013
Messages
265
Reaction score
223
First Language
English
Primarily Uses
RMVXA
Wow! Thanks for doing that! Unfortunately, I get an error when activating an event with the script tag: random_item(1, 1, 5, 0, 0, 2)

 

Ninjakillzu

Veteran
Veteran
Joined
Aug 19, 2013
Messages
265
Reaction score
223
First Language
English
Primarily Uses
RMVXA
Ok, I spent some time digging around in the script and the more I dug the more I found that was wrong with the script. Basically, the script was structured incorrectly. It would only trigger a monster (assuming you want that behavior) if it failed to find an item. It would frequently fail though because if the first randomly selected item didn't belong to the family you listed, then it would declare that it couldn't find anything. Then there were some other more minor issues.

Anyways... long story short. I just rewrote a good chunk of the script and called it v1.5. It's posted below. Do me a favor and test it out some. If it looks good, I'll post it over in the original thread so others can make use of it.
Code:
#===============================================================================
#                          +++ 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
#===============================================================================

Oh, one more thing, the way the rarity scale is set up causes higher linear rarities to be available on an exponentially decreasing basis. That is to say that an increase of 1 in rarity (like from 3 -> 4) will cause the odds of getting the item to decrease exponentially. Just something to keep in mind.
As for my error, I deleted these two lines
Code:
    random_loot_debug_print_loot("ALL LOOT")
    random_loot_debug_print_loot("SELECTED LOOT")
from the script and that solved the error. I don't know if those lines were essential or not. So far, it seems like the script works good otherwise. I'll have to keep testing it.
 

MobiusXVI

Game Maker
Veteran
Joined
Mar 20, 2013
Messages
383
Reaction score
91
First Language
English
Primarily Uses
Oops! That was some old testing code that got left in by mistake, so that's my bad :dizzy:. I'm glad you found the problem though. :thumbsup-right::)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,036
Messages
1,018,461
Members
137,821
Latest member
Capterson
Top