Jump to content
Sign in to follow this  
eshra

Alternate Drops

Recommended Posts

Modern Algebra said he was going to add switches to his Drop Options script but he hasn't done it yet. This script was written in response to a request. I'm surprised this hasn't popped up yet. If it has though and I have just failed to find it please lock this.

 

Introduction

 

Allows enemies to drop additional items when certain switches are turned on.

 

Features

 

Use notetags to make enemies drop alternate items when a switch is turned on.

 

Screenshots

 

 

An example note tag

dropswitches.png

(causes item 1 and weapon 1 to drop 100% and 50% of the time respectively when switch 1 is on and causes armor 1 to drop 100% of the time when switch 2 is on)

 

 

 

How to use

 

To use this script just add a note tag to the enemy you want to drop an alternate item the notetag should have the following form

 

<when number1 keyword number2 1/number3>

 

number1 should be replaced with the id of the switch you want to be on to activate the alternate drop.

keyword should be replaced with either the word item, armor, or weapon

number2 should be replaced with the id of the item,armor, or weapon that you want to drop

number3 should be replaced with denominator of the fraction 1/x representing the chance of the drop happening

 

Demo

Demo

 

Script

 

 

#Alternate Drops on Encounters - Eshra

#Allows enemies to drop alternate items, weapons, or armor based on switches that
#are active when a battle starts.

#How to use:
#Place a notetag in the note box for the enemy that you want to gain an alternate
#drop.
#The note tag should look like: <when "number" "keyword" "number" 1/"number">
#The keyword can be either item, weapon, or armor. Wherever "number" appears,
#replace that with an actual number.
#The first number is the id number that corresponds to the switch that must be on
#for the alternate drop to show up. Then comes a space followed by either the word
#item, weapon, or armor. After the keyword is another number. This number is the
#id number of the item, weapon, or armor that you want to have as an alternate drop.
#the last value, i.e. the number that appears after "1/" is the denominator of the
#fraction that represents the chance of that item dropping.

#Example
#If I want an enemy to drop item number five 25% of the time when switch 73 is on
#and I also want that enemy to drop armor 16 5% of the time when switch 89 is on
#I would make a notetag like this for that enemy:
#<when 73 item 5 1/4>
#<when 89 armor 16 1/20>

#note capitalization doesn't matter

#Bug fixes

#- fixed a problem where I was adding the same item to the drop_items list after
#  each battle even if the item had already been added

#Regular Expressions
module ENCOUNTER_CHANGE
 module RE
	  ITEM = /<when (\d+) item (\d+) 1\/(\d+)>/i
	  WEAPON = /<when (\d+) WEAPON (\d+) 1\/(\d+)>/i
	  ARMOR = /<when (\d+) ARMOR (\d+) 1\/(\d+)>/i
 end
end

module DataManager
 #--------------------------------------------------------------------------
 # alias method: load_database
 #--------------------------------------------------------------------------
 class <<self; alias load_database_encounter_change load_database; end
 def self.load_database
	$alt_enemy_drops ||= {}

	load_database_encounter_change
	load_notetags_encounter_change
 end

 #--------------------------------------------------------------------------
 # new method: load_notetags_abe
 #--------------------------------------------------------------------------
 def self.load_notetags_encounter_change
	group = $data_enemies
	  for obj in group
			next if obj.nil?
			obj.load_notetags_encounter_change
	end
 end
end # DataManager


class RPG::Enemy < RPG::BaseItem
 def load_notetags_encounter_change
	$alt_enemy_drops[id] = Hash.new
	self.note.split(/[\r\n]+/).each { |line|
	  next unless line != nil# && $1 != nil
	  case line
	  when ENCOUNTER_CHANGE::RE::ITEM
			add_alternate_drop(1,$1.to_i, $2.to_i, $3.to_i)
	  when ENCOUNTER_CHANGE::RE::WEAPON
			add_alternate_drop(2,$1.to_i, $2.to_i,$3.to_i)
	  when ENCOUNTER_CHANGE::RE::ARMOR
			add_alternate_drop(3,$1.to_i, $2.to_i,$3.to_i)  
	  end
	} # self.note.split
 end

 def add_alternate_drop(type, switch, base_item, chance)
	if !$alt_enemy_drops[id][type]
	  $alt_enemy_drops[id][type] = {}
	end

	if !$alt_enemy_drops[id][type][switch]
	  $alt_enemy_drops[id][type][switch] = []
	end

	$alt_enemy_drops[id][type][switch].push([base_item, chance])
 end

 def delete_alt_drop_item(item_id, kind, denominator, delete = true)
	count = 0
	@drop_items.each{ |drop_item|
	  same_item = drop_item.data_id == item_id && drop_item.kind == kind
	  same_item = same_item && drop_item.denominator == denominator
	  if  same_item
			return true if !delete
			@drop_items.delete_at(count)
			count -= 1
	  end
	  count += 1
	}
return false
 end
end

module BattleManager
 #--------------------------------------------------------------------------
 # * Setup
 #--------------------------------------------------------------------------
 class <<self; alias setup_encounter_change setup; end
 def self.setup(troop_id, can_escape = true, can_lose = false)
	troop_contains(troop_id)
	setup_encounter_change(troop_id, can_escape, can_lose)
 end

 def self.troop_contains(troop_id)

	troop = $data_troops[troop_id]
	$alt_items ||= {}

	loaded_members = []
	troop.members.each{ |member|
	enemy_id = member.enemy_id
	 if loaded_members.include?(enemy_id)
	   next
	 end
	 loaded_members.push(enemy_id)

	  type_keys = $alt_enemy_drops[member.enemy_id].keys
	  type_keys.each{ |type|

		switch_keys = $alt_enemy_drops[member.enemy_id][type].keys
		switch_keys.each{ |switch|

		  if $game_switches[switch]
			$alt_enemy_drops[member.enemy_id][type][switch].each{ |item_data|

			  alternate_item = RPG::Enemy::DropItem.new
			  alternate_item.kind = type
			  alternate_item.data_id = item_data[0]
			  alternate_item.denominator = item_data[1]
			  if $data_enemies[member.enemy_id].delete_alt_drop_item(item_data[0], type, item_data[1], false)
				#item was already in enemy.drop_items so skip it

				next
			  end
			  $data_enemies[member.enemy_id].drop_items.push(alternate_item)
			}
		  else
			$alt_enemy_drops[member.enemy_id][type][switch].each{ |item_data|
			  $data_enemies[member.enemy_id].delete_alt_drop_item(item_data[0], type, item_data[1])
			}
		  end #end if $game_switches[switch]
		} #end switch_keys.each
	  } #end type_keys.each
	} #end troop.each
 end #end self.troop_contains(troop_id)
end #end BattleManager

 

 

 

Credit and Thanks

Eshra

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted