IceDragon200

[IEX2]Randomize Battle Skills[VX]

Mar 25th, 2012
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.53 KB | None | 0 0
  1. #==============================================================================#
  2. # ● IEX2 - Randomize Battle Skills [VX]
  3. #==============================================================================#
  4. # // • Created By    : IceDragon
  5. # // • Data Created  : 03/25/2012
  6. # // • Data Modified : 03/25/2012
  7. # // • Version       : 1.0
  8. # // • RGSS.design   : 2 (VX-Default)
  9. #==============================================================================#
  10. # ● Installation
  11. #     Below
  12. #       Material
  13. #       Scripts that make changes to actor.skills
  14. #     Above
  15. #       Main
  16. #==============================================================================#
  17. # ● How to Modify
  18. #    set_rand_skills(n=4)
  19. #     In the Game_Actor class, set_rand_skills, creates an array of 'n' size
  20. #     And selects skills until its full (there will be no duplicates)
  21. #     If the number of available skills falls under the array size, it will
  22. #     be ignored.
  23. #     If you wish to change the number of random skills, simply change the value
  24. #     of 'n'
  25. #
  26. #    reset_rand_turn_count()
  27. #     This will set the number of turns till the next randomization
  28. #     By default:
  29. #      @rand_turn_count = 3 + rand(2)
  30. #      The number of turns will be 3 or 4
  31. #==============================================================================#
  32. # ● Change Log
  33. #     ♣ 03/25/2012 V1.0
  34. #         Completed Script
  35. #==============================================================================#
  36. # // 1.9 Functions
  37. class Array
  38.   def shuffle()
  39.     self.sort_by{rand}
  40.   end unless(method_defined?(:shuffle))
  41.   def shuffle!()
  42.     self.replace(shuffle())
  43.   end unless(method_defined?(:shuffle!))
  44.   def pick()
  45.     self[rand(self.size)]
  46.   end unless(method_defined?(:pick))
  47.   def pick!()
  48.     self.delete(pick())
  49.   end unless(method_defined?(:pick!))
  50. end
  51. class Integer
  52.   def pred()
  53.     self - 1
  54.   end unless method_defined?(:pred)  
  55.   def succ()
  56.     self + 1
  57.   end unless method_defined?(:succ)  
  58. end  
  59. # // VX
  60. class Game_Battler
  61.   def all_skills()
  62.     []
  63.   end
  64.   def random_skills()
  65.     set_rand_skills() unless(@random_skills)
  66.     @random_skills
  67.   end  
  68.   def set_rand_skills(n=4)
  69.     sks = all_skills().compact().collect{|s|s.id}
  70.     (@random_skills ||=[]).replace(Array.new(n){sks.pick!()}.compact)
  71.   end
  72.   def randomize_skills?()
  73.     @randomize_skills = true if(@randomize_skills.nil?())
  74.     @randomize_skills
  75.   end
  76.   attr_writer :randomize_skills
  77.   def rand_turn_count()
  78.     reset_rand_turn_count() unless(@rand_turn_count)
  79.     @rand_turn_count
  80.   end  
  81.   def reset_rand_turn_count()
  82.     @rand_turn_count = 3 + rand(2)
  83.   end  
  84.   def at_turn_end()
  85.     @rand_turn_count = rand_turn_count.pred
  86.     if(@rand_turn_count <= 0)
  87.       set_rand_skills() if(randomize_skills?())
  88.       reset_rand_turn_count()
  89.     end
  90.   end  
  91. end
  92. class Game_Actor
  93.   alias :all_skills :skills unless($@)
  94.   def skills()
  95.     $game_temp.in_battle ? random_skills.collect{|id|$data_skills[id]} : all_skills()
  96.   end
  97. end  
  98. class Game_Unit
  99.   def at_turn_end()
  100.     members.each{|m|m.at_turn_end()}
  101.   end  
  102. end  
  103. class Scene_Battle
  104.   alias :at_turn_end :turn_end unless($@)
  105.   def turn_end(*args,&block)
  106.     $game_party.at_turn_end()
  107.     $game_troop.at_turn_end()
  108.     at_turn_end(*args,&block)
  109.   end  
  110. end  
  111. #=■==========================================================================■=#
  112. #                           // ● End of File ● //                              #
  113. #=■==========================================================================■=#
Advertisement
Add Comment
Please, Sign In to add comment