Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Solved]How to make a monster drop more then one item?

Scuff

Member

I was not sure if this is the right spot...so... tell me if its in the wrong spot. How can i make a monster drop more then one item? Can i make it so it has 10% drop for "said" item and a 50% drop for "said" item?
 

Atoa

Member

For XP:

Code:
#==============================================================================

# Multi_Drop

# by Atoa

#==============================================================================

# This script allows to add more than one item for the enemies

#

# Enemy_Drops[ID] = {"ITEM" => RATE}

#

# ID = Enemy ID

# ITEM = Item Type and ID. Must be written line "xY"

#  where x =  item type e Y = item ID

# x must be "a" for armors, "w" for weapons, "i" for items

# RATE = Drop rate. An value from 0.0 and 100.0

#   ex.: 5.4  = 5,4% drop rate

#

# E.g.:

# Enemy_Drops[15] = {"w6" => 22.5, "a9" => 12}

# That means the enemy ID 15 (Enemy_Drops[15])

# has 22,5% of droping the weapon ID 6 ("w6" => 22.5)

# and also has 12% of droping the armor ID 9 ("a9" => 12)

#

#==============================================================================

 

#==============================================================================

# Module Atoa

#==============================================================================

module Atoa

  Enemy_Drops = [] # dont remove this line

 

  # Add here the new enemies drops

  Enemy_Drops[1] = {"a1" => 15.5, "w1" => 12, "i2" =>  5}

  Enemy_Drops[2] = {"i3" => 22.5, "w2" => 0.5}

 

end

 

#==============================================================================

# Game_Enemy

#==============================================================================

class Game_Enemy < Game_Battler

  #--------------------------------------------------------------------------

  include Atoa

  #--------------------------------------------------------------------------

  def multi_drops

    drop_items = []

    return drop_items if Enemy_Drops[@enemy_id] == nil

    Enemy_Drops[@enemy_id].each do |item, drop_rate|

      item = item.split('')

      if item[0] == "i"

        item = item.join

        item.slice!("i")

        drop_items.push($data_items[item.to_i]) if rand(1000) < (drop_rate * 10).to_i

      elsif item[0] == "a"

        item = item.join

        item.slice!("a")

        drop_items.push($data_armors[item.to_i]) if rand(1000) < (drop_rate * 10).to_i

      elsif item[0] == "w"

        item = item.join

        item.slice!("w")

        drop_items.push($data_weapons[item.to_i]) if rand(1000) < (drop_rate * 10).to_i

      end

    end

    return drop_items

  end

  #--------------------------------------------------------------------------

  def multi_drop_items

    multi_items = []

    multi_items.push(multi_drops)

    for item in multi_items

      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

    return multi_items

  end

end

 

#==============================================================================

# Window_BattleResult

#==============================================================================

class Window_BattleResult < Window_Base

  #--------------------------------------------------------------------------

  def add_multi_drops

    for enemy in $game_troop.enemies

      @treasures.push(enemy.multi_drop_items)

    end

    @treasures.flatten!

    @treasures.sort! {|a, b| a.id <=> b.id}

    @treasures.sort! do |a, b|

      a_class = a.is_a?(RPG::Item) ? 0 : a.is_a?(RPG::Weapon) ? 1 : 2

      b_class = b.is_a?(RPG::Item) ? 0 : b.is_a?(RPG::Weapon) ? 1 : 2

      a_class <=> b_class

    end

    self.height = [@treasures.size * 32 + 64, 288].min

    self.contents = Bitmap.new(width - 32, @treasures.size * 32 + 32)

    self.y = 160 - height / 2

    refresh

  end

  #--------------------------------------------------------------------------

  def update

    super

    if @treasures.size * 32 + 64 > 288

      if Input.press?(Input::UP)

        self.oy -= 4 if self.oy > 0

      elsif Input.press?(Input::DOWN)

        self.oy += 4 if self.oy < @treasures.size * 32 + 64 - 288

      end

    end   

  end

end

 

#==============================================================================

# Scene_Battle

#==============================================================================

class Scene_Battle

  #--------------------------------------------------------------------------

  alias multi_drop_start_phase5 start_phase5

  alias multi_drop_update_phase5 update_phase5

  #--------------------------------------------------------------------------

  def start_phase5

    multi_drop_start_phase5

    @result_window.add_multi_drops

  end

  #--------------------------------------------------------------------------

  def update_phase5

    @result_window.update

    multi_drop_update_phase5

  end

end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top