Advertisement
Vendily

Wild Drop Items [v21]

Aug 14th, 2024 (edited)
1,301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.60 KB | None | 0 0
  1. #===============================================================================
  2. # Wild Drop Items - By Vendily [v21]
  3. #===============================================================================
  4. # This script adds in Wild Drop Items, allowing for Wild Pokémon to drop
  5. #  specially defined items in the PBS upon fainting.
  6. # They do not have to be the same as the items Wild Pokémon might generate with.
  7. #===============================================================================
  8. # The script is plug and play, you just need to add in the PBS information
  9. #  `WildDropCommon`, `WildDropUncommon`, and `WildDropRare`, used in the same
  10. #  way as the `WildItem` version. (You don't have to define all three.)
  11. # The base rate is `[50,5,1]`, but if all three properties are the same then it
  12. #  is a 100% rate.
  13. # Check the `def pbFaint` here if you wish to modify the mechanics further
  14. #  or change the windowskin colour to dark mode.
  15. #===============================================================================
  16. PluginManager.register({
  17.   :name    => "Wild Drop Items",
  18.   :version => "1.0",
  19.   :essentials => "21.1",
  20.   :credits => "Vendily"
  21. })
  22.  
  23.  
  24. module GameData
  25.   class Species
  26.     attr_reader :wild_drop_common
  27.     attr_reader :wild_drop_uncommon
  28.     attr_reader :wild_drop_rare
  29.    
  30.     class << self
  31.       alias_method :wild_drop_schema, :schema
  32.       def schema(compiling_forms = false)
  33.         ret = wild_drop_schema(compiling_forms)
  34.         ret["WildDropCommon"]   = [:wild_drop_common,   "*e", :Item]
  35.         ret["WildDropUncommon"] = [:wild_drop_uncommon, "*e", :Item]
  36.         ret["WildDropRare"]     = [:wild_drop_rare,     "*e", :Item]
  37.         return ret
  38.       end
  39.      
  40.       alias_method :wild_drop_editor_properties, :editor_properties
  41.       def editor_properties
  42.         ret = wild_drop_editor_properties
  43.         ret.push(["WildDropCommon",    GameDataPoolProperty.new(:Item),    _INTL("Item(s) commonly dropped by wild Pokémon of this species.")])
  44.         ret.push(["WildDropUncommon",  GameDataPoolProperty.new(:Item),    _INTL("Item(s) uncommonly dropped by wild Pokémon of this species.")])
  45.         ret.push(["WildDropRare",      GameDataPoolProperty.new(:Item),    _INTL("Item(s) rarely dropped by wild Pokémon of this species.")])
  46.         return ret
  47.       end
  48.     end
  49.     alias wild_drop_initialize initialize
  50.     def initialize(hash)
  51.       wild_drop_initialize(hash)
  52.       @wild_drop_common   = hash[:wild_drop_common]   || []
  53.       @wild_drop_uncommon = hash[:wild_drop_uncommon] || []
  54.       @wild_drop_rare     = hash[:wild_drop_rare]     || []
  55.     end
  56.   end
  57. end
  58.  
  59. class Pokemon
  60.   # @return [Array<Array<Symbol>>] the items this species can drop in the wild
  61.   def wildDropItems
  62.     sp_data = species_data
  63.     return [sp_data.wild_drop_common, sp_data.wild_drop_uncommon, sp_data.wild_drop_rare]
  64.   end
  65. end
  66.  
  67. class Battle::Battler
  68.   alias wild_drop_pbFaint pbFaint
  69.   def pbFaint(showMessage = true)
  70.     old_fainted = @fainted
  71.     wild_drop_pbFaint(showMessage)
  72.     # we don't drop items if no message will show
  73.     return unless showMessage
  74.     # must be a wild battle, and this is a wild mon
  75.     return unless @battle.wildBattle? && opposes?
  76.     # must be fainted, and it can't already have been fainted
  77.     return unless @fainted && old_fainted != @fainted
  78.     # we need a pokemon, and this can't be a non-standard battle
  79.     return unless @pokemon && @battle.internalBattle
  80.     items = @pokemon.wildDropItems
  81.     chances = [50, 5, 1]
  82.     itemrnd = rand(100)
  83.     item = nil
  84.     qty = 1
  85.     if (items[0] == items[1] && items[1] == items[2]) || itemrnd < chances[0]
  86.       item = items[0].sample
  87.     elsif itemrnd < (chances[0] + chances[1])
  88.       item = items[1].sample
  89.     elsif itemrnd < (chances[0] + chances[1] + chances[2])
  90.       item = items[2].sample
  91.     end
  92.     return unless item
  93.     # if we have an item and sucessfully added it
  94.     old_quantity_items = $bag.quantity(item)
  95.     $bag.add(item,qty)
  96.     added_items = $bag.quantity(item) - old_quantity_items
  97.     if added_items>0
  98.       item_data = GameData::Item.get(item)
  99.       itemname = (added_items > 1) ? item_data.portion_name_plural : item_data.portion_name
  100.       pocket = item_data.pocket
  101.       # change the false to true if your battle window skin is dark
  102.       colour_tag = getSkinColor(nil, 1, false)
  103.       @battle.pbDisplay(_INTL("{1} dropped {2}{3} x{4}</c3>!",pbThis,colour_tag,itemname,added_items))
  104.       @battle.pbDisplay(_INTL("You put the {1} in\nyour Bag's <icon=bagPocket{2}>{3}{4}</c3> pocket.",
  105.                     itemname, pocket, colour_tag, PokemonBag.pocket_names[pocket - 1]))
  106.     end
  107.   end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement