Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Looking for a SP per hit script

I'm looking for a script that gives you SP everytime you hit the mob, just Attacking it, not using a skill and etc. For example, when you just "Attack" the mob, you gain 10 SP, thanks!
 
Code:
module Sp_Hit
  SP = {actor_id => float + int, actor_id => float + int, ...}
  DEFAULT = 0
  Show_Recovery = true
end

class Scene_Battle
  alias sp_per_hit_make_basic_action_result make_basic_action_result
  def make_basic_action_result
    if @active_battler.is_a?(Game_Actor) and @active_battler.current_action.basic == 0
     if Sp_Hit.has_key?(@active_battler.id)
       amount = Sp_Hit::SP[@active_battler.id]
     else
       amount = Sp_Hit::DEFAULT
     end
     percentage = amount - amount.to_i
     amount = amount.to_i
     restored = max * percentage + amount
     max = @active_battler.maxsp
     @active_battler.sp += restored
     if Sp_Hit::Show_Recovery
       @active_battler.damage = - restored
       @active_battler.damage_pop = true
     end
     @status_window.refresh if @status_window != nil and restored != 0
    end
  end  
end

untested but should work
 
yes the .. was intentionally placed there to show that you have have as many keys and values you wish in the hash I suppose I should also say that

actor_id is the actor id from the database
float + int is an Integer + Decimal where Decimal is the percentage recovered and Integer is the amount recovered

Code:
module Sp_Hit
  #syntax {actor_id => Integer + Decimal, ...}
  # actor id is the actor id from the database without zeros
  # Integer is the amount recovered
  # Decimal is the percentage recovered
  # so {1 => 10.75} means actor 1 when attacking gains
  # 75% of his max sp + 10 sp
  SP = {actor_id => Integer + Decimal, ...}
  DEFAULT = 0
  Show_Recovery = true
end

class Scene_Battle
  alias sp_per_hit_make_basic_action_result make_basic_action_result
  def make_basic_action_result
    if @active_battler.is_a?(Game_Actor) and @active_battler.current_action.basic == 0
     if Sp_Hit::SP.has_key?(@active_battler.id)
       amount = Sp_Hit::SP[@active_battler.id]
     else
       amount = Sp_Hit::DEFAULT
     end
     percentage = amount - amount.to_i
     amount = amount.to_i
     max = @active_battler.maxsp
     restored = max * percentage + amount
     @active_battler.sp += restored
     if Sp_Hit::Show_Recovery
       @active_battler.damage = - restored
       @active_battler.damage_pop = true
     end
     @status_window.refresh if @status_window != nil and restored != 0
   end
   sp_per_hit_make_basic_action_result
  end  
end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top