Consume MP in combat by all actions

This script can make that when you execute any actions in combat
your MP is consumed based in a large number of options (actors, classes, equipment,
skill or item used, fixed value and event variables) like for example in Final Fantasy: The Four Heroes
of Light.

  1.  
  2. #==============================================================================
  3. # Consume MP in combat by all actions
  4. # By gerkrt/gerrtunk, sournote103(idea)
  5. # Version: 2.1
  6. # License: GPL, credits
  7. # Date: 16/05/2011
  8. # For the latests updates or bugs fixes of this script check here:
  9. # http://usuarios.multimania.es/kisap/english_list.html
  10. #==============================================================================
  11.  
  12. =begin
  13.  
  14. ---------INTRODUCTION----------
  15.  
  16. This script can make that when you execute any actions in combat
  17. your MP is consumed based in a large number of options (actors, classes, equipment,
  18. skill or item used, fixed value and event variables) like for example in Final Fantasy: The Four Heroes
  19. of Light.
  20.  
  21. --------INSTRUCTIONS------------
  22.  
  23. Exist 6 actions with his own identificative code to use:
  24. :attack
  25. :defend
  26. :escape
  27. :skill
  28. :item
  29. :general
  30.  
  31. General is a general default configurationthats applied always, when you are doing
  32. any action.
  33.  
  34. You can configure how many and how will be reduced the MP based in these options
  35. that use these codes:
  36.  
  37. :actors
  38. :classes
  39. :weapons
  40. :shields
  41. :helmets
  42. :armors
  43. :accesories
  44. :variables
  45. :fixed
  46.  
  47. Plus these two that are used only when using a skill or item:
  48.  
  49. :skill
  50. :item
  51.  
  52. In each of these configuration lists, you will put what actor id, or class id,etc
  53. (the id is the value in the database) modify that action and how they do that.
  54. The program sums all the values of the list each time and independently, so you
  55. can have a armor that sums to attack and item, but reduces defense, and does nothing
  56. with the rest, for example, and make other things also.
  57.  
  58.  
  59. You dont have to use all of them anyway.
  60.  
  61. This is a sample configuration, that you have to add anytime you want to configure
  62. any of that options.
  63.  
  64. id of X(armor, helmet, actor...) => [type(+ or %), value(normal or decimal)],
  65. 55 => [2, 0.50],
  66.  
  67. Each configuration can work in two ways:
  68.  
  69. If the first value is 1: it will add to the actual sp the value you put
  70. If the value is 2, it will apply a % based changue, so if you write 0.50 for
  71. example it will be reduced to 50% and 1.50 150%.
  72.  
  73. Note that you can make negative things using negative numbers, but it will never
  74. reduce beyond 0 or 1%.
  75.  
  76. For configuring you only to have to add each time:
  77. 55 => [2, 0.50],
  78. Where 55 is the id of the actor, weapon or armor or whatever, 2 the type to use,
  79. and 0.50 or 50 the value to use.
  80.  
  81. Note that in :variables the code is different because the value is in the event
  82. variable: 55 => [2], 2 is the type. Also when you are using in % the event
  83. variables its values will be divided by 100, so it became decimals compatible with
  84. the rest. If var 55 was 25, it will be 0.25.
  85.  
  86. :fixed is different also, it add a value based only on the action and nothing more,
  87. so you dont need the id, but it use the normal way of + or %.
  88. :fixed => [1, 40]
  89.  
  90. Finally, first is summed the normal value, and later applied the % value. They
  91. way the formula works it sums all the % and normals values before suming nothing.
  92.  
  93. Also the skill reduces the sp in the normal way first, and later using this script.
  94.  
  95. ----SYNTAX NOTES----
  96.   Actions = {
  97.  
  98.     :attack => { # Attack config
  99.         :weapons => {
  100.           1 => [1, -150],
  101.           2 => [2, 0.50]
  102.         },
  103.        
  104.         :armors => {
  105.           13 => [1, -150],
  106.           2 => [2, 0.50]
  107.         },
  108.        
  109.         :shields => {
  110.           1 => [2, 0.50]
  111.         },
  112.        
  113.         :fixed => [1, 40]
  114.          
  115.     }, # End of attack config
  116.    
  117. To add new option for attack, you have to include it before the last } with the ,
  118. that makrs the end of any action, like defense or item too.
  119.  
  120. To add a new option like this:
  121.  
  122.        :helmets => {
  123.           1 => [2, 0.50]
  124.         },
  125.        
  126.        
  127. Do this:
  128.     :attack => { # Attack config
  129.         :weapons => {
  130.           1 => [1, -150],
  131.           2 => [2, 0.50]
  132.         },
  133.        
  134.         :armors => {
  135.           13 => [1, -150],
  136.           2 => [2, 0.50]
  137.         },
  138.        
  139.         :shields => {
  140.           1 => [2, 0.50]
  141.         },
  142.        
  143.        :helmets => {
  144.           1 => [2, 0.50]
  145.         },
  146.  
  147.         :fixed => [1, 40]
  148.          
  149.     }, # End of attack config
  150.    
  151. So the the option have a , at the end of the {}
  152. To include effects for each id, you have to add a new line each time, adding
  153. a coma at the end. Note that each id have to be unique.
  154.  
  155.           id,    type, effect
  156.        :helmets => {
  157.           1 => [2, 0.50],
  158.           2 => [2, 0.50],
  159.           3 => [2, 0.50]
  160.         },
  161.  
  162. =end
  163.  
  164. module Wep
  165.  
  166.   Actions = { # Actions start
  167.  
  168.  
  169.     :attack => { # Attack config
  170.         :weapons => {
  171.           1 => [1, -150],
  172.           2 => [2, 0.50]
  173.         },
  174.        
  175.         :armors => {
  176.           13 => [1, -150],
  177.           2 => [2, 0.50]
  178.         },
  179.        
  180.         :shields => {
  181.           1 => [2, 0.50]
  182.         },
  183.        
  184.         :fixed => [1, 40]
  185.          
  186.     }, # End of attack config
  187.    
  188.     :defense => { # Defense config
  189.         :weapons => {
  190.           1 => [1, -150],
  191.           2 => [2, 0.50]
  192.         },
  193.        
  194.         :armors => {
  195.           13 => [1, -150],
  196.           2 => [2, 0.50]
  197.         },
  198.        
  199.         :shields => {
  200.           1 => [2, 0.50]
  201.         },
  202.        
  203.         :actors => {
  204.           1 => [1, -150],
  205.           2 => [2, 0.50]
  206.         },
  207.        
  208.         :classes => {
  209.           1 => [1, -150],
  210.           2 => [2, 0.50]
  211.         },
  212.        
  213.         :variables => {
  214.           1 => [1],
  215.           2 => [2]
  216.         },
  217.        
  218.         :fixed => [1, 40]
  219.          
  220.     },# End of defend config
  221.  
  222.    
  223.     :escape => {# Escape config
  224.          
  225.     },# End of escape config
  226.    
  227.    
  228.     :item => {# Item config
  229.          
  230.     },# End of item config
  231.    
  232.    
  233.     :skill => {# Skill config
  234.          
  235.     },# End of skill config
  236.    
  237.    
  238.     :general => {# General config
  239.         :actors => {
  240.           1 => [2, 1.0],
  241.           2 => [2, 1.50]
  242.         },
  243.        
  244.         :classes => {
  245.           4 => [1, -150],
  246.           2 => [2, 1.50]
  247.         }
  248.          
  249.     },  # End of general config
  250.  
  251.   } # End of action
  252.  
  253.  
  254.  
  255.   # 6 accions
  256.   # iteres segons el codi,sumant tot, i executant segons el subcodi, i rula be
  257.   # hiperfacil!
  258.  
  259.  
  260.   # fer que lo de accions usi codi dels hashes, hipersimple aleshores
  261.   # tu pases :defend i amb aixo, extreu de un hash de acciones, la bona, i ale
  262.   def self.test(action_type, actor, extra=false)
  263.     v = 0
  264.     r = 0.0
  265.     #actor.sp = 24
  266.    
  267.     # Sum the desired action
  268.     for key, arr  in Actions[action_type] # + Actions[:general]
  269.      #p key, arr
  270.       # Set id of the item or whatever based in key used. Make needed checks.
  271.       if key == :weapons and actor.weapon_id != 0
  272.         id = actor.weapon_id
  273.       elsif key == :shields and actor.armor1_id != 0
  274.         id = actor.armor1_id
  275.       elsif key == :helmets and actor.armor2_id != 0
  276.         id = actor.armor2_id
  277.       elsif key == :armors and actor.armor3_id != 0
  278.         id = actor.armor3_id
  279.       elsif key == :accesories and actor.armor4_id != 0
  280.         id = actor.armor4_id
  281.       elsif key == :actors
  282.         id = actor.actor_id
  283.       elsif key == :classes
  284.         id = actor.class_id
  285.       elsif key == :items
  286.         id = extra
  287.       elsif key == :skills
  288.         id = extra
  289.       elsif key == :fixed
  290.           if arr[0] == 1
  291.              v += arr[1]
  292.           else
  293.              r += arr[1]
  294.           end
  295.           next
  296.       elsif key == :variables
  297.         # If variables, iterate in subarray
  298.         for key2, val in arr
  299.           #p key, val
  300.           if val[0] == 1
  301.            
  302.              v += $game_variables[key2]
  303.              #p 'var v', v
  304.           else
  305.            
  306.              r += ($game_variables[key2].to_f / 100)
  307.              #p 'var r', r, ($game_variables[key2].to_f / 100), key2, $game_variables[key2]
  308.           end
  309.         end
  310.         next
  311.       else
  312.         next
  313.       end
  314.      
  315.       #p arr, id
  316.       # Each time check if value exist and extract it
  317.       if arr[id] != nil
  318.        
  319.           if arr[id][0] == 1
  320.              v += arr[id][1]
  321.           else
  322.              r += arr[id][1]
  323.           end
  324.           #p 'c', v, r
  325.       end
  326.  
  327.     end
  328.    
  329.     # Sum the general option always
  330.     for key, arr  in Actions[:general]
  331.      #p key, arr
  332.       # Set id of the item or whatever based in key used. Make needed checks.
  333.       if key == :weapons and actor.weapon_id != 0
  334.         id = actor.weapon_id
  335.       elsif key == :shields and actor.armor1_id != 0
  336.         id = actor.armor1_id
  337.       elsif key == :helmets and actor.armor2_id != 0
  338.         id = actor.armor2_id
  339.       elsif key == :armors and actor.armor3_id != 0
  340.         id = actor.armor3_id
  341.       elsif key == :accesories and actor.armor4_id != 0
  342.         id = actor.armor4_id
  343.       elsif key == :actors
  344.         id = actor.actor_id
  345.       elsif key == :classes
  346.         id = actor.class_id
  347.       elsif key == :items
  348.         id = extra
  349.       elsif key == :skills
  350.         id = extra
  351.       elsif key == :variables
  352.         # If variables, iterate in subarray
  353.         for key2, val in arr
  354.           #p key, val
  355.           if val[0] == 1
  356.            
  357.              v += $game_variables[key2]
  358.              #p 'var v', v
  359.           else
  360.            
  361.              r += ($game_variables[key2].to_f / 100)
  362.              #p 'var r', r, ($game_variables[key2].to_f / 100), key2, $game_variables[key2]
  363.           end
  364.         end
  365.         next
  366.       else
  367.         next
  368.       end
  369.      
  370.       #p arr, id
  371.       # Each time check if value exist and extract it
  372.       if arr[id] != nil
  373.        
  374.           if arr[id][0] == 1
  375.              v += arr[id][1]
  376.           else
  377.              r += arr[id][1]
  378.           end
  379.           #p 'c', v, r
  380.       end
  381.  
  382.     end
  383.    
  384.     #p 'valfin', v, r
  385.    
  386.      # Reduce actor sp
  387.      #p actor.sp
  388.    
  389.      actor.sp= actor.sp + v
  390.      actor.sp= actor.sp * (1.0 + r).to_i
  391.      #actor.sp= actor.sp.to_i
  392.    
  393.      #actor.sp = 9999 if actor.sp > 9999
  394.      #p 'final', actor.sp
  395.      # comprova q r no sigui negatiu
  396.    end
  397.  
  398.        
  399.  
  400. end
  401.  
  402. class Scene_Battle
  403.   #--------------------------------------------------------------------------
  404.   # * Frame Update (party command phase: escape)
  405.   #--------------------------------------------------------------------------
  406.   def update_phase2_escape
  407.    
  408.     # Calculate enemy agility average
  409.     enemies_agi = 0
  410.     enemies_number = 0
  411.     for enemy in $game_troop.enemies
  412.       if enemy.exist?
  413.         enemies_agi += enemy.agi
  414.         enemies_number += 1
  415.       end
  416.     end
  417.     if enemies_number > 0
  418.       enemies_agi /= enemies_number
  419.     end
  420.     # Calculate actor agility average
  421.     actors_agi = 0
  422.     actors_number = 0
  423.     for actor in $game_party.actors
  424.       if actor.exist?
  425.         actors_agi += actor.agi
  426.         actors_number += 1
  427.         Wep.test (:escape, actor)
  428.       end
  429.     end
  430.     if actors_number > 0
  431.       actors_agi /= actors_number
  432.     end
  433.     # Determine if escape is successful
  434.     success = rand(100) < 50 * actors_agi / enemies_agi
  435.     # If escape is successful
  436.     if success
  437.       # Play escape SE
  438.       $game_system.se_play($data_system.escape_se)
  439.       # Return to BGM before battle started
  440.       $game_system.bgm_play($game_temp.map_bgm)
  441.       # Battle ends
  442.       battle_end(1)
  443.     # If escape is failure
  444.     else
  445.       # Clear all party member actions
  446.       $game_party.clear_actions
  447.       # Start main phase
  448.       start_phase4
  449.     end
  450.   end
  451.  
  452.     #--------------------------------------------------------------------------
  453.   # * Make Basic Action Results
  454.   #--------------------------------------------------------------------------
  455.   def make_basic_action_result
  456.     # If attack
  457.     if @active_battler.current_action.basic == 0
  458.       # Set anaimation ID
  459.       @animation1_id = @active_battler.animation1_id
  460.       @animation2_id = @active_battler.animation2_id
  461.       # If action battler is enemy
  462.       if @active_battler.is_a?(Game_Enemy)
  463.         if @active_battler.restriction == 3
  464.           target = $game_troop.random_target_enemy
  465.         elsif @active_battler.restriction == 2
  466.           target = $game_party.random_target_actor
  467.         else
  468.           index = @active_battler.current_action.target_index
  469.           target = $game_party.smooth_target_actor(index)
  470.         end
  471.       end
  472.       # If action battler is actor
  473.       if @active_battler.is_a?(Game_Actor)
  474.         if @active_battler.restriction == 3
  475.           target = $game_party.random_target_actor
  476.         elsif @active_battler.restriction == 2
  477.           target = $game_troop.random_target_enemy
  478.         else
  479.           index = @active_battler.current_action.target_index
  480.           target = $game_troop.smooth_target_enemy(index)
  481.         end
  482.       end
  483.       # Set array of targeted battlers
  484.       @target_battlers = [target]
  485.       # Apply normal attack results
  486.       for target in @target_battlers
  487.         target.attack_effect(@active_battler)
  488.       end
  489.       return
  490.     end
  491.     # If guard
  492.     if @active_battler.current_action.basic == 1
  493.       # Display "Guard" in help window
  494.       @help_window.set_text($data_system.words.guard, 1)
  495.       # Reduce MP if is a MP consumer and a actor
  496.       if @active_battler.is_a? Game_Actor
  497.            Wep.test (:defense, @active_battler)
  498.       end
  499.    
  500.      
  501.       return
  502.     end
  503.     # If escape
  504.     if @active_battler.is_a?(Game_Enemy) and
  505.        @active_battler.current_action.basic == 2
  506.       # Display "Escape" in help window
  507.       @help_window.set_text("Escape", 1)
  508.       # Escape
  509.       @active_battler.escape
  510.       return
  511.     end
  512.     # If doing nothing
  513.     if @active_battler.current_action.basic == 3
  514.       # Clear battler being forced into action
  515.       $game_temp.forcing_battler = nil
  516.       # Shift to step 1
  517.       @phase4_step = 1
  518.       return
  519.     end
  520.   end
  521. end
  522.  
  523.  
  524. class Game_Actor
  525.   attr_reader :actor_id
  526.   attr_reader :class_id
  527. end
  528.  
  529. class Game_Battler
  530.  
  531.   #--------------------------------------------------------------------------
  532.   # * Applying Normal Attack Effects
  533.   #     attacker : battler
  534.   #--------------------------------------------------------------------------
  535.   def attack_effect(attacker)
  536.     # Clear critical flag
  537.     self.critical = false
  538.       # Reduce MP if is a MP consumer and a actor
  539.       if attacker.is_a? Game_Actor
  540.           Wep.test(:attack, attacker)
  541.       end
  542.     # First hit detection
  543.     hit_result = (rand(100) < attacker.hit)
  544.     # If hit occurs
  545.     if hit_result == true
  546.  
  547.       # Calculate basic damage
  548.       atk = [attacker.atk - self.pdef / 2, 0].max
  549.       self.damage = atk * (20 + attacker.str) / 20
  550.       # Element correction
  551.       self.damage *= elements_correct(attacker.element_set)
  552.       self.damage /= 100
  553.       # If damage value is strictly positive
  554.       if self.damage > 0
  555.         # Critical correction
  556.         if rand(100) < 4 * attacker.dex / self.agi
  557.           self.damage *= 2
  558.           self.critical = true
  559.         end
  560.         # Guard correction
  561.         if self.guarding?
  562.           self.damage /= 2
  563.         end
  564.       end
  565.       # Dispersion
  566.       if self.damage.abs > 0
  567.         amp = [self.damage.abs * 15 / 100, 1].max
  568.         self.damage += rand(amp+1) + rand(amp+1) - amp
  569.       end
  570.       # Second hit detection
  571.       eva = 8 * self.agi / attacker.dex + self.eva
  572.       hit = self.damage < 0 ? 100 : 100 - eva
  573.       hit = self.cant_evade? ? 100 : hit
  574.       hit_result = (rand(100) < hit)
  575.     end
  576.     # If hit occurs
  577.     if hit_result == true
  578.       # State Removed by Shock
  579.       remove_states_shock
  580.       # Substract damage from HP
  581.       self.hp -= self.damage
  582.       # State change
  583.       @state_changed = false
  584.       states_plus(attacker.plus_state_set)
  585.       states_minus(attacker.minus_state_set)
  586.     # When missing
  587.     else
  588.       # Set damage to "Miss"
  589.       self.damage = "Miss"
  590.       # Clear critical flag
  591.       self.critical = false
  592.     end
  593.     # End Method
  594.     return true
  595.   end
  596.  
  597.   #--------------------------------------------------------------------------
  598.   # * Apply Skill Effects
  599.   #     user  : the one using skills (battler)
  600.   #     skill : skill
  601.   #--------------------------------------------------------------------------
  602.   def skill_effect(user, skill)
  603.     # Clear critical flag
  604.     self.critical = false
  605.       # Reduce MP if is a MP consumer and a actor
  606.       if self.is_a? Game_Actor
  607.            Wep.test(:skill, self, skill)
  608.       end
  609.     # If skill scope is for ally with 1 or more HP, and your own HP = 0,
  610.     # or skill scope is for ally with 0, and your own HP = 1 or more
  611.     if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
  612.        ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
  613.       # End Method
  614.       return false
  615.     end
  616.     # Clear effective flag
  617.     effective = false
  618.     # Set effective flag if common ID is effective
  619.     effective |= skill.common_event_id > 0
  620.     # First hit detection
  621.     hit = skill.hit
  622.     if skill.atk_f > 0
  623.       hit *= user.hit / 100
  624.     end
  625.     hit_result = (rand(100) < hit)
  626.     # Set effective flag if skill is uncertain
  627.     effective |= hit < 100
  628.     # If hit occurs
  629.     if hit_result == true
  630.  
  631.    
  632.       # Calculate power
  633.       power = skill.power + user.atk * skill.atk_f / 100
  634.       if power > 0
  635.         power -= self.pdef * skill.pdef_f / 200
  636.         power -= self.mdef * skill.mdef_f / 200
  637.         power = [power, 0].max
  638.       end
  639.       # Calculate rate
  640.       rate = 20
  641.       rate += (user.str * skill.str_f / 100)
  642.       rate += (user.dex * skill.dex_f / 100)
  643.       rate += (user.agi * skill.agi_f / 100)
  644.       rate += (user.int * skill.int_f / 100)
  645.       # Calculate basic damage
  646.       self.damage = power * rate / 20
  647.       # Element correction
  648.       self.damage *= elements_correct(skill.element_set)
  649.       self.damage /= 100
  650.       # If damage value is strictly positive
  651.       if self.damage > 0
  652.         # Guard correction
  653.         if self.guarding?
  654.           self.damage /= 2
  655.         end
  656.       end
  657.       # Dispersion
  658.       if skill.variance > 0 and self.damage.abs > 0
  659.         amp = [self.damage.abs * skill.variance / 100, 1].max
  660.         self.damage += rand(amp+1) + rand(amp+1) - amp
  661.       end
  662.       # Second hit detection
  663.       eva = 8 * self.agi / user.dex + self.eva
  664.       hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100
  665.       hit = self.cant_evade? ? 100 : hit
  666.       hit_result = (rand(100) < hit)
  667.       # Set effective flag if skill is uncertain
  668.       effective |= hit < 100
  669.     end
  670.     # If hit occurs
  671.     if hit_result == true
  672.       # If physical attack has power other than 0
  673.       if skill.power != 0 and skill.atk_f > 0
  674.         # State Removed by Shock
  675.         remove_states_shock
  676.         # Set to effective flag
  677.         effective = true
  678.       end
  679.       # Substract damage from HP
  680.       last_hp = self.hp
  681.       self.hp -= self.damage
  682.       effective |= self.hp != last_hp
  683.       # State change
  684.       @state_changed = false
  685.       effective |= states_plus(skill.plus_state_set)
  686.       effective |= states_minus(skill.minus_state_set)
  687.       # If power is 0
  688.       if skill.power == 0
  689.         # Set damage to an empty string
  690.         self.damage = ""
  691.         # If state is unchanged
  692.         unless @state_changed
  693.           # Set damage to "Miss"
  694.           self.damage = "Miss"
  695.         end
  696.       end
  697.     # If miss occurs
  698.     else
  699.       # Set damage to "Miss"
  700.       self.damage = "Miss"
  701.     end
  702.     # If not in battle
  703.     unless $game_temp.in_battle
  704.       # Set damage to nil
  705.       self.damage = nil
  706.     end
  707.     # End Method
  708.     return effective
  709.   end
  710.  
  711.   #--------------------------------------------------------------------------
  712.   # * Application of Item Effects
  713.   #     item : item
  714.   #--------------------------------------------------------------------------
  715.   def item_effect(item)
  716.     # Clear critical flag
  717.     self.critical = false
  718.     Wep.test(:item, self, item)
  719.     # If item scope is for ally with 1 or more HP, and your own HP = 0,
  720.     # or item scope is for ally with 0 HP, and your own HP = 1 or more
  721.     if ((item.scope == 3 or item.scope == 4) and self.hp == 0) or
  722.        ((item.scope == 5 or item.scope == 6) and self.hp >= 1)
  723.       # End Method
  724.       return false
  725.     end
  726.     # Clear effective flag
  727.     effective = false
  728.     # Set effective flag if common ID is effective
  729.     effective |= item.common_event_id > 0
  730.     # Determine hit
  731.     hit_result = (rand(100) < item.hit)
  732.     # Set effective flag is skill is uncertain
  733.     effective |= item.hit < 100
  734.     # If hit occurs
  735.     if hit_result == true
  736.      
  737.      
  738.       # Calculate amount of recovery
  739.       recover_hp = maxhp * item.recover_hp_rate / 100 + item.recover_hp
  740.       recover_sp = maxsp * item.recover_sp_rate / 100 + item.recover_sp
  741.       if recover_hp < 0
  742.         recover_hp += self.pdef * item.pdef_f / 20
  743.         recover_hp += self.mdef * item.mdef_f / 20
  744.         recover_hp = [recover_hp, 0].min
  745.       end
  746.       # Element correction
  747.       recover_hp *= elements_correct(item.element_set)
  748.       recover_hp /= 100
  749.       recover_sp *= elements_correct(item.element_set)
  750.       recover_sp /= 100
  751.       # Dispersion
  752.       if item.variance > 0 and recover_hp.abs > 0
  753.         amp = [recover_hp.abs * item.variance / 100, 1].max
  754.         recover_hp += rand(amp+1) + rand(amp+1) - amp
  755.       end
  756.       if item.variance > 0 and recover_sp.abs > 0
  757.         amp = [recover_sp.abs * item.variance / 100, 1].max
  758.         recover_sp += rand(amp+1) + rand(amp+1) - amp
  759.       end
  760.       # If recovery code is negative
  761.       if recover_hp < 0
  762.         # Guard correction
  763.         if self.guarding?
  764.           recover_hp /= 2
  765.         end
  766.       end
  767.       # Set damage value and reverse HP recovery amount
  768.       self.damage = -recover_hp
  769.       # HP and SP recovery
  770.       last_hp = self.hp
  771.       last_sp = self.sp
  772.       self.hp += recover_hp
  773.       self.sp += recover_sp
  774.       effective |= self.hp != last_hp
  775.       effective |= self.sp != last_sp
  776.       # State change
  777.       @state_changed = false
  778.       effective |= states_plus(item.plus_state_set)
  779.       effective |= states_minus(item.minus_state_set)
  780.       # If parameter value increase is effective
  781.       if item.parameter_type > 0 and item.parameter_points != 0
  782.         # Branch by parameter
  783.         case item.parameter_type
  784.         when 1  # Max HP
  785.           @maxhp_plus += item.parameter_points
  786.         when 2  # Max SP
  787.           @maxsp_plus += item.parameter_points
  788.         when 3  # Strength
  789.           @str_plus += item.parameter_points
  790.         when 4  # Dexterity
  791.           @dex_plus += item.parameter_points
  792.         when 5  # Agility
  793.           @agi_plus += item.parameter_points
  794.         when 6  # Intelligence
  795.           @int_plus += item.parameter_points
  796.         end
  797.         # Set to effective flag
  798.         effective = true
  799.       end
  800.       # If HP recovery rate and recovery amount are 0
  801.       if item.recover_hp_rate == 0 and item.recover_hp == 0
  802.         # Set damage to empty string
  803.         self.damage = ""
  804.         # If SP recovery rate / recovery amount are 0, and parameter increase
  805.         # value is ineffective.
  806.         if item.recover_sp_rate == 0 and item.recover_sp == 0 and
  807.            (item.parameter_type == 0 or item.parameter_points == 0)
  808.           # If state is unchanged
  809.           unless @state_changed
  810.             # Set damage to "Miss"
  811.             self.damage = "Miss"
  812.           end
  813.         end
  814.       end
  815.     # If miss occurs
  816.     else
  817.       # Set damage to "Miss"
  818.       self.damage = "Miss"
  819.     end
  820.     # If not in battle
  821.     unless $game_temp.in_battle
  822.       # Set damage to nil
  823.       self.damage = nil
  824.     end
  825.     # End Method
  826.     return effective
  827.   end
  828.  
  829. end
  830.  
Expand to see the code.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=75067