The RPG Maker Resource Kit

RMRK RPG Maker Creation => Requests => Script Request => Topic started by: sacred on September 15, 2010, 12:55:53 PM

Title: [Request] Force Drop Item
Post by: sacred on September 15, 2010, 12:55:53 PM
Force Drop Item
September 15th, 2010




Summary
It's sort of rather easy, I think. I just want a script that force enemy to drop an item, like in ff10. Apply to weapon and items and skills.

Features Desired

Mockups
None yet.

Games its been in




Did you search?
Yes

Where did you search?

What did you search for?
Title: Re: [Request] Force Drop Item
Post by: The Mormegil on September 15, 2010, 01:41:01 PM
Hmmm... so something to make an enemy drop an item if you have a certain armor or weapon equipped?
Title: Reply
Post by: sacred on September 15, 2010, 11:00:14 PM
Not that. I want the item to be used, or the person equip the weapon has to attack to make it drop. And i don't want it to be applied with armors. Also, i want the force drop items and weapons when are used, they delete all of the target's drop items of the current battle.
Title: Re: [Request] Force Drop Item
Post by: The Mormegil on September 16, 2010, 05:06:09 PM
One more thing, then I can start to work on it. Do you want the item to drop instantly or wait until you defeat the enemy and gather its drops?
Title: Reply
Post by: sacred on September 17, 2010, 04:50:34 AM
It would be better to customize this option and can change it in game.
Title: Re: [Request] Force Drop Item
Post by: The Mormegil on September 17, 2010, 11:24:31 AM
Ok, I will start working today. Since I still haven't got my PC back, you will probably have to wait a bit... I hope to be able to finish it before sunday, otherwise you can ask somebody else, since I will go to LHD ad then Paris for a week...
Title: Reply
Post by: sacred on September 17, 2010, 11:47:55 AM
Well, i need to add this to the features: it should be compatible with YEM battle engine.
Title: Re: [Request] Force Drop Item
Post by: The Mormegil on September 18, 2010, 06:43:35 PM
I won't be able to finish this before tomorrow. That means that I can't do this unless you wait for Armageddon (or at least two weeks, your choice).
Title: Reply
Post by: sacred on September 18, 2010, 11:35:30 PM
Well, i will wait.
Title: Re: [Request] Force Drop Item
Post by: The Mormegil on September 29, 2010, 06:32:22 PM
Ok, all right. I have returned, but I still haven't got a PC... Just to let you know I haven't forgotten this.
Title: Re: [Request] Force Drop Item
Post by: The Mormegil on October 01, 2010, 03:50:33 PM
Ok, this SHOULD work. Probably have a few bugs, but report them and I'll try my best to fix them!
#------------------------------------------------------------------
#------------------------------------------------------------------
#                  The Mormegil's Force Drops
#                             v 1.0
#------------------------------------------------------------------
#------------------------------------------------------------------
#
# This script allows you to set some skills, weapons or items that can make an enemy
# drop an object when used (or you attack with it).
# There are two possible options: the enemy drops the item instantly and no changes
# to enemy loot is done, or the enemy changes his own drops to a new loot.
#
# NOTETAGS:
#   Skills:
#   <force drop type: x>
#   <force instant drop type: x>
#
#   Items:
#   <force drop type: x>
#   <force instant drop type: x>
#
#   Weapons:
#   <force drop type: x>
#   <force instant drop type: x>
#
# where type is "armor", "item", or "weapon", and x is the drop's id.
#
# Some notes: if you use the first option (instant drop), you can still
# nullify the final drops: just set a second option tag with 0 as the id.
# If you use the second option (change drops), you can obtain up to 2
# new objects as a loot; they will be the last two to be set up with skills
# or items. For example, skill1 can make an enemy drop an omelette, while
# item1 makes it drop eggs. If you use skill1 twice on enemyA, it will drop
# two omelettes. If you use it again, nothing will change. Say you use skill1
# three times, then item1 once: the enemy will drop an omelette and an egg.
# If you use skill1 again after that, nothing will change, but if you use it twice
# you will get two omelettes again. Savvy?
#
# Another note: the script is written for the standard battle system.
# If you are using a different battle system, turn the option below to true
# unless this battle system still uses battle messages.
# The instant drop feature calls a battle message to inform the player he has
# gained an item, so if you turn it to true it will just be added to the inventory,
# which isn't nice. You can ask a modification to the script to change this - if you do,
# just rewrite the "show_text_item_instant_drop" method.
#
#------------------------------------------------------------------
#
#     $$$$$$$$$$$$$$$ CUSTOMIZATION OPTIONS $$$$$$$$$$$$$$$$$$$$
#
# Read above for this option:

FORCE_DROPS_DIFFERENT_BATTLE_SYSTEM = false

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

#                   STOP EDITING PAST THIS POINT!
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#


$imported = {} if $imported == nil
$imported["TM_ForceDrops"] = true


class Game_Enemy < Game_Battler
 
  attr_accessor    :forced_drops
  attr_accessor    :force_drop_flag

  alias force_drop_initialize initialize
  def initialize(a, b)
    @force_drop_flag = false
    @forced_drops = []
    force_drop_initialize(a, b)
  end

  alias force_di1 drop_item1
  alias force_di2 drop_item2

  def drop_item1
    force = @forced_drops[0]
    drop = force_di1
    if @force_drop_flag
      return make_a_forced_drop(force)
    else
      return drop
    end
  end

  def drop_item2
    force = @forced_drops[1]
    drop = force_di2
    if @force_drop_flag
      return make_a_forced_drop(force)
    else
      return drop
    end
  end

  def make_a_forced_drop(item)
    item.kind = 1 if item.is_a?(Item)
    item.kind = 2 if item.is_a?(Weapon)
    item.kind = 3 if item.is_a?(Armor)
    case item.kind
    when 1
      item.item_id = item.id
    when 2
      item.weapon_id = item.id
    when 3
      item.armor_id = item.id
    end
  end

end

module RPG
  class BaseItem
    alias force_drops_in initialize
    def initialize
      force_drops_in
      @kind = 0
      @item_id = 1
      @weapon_id = 1
      @armor_id = 1
      @denominator = 1
    end
    attr_accessor   :kind
    attr_accessor   :item_id
    attr_accessor   :weapon_id
    attr_accessor   :armor_id
    attr_accessor   :denominator
  end
end

class Game_Battler

  alias force_drops_se skill_effect
  def skill_effect(user, skill)
    force_drops_se(user, skill)
    lines = skill.note.split(/[\r\n]+/)
    for line in lines
      if line =~ TheMormegil::ForceItems::Regexp::FORCE_A_DROP
        case $1.upcase
        when "ARMOR"
          drop_item = $data_armors[$2.to_i]
        when "ITEM"
          drop_item = $data_items[$2.to_i]
        when "WEAPON"
          drop_item = $data_weapons[$2.to_i]
        end
      end
      self.forced_drops.unshift(drop_item) if drop_item != nil
      self.force_drop_flag = true if drop_item != nil
    end
    for line in lines
      if line =~ TheMormegil::ForceItems::Regexp::FORCE_INSTANT_DROP
        case $1.upcase
        when "ARMOR"
          instant_drop_item = $data_armors[$2.to_i]
        when "ITEM"
          instant_drop_item = $data_items[$2.to_i]
        when "WEAPON"
          instant_drop_item = $data_weapons[$2.to_i]
        end
        $scene.fi_get_item(instant_drop_item) if $scene.is_a?(Scene_Battle)
        $scene.show_text_item_instant_drop(instant_drop_item) if $scene.is_a?(Scene_Battle)
      end
    end
  end

  alias force_drops_ie item_effect
  def item_effect(user, item)
    force_drops_ie(user, item)
    lines = item.note.split(/[\r\n]+/)
    for line in lines
      if line =~ TheMormegil::ForceItems::Regexp::FORCE_A_DROP
        case $1.upcase
        when "ARMOR"
          drop_item = $data_armors[$2.to_i]
        when "ITEM"
          drop_item = $data_items[$2.to_i]
        when "WEAPON"
          drop_item = $data_weapons[$2.to_i]
        end
      end
      self.forced_drops.unshift(drop_item) if drop_item != nil
      self.force_drop_flag = true if drop_item != nil
    end
    for line in lines
      if line =~ TheMormegil::ForceItems::Regexp::FORCE_INSTANT_DROP
        case $1.upcase
        when "ARMOR"
          instant_drop_item = $data_armors[$2.to_i]
        when "ITEM"
          instant_drop_item = $data_items[$2.to_i]
        when "WEAPON"
          instant_drop_item = $data_weapons[$2.to_i]
        end
        $scene.fi_get_item(instant_drop_item) if $scene.is_a?(Scene_Battle)
        $scene.show_text_item_instant_drop(instant_drop_item) if $scene.is_a?(Scene_Battle)
      end
    end
  end

end

class Scene_Battle < Scene_Base
  alias force_drops_eacatt execute_action_attack
  def execute_action_attack
    force_drops_eacatt
    weapons = @active_battler.weapons
    lines = []
    for weapon in weapons
      weapon_lines = weapon.note.split(/[\r\n]+/)
      lines += weapon_lines
    end
    for line in lines
      if line =~ TheMormegil::ForceItems::Regexp::FORCE_A_DROP
        case $1.upcase
        when "ARMOR"
          drop_item = $data_armors[$2.to_i]
        when "ITEM"
          drop_item = $data_items[$2.to_i]
        when "WEAPON"
          drop_item = $data_weapons[$2.to_i]
        end
      end
      for target in targets
        target.forced_drops.unshift(drop_item) if drop_item != nil
        target.force_drop_flag = true if drop_item != nil
      end
    end
    for line in lines
      if line =~ TheMormegil::ForceItems::Regexp::FORCE_INSTANT_DROP
        case $1.upcase
        when "ARMOR"
          instant_drop_item = $data_armors[$2.to_i]
        when "ITEM"
          instant_drop_item = $data_items[$2.to_i]
        when "WEAPON"
          instant_drop_item = $data_weapons[$2.to_i]
        end
        fi_get_item(instant_drop_item)
        show_text_item_instant_drop(instant_drop_item)
      end
    end
  end

  def fi_get_item(item)
    $game_party.gain_item(item, 1)
  end

  def show_text_item_instant_drop(item)
    unless FORCE_DROPS_DIFFERENT_BATTLE_SYSTEM
      text = sprintf(Vocab::ObtainItem, item.name)
      $game_message.texts.push(text)
      wait_for_message
    end
  end

end

module TheMormegil
  module ForceItems
    module Regexp
      FORCE_A_DROP = /<(?:FORCE_DROP|force\sdrop)\s*?(\w+?)\:\s*?(\d+?)>/
      FORCE_INSTANT_DROP = /<(?:FORCE_INSTANT_DROP|force\sinstant\sdrop)\s*?(\w+?)\:\s*?(\d+?)>/
    end
  end
end

Title: Re: [Request] Force Drop Item
Post by: sacred on October 03, 2010, 02:39:30 AM
A bug found. When a character attacks, it comes up with this error:

Script "Force Drop Item" line 235 NameError occurred.

undefined local variables or method 'targets' for
#<Scene_Battle:0xc0c6520>

I place the script under the Yanfly Engine Melody.
Title: Re: [Request] Force Drop Item
Post by: The Mormegil on October 03, 2010, 07:52:55 AM
Add this line between line 218 and 219.
    targets = @active_battler.action.make_targets