Advertisement
Vlue

Extra Enemy Drops

Apr 15th, 2014
1,614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.02 KB | None | 0 0
  1. #Extra Enemy Drops v1.0
  2. #----------#
  3. #Features: Let's you set, via notes, more than just three item drops
  4. #           from an enemy. Yay!
  5. #
  6. #Usage:    Plug and play, customize as needed
  7. #        
  8. #         Enemy Notetags:
  9. #          <DROP type id rate>
  10. #           type is 1 for item, 2 for weapon, 3 for armor
  11. #           id is the id of the item
  12. #           rate is the 1/rate of the item, 20 would be 1/20 chance
  13. #
  14. #          A weapon of id 3 that drops 1 out of 5 times would be:
  15. #           <DROP 2 3 5>
  16. #
  17. #----------#
  18. #-- Script by: V.M of D.T
  19. #
  20. #- Questions or comments can be:
  21. #    given by email: sumptuaryspade@live.ca
  22. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  23. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  24. #
  25. #- Free to use in any project with credit given, donations always welcome!
  26.  
  27. #Maximum number of items that can drop from one enemy in a battle
  28. MAX_ENEMY_DROPS = 3
  29.  
  30. class RPG::Enemy
  31.   def add_drop(type,id,rate)
  32.     @drop_items.push(RPG::Enemy::DropItem.new)
  33.     @drop_items[-1].kind = type
  34.     @drop_items[-1].data_id = id
  35.     @drop_items[-1].denominator = rate
  36.   end
  37.   def add_drops
  38.     snote = self.note.clone
  39.     while snote.include?("<DROP ")
  40.       snote =~ /<DROP (\d+) (\d+) (\d+)>/
  41.       add_drop($1.to_i,$2.to_i,$3.to_i)
  42.       snote[snote.index("<DROP")] = "N"
  43.     end
  44.   end
  45. end
  46.  
  47. module DataManager
  48.   def self.load_database
  49.     if $BTEST
  50.       load_battle_test_database
  51.     else
  52.       load_normal_database
  53.       check_player_location
  54.     end
  55.     add_enemy_drops
  56.   end
  57.   def self.add_enemy_drops
  58.     $data_enemies.each do |enemy|
  59.       next if enemy.nil?
  60.       enemy.add_drops
  61.     end
  62.   end
  63. end
  64.  
  65. class Game_Enemy
  66.   def make_drop_items
  67.     iter = 0
  68.     enemy.drop_items.inject([]) do |r, di|
  69.       if di.kind > 0 && rand * di.denominator < drop_item_rate && iter < MAX_ENEMY_DROPS
  70.         iter += 1
  71.         r.push(item_object(di.kind, di.data_id))
  72.       else
  73.         r
  74.       end
  75.     end
  76.   end
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement