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.

Restoring SP by defending-- how do I do this?

I'm creating a battle system where all actions cost SP, and I want defending to restore SP.  How would I write a script to restore, say, 20% of the character's SP by defending?  I'm afraid I suck too much at scripting to figure this one out on my own.

Thanks very much for the help!
 
I can't write up a code for you now, but I'll give you a basis:

@actor_sp = $game_party.actors[0].sp
percent = @actor_sp/20.to_f

$game_party.actors[0].sp += percent

Obviously that won't work, but it should give you an idea of how to do it.
 
I appreciate the help, but I really suck at scripting-- I could manage to remove "Attack" from the menu, and I was able to turn the battlers side view, but that's about it.  I'm afraid that I probably won't be able to figure it out from that alone. 

Can anyone expand on that a bit?  Please?  I'm sorry that I suck at this...
 

khmp

Sponsor

There's a constant at the top you might want to adjust if 20% is too high or low.

@AbyssalLord: You were so close. But the percentage of sp should based on maximum sp. Not the current sp. Imagine having 1 point in SP and taking 20% of it.

Code:
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Constant Variables
  #--------------------------------------------------------------------------
  SP_GAIN_PERCENT = 0.2 # 20%
  #--------------------------------------------------------------------------
  # * Make Basic Action Results !OVERRIDE!
  #--------------------------------------------------------------------------
  def make_basic_action_result
    # If attack
    if @active_battler.current_action.basic == 0
      # Set anaimation ID
      @animation1_id = @active_battler.animation1_id
      @animation2_id = @active_battler.animation2_id
      # If action battler is enemy
      if @active_battler.is_a?(Game_Enemy)
        if @active_battler.restriction == 3
          target = $game_troop.random_target_enemy
        elsif @active_battler.restriction == 2
          target = $game_party.random_target_actor
        else
          index = @active_battler.current_action.target_index
          target = $game_party.smooth_target_actor(index)
        end
      end
      # If action battler is actor
      if @active_battler.is_a?(Game_Actor)
        if @active_battler.restriction == 3
          target = $game_party.random_target_actor
        elsif @active_battler.restriction == 2
          target = $game_troop.random_target_enemy
        else
          index = @active_battler.current_action.target_index
          target = $game_troop.smooth_target_enemy(index)
        end
      end
      # Set array of targeted battlers
      @target_battlers = [target]
      # Apply normal attack results
      for target in @target_battlers
        target.attack_effect(@active_battler)
      end
      return
    end
    # If guard
    if @active_battler.current_action.basic == 1
      # Display "Guard" in help window
      @help_window.set_text($data_system.words.guard, 1)
      # Increase the battler's sp.
      @active_battler.sp += @active_battler.maxsp * 0.2
      return
    end
    # If escape
    if @active_battler.is_a?(Game_Enemy) and
       @active_battler.current_action.basic == 2
      # Display "Escape" in help window
      @help_window.set_text("Escape", 1)
      # Escape
      @active_battler.escape
      return
    end
    # If doing nothing
    if @active_battler.current_action.basic == 3
      # Clear battler being forced into action
      $game_temp.forcing_battler = nil
      # Shift to step 1
      @phase4_step = 1
      return
    end
  end
end
 
That does the job!  Thank you very much for the help!

edit:  Uh, one other thing-- is there a way to loose the decimal points that show up?  I can't just add .trunc to active_battler.sp, as it turns out.
 

khmp

Sponsor

Uh change line 56 in that little scriplet:
Code:
@active_battler.sp += @active_battler.maxsp * 0.2
to this:
Code:
@active_battler.sp += (@active_battler.maxsp * 0.2).to_i

I didn't think it would allow SP to become a float. My apology
 

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