Ventwig

VTS-Critical Magic Casting

Aug 13th, 2013
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.10 KB | None | 0 0
  1. #============================================================================
  2. #VTS-Critical Magic Casting
  3. #By Ventwig
  4. #Version 1.1 - Jun 1 2014
  5. #For RPGMaker VX Ace
  6. #=============================================================================
  7. # Description:
  8. # This "Critical Magic Casting" script gives your spellcasters a little bonus.
  9. # through a custom formula, select spells will be able to evolve into a stronger
  10. # one before casting, enabling the caster to use the new spell at no extra cost!
  11. # Also includes specific critical rates based on both actor AND skill
  12. #==============================================================================
  13. # Compatability:
  14. # No issues so far. It's pretty unlikely unless you're using a full-out battle
  15. # changer like an ABS (though that might work)
  16. #===============================================================================
  17. # Instructions: Put in materials, above main. Simple notetags are required.
  18. #==============================================================================
  19. # Please give Credit to Ventwig if you would like to use one of my scripts!
  20. # Use it commericial or non-commercial, and feel free to tell me if you're using
  21. # it commercially!
  22. # You may edit my scripts, just don't claim as your own!
  23. #===============================================================================
  24.  
  25. #===============================================================================
  26. # Notetags!
  27. #===============================================================================
  28. # CMC = Critical Magic Cast
  29. #
  30. # <crit_skill x>
  31. #================
  32. # This is the base of it all and the only tag that's required to set up the
  33. # CMC. Put this tag into the notebox of the skill that should be used BEFORE
  34. # the CMC. Replace the x with the skillid of the new skill.
  35. #
  36. # <crit_rate x>
  37. #================
  38. # This can be used inside the formula of the CMC rate. Default is 0, so
  39. # it is not mandatory. It is used by default to increase/decrease the rate in
  40. # which a CMC will occur. A negative number will decrease it. This affects
  41. # all characters.
  42. #
  43. # <crit_act x,x,x>
  44. # <act_rate x,x,x>
  45. #================
  46. # This determines actor AND skill specific rates. Used in skill noteboxes
  47. # The first one determines which actors get specific rates.
  48. # The second one determines said rates for those actors.
  49. # They line up together, so if Eric is used in the first slot, his rate should
  50. # also be in the first slot.
  51. # This is added on top of the <crit_rate x> (unless you change the formula)
  52. # You can add as many x-s as you want
  53. # PLEASE NOTE:
  54. #  <crit_act> uses ACTOR IDs. That's the number beside the actor name!
  55. #
  56. # <acrit_rate x>
  57. #================
  58. # This works like crit_rate, except it is placed inside the actor notebox.
  59. #===============================================================================
  60.  
  61.  
  62. #===============================================================================
  63. #Changing the formula (on line 133)
  64. #===============================================================================
  65. # crit = 10 + rand(101) + a.acrit_rate + quest_skill.crit_rate + privat_rate
  66. #
  67. # This is the default formula to determine the chance for a CMC. You can work it
  68. # around like any other math problem similar to the skill formula in the database.
  69. # After the formula, if "crit" is equal to or greater than 100, a CMC will occur.
  70.  
  71. # Here are some major components:      
  72. # [crit = ] leave this be. It is required for the script to work
  73. # [15/number] this adds to the chance for a CMC.
  74. # [rand(101)] a random number between 0-100. The number you use is NOT included
  75. # [a.luk/50] like in the skill formula. Be careful when using luck as it gets pretty
  76. #            high at later levels (200+ for default thief class)
  77. # [a.acrit_rate] accesses the notetag above with the same name. def 0
  78. # [quest_skill.crit_rate] accesses the notetag above with the same name. def 0
  79. # [a.cri*100] this isn't in the formula but incase you want it. This gets the
  80. #              actor's critical hit rate. By default, it's 0.04 so multiply it
  81. #              by 100 to make it worth something.
  82. # [private_rate] refers to the note tags <crit_act> and <act_rate>
  83. #                make sure to include this for those to work!
  84. #===============================================================================
  85. # If you're curious as to what levels you're getting each skill, place
  86. # p(a.name)
  87. # p(a.crit)
  88. # under the formula. It will display the value of "crit" in the console
  89. #==============================================================================
  90.  
  91. module VTS_CRITSKILL
  92.   CRIT_TEXT = "Critical Magic Cast!"
  93.   #The text said when announcing the new change
  94. end
  95. #############################################################################
  96.  
  97. #===============================================================================
  98. #DON'T TOUCH HERE!
  99. #===============================================================================
  100.  
  101. module RPG
  102.   class BaseItem
  103.     def crit_skill
  104.       if @crit_skill.nil?
  105.         if @note =~ /<crit_skill (.*)>/i
  106.           @crit_skill= $1.to_i
  107.         else
  108.           @crit_skill = 0
  109.         end
  110.       end
  111.       @crit_skill
  112.     end
  113.     def crit_rate
  114.       if @crit_rate.nil?
  115.         if @note =~ /<crit_rate (.*)>/i
  116.           @crit_rate= $1.to_i
  117.         else
  118.           @crit_rate = 0
  119.         end
  120.       end
  121.       @crit_rate
  122.     end
  123.     def crit_act
  124.       if @crit_act.nil?
  125.         if @note =~ /<crit_act (.*)>/i
  126.           @crit_act = $1.split(",")
  127.         else
  128.           @crit_act =  []
  129.         end
  130.       end
  131.       @crit_act
  132.     end
  133.     def act_rate
  134.       if @act_rate.nil?
  135.         if @note =~ /<act_rate (.*)>/i
  136.           @act_rate = $1.split(",")
  137.         else
  138.           @act_rate =  []
  139.         end
  140.       end
  141.       @act_rate
  142.     end
  143.   end
  144.  
  145.   class Actor
  146.     def acrit_rate
  147.       if @acrit_rate.nil?
  148.         if @note =~ /<acrit_rate (.*)>/i
  149.           @acrit_rate= $1.to_i
  150.         else
  151.           @acrit_rate = 0
  152.         end
  153.       end
  154.       @acrit_rate
  155.     end
  156.   end
  157. end
  158.  
  159. class Game_Action
  160.   attr_accessor :old_skill
  161. end
  162.  
  163. class Game_Actor < Game_Battler
  164.   def acrit_rate
  165.     return actor.acrit_rate
  166.   end
  167.   def actor_id
  168.      return @actor_id
  169.   end
  170. end
  171.  
  172. class Game_Battler < Game_BattlerBase
  173.   def crit_new_skill(a)
  174.     return unless current_action.item.is_a?(RPG::Skill)
  175.     quest_skill = current_action.item
  176.    
  177.     if a.actor? == true
  178.       rate_index = quest_skill.crit_act.index(a.actor_id.to_s)
  179.       if rate_index != nil
  180.         private_rate = quest_skill.act_rate[rate_index].to_i
  181.       else
  182.         rate_index = 0
  183.         private_rate = 0
  184.       end
  185.     else
  186.       rate_index = 0
  187.       private_rate = 0
  188.     end
  189.    
  190.     if quest_skill.crit_skill != 0
  191.       #====================F=O=R=M=U=L=A===================================
  192.         crit = 10 + rand(101) + a.acrit_rate + quest_skill.crit_rate + private_rate
  193.       #====================F=O=R=M=U=L=A===================================
  194.         if crit >= 100
  195.           current_action.set_skill(quest_skill.crit_skill)
  196.           current_action.old_skill = quest_skill
  197.           current_action.item.mp_cost = current_action.old_skill.mp_cost
  198.         end
  199.     end
  200.   end
  201. end # Game_Battler
  202.  
  203. class Window_BattleLog < Window_Selectable
  204.   alias vts_critskill_display_use_item display_use_item
  205.   def display_use_item(subject, item)
  206.     if item.is_a?(RPG::Skill)
  207.       if subject.current_action.old_skill != nil
  208.         name = subject.name
  209.         change_text = VTS_CRITSKILL::CRIT_TEXT
  210.         skill_name = item.name + '!'
  211.         use_name = subject.current_action.old_skill.message1
  212.         old_skill_text = name + use_name
  213.         add_text(old_skill_text)
  214.         wait
  215.         new_skill_text = change_text
  216.         add_text(new_skill_text)
  217.         wait
  218.       end
  219.     end    
  220.     vts_critskill_display_use_item(subject, item)
  221.     subject.current_action.old_skill = nil
  222.   end
  223. end
  224.  
  225. class Scene_Battle < Scene_Base
  226.   alias scene_battle_use_crit_new use_item
  227.   def use_item
  228.     @subject.crit_new_skill(@subject)
  229.     scene_battle_use_crit_new
  230.   end
  231.  
  232. end # Scene_Battle
  233. #End of Script
Advertisement
Add Comment
Please, Sign In to add comment