Help - Search - Members - Calendar
Full Version: Jens009's SP Pop Up
RPG RPG Revolution Forums > Scripting > Script Submissions > RGSS-Submissions
jens009
Jens009's SP Pop Up

Version: 1.0
Author Jens009
Release Date January 7, 2010

Introduction
I happened to open up my external hard drive with all my unreleased scripts. Here's one of them.

Don't you hate it when you use an elixir/perfume/(your custom SP increase item here) you don't get a pop up version like healing items do? Here's the solution. =]

Features
- Plug And Play
- SP Value Pops up
- Defense Add on
- Highly Compatible with any Default Battle System

Customization
None.
If you include the "SP Defence Add on" You can modify the percentage increase of SP and the animation used.
See script below

Compatibility
Since I aliased most methods the compatibility on Custom Battle Systems should be high. If not, please report it to me.

Screenshot

Version 1.0


With Defend SP+ Add on


DEMO
It's plug and play

Installation

Paste above main. Below everything else.

Script
[Show/Hide] Jens009 SP Pop Up ver 1.0

CODE
#===============================================================================
# Jens009's SP Pop Up
# Version 1.0
# Description: When using an item that has an SP increase, the value pops up.
# Scripter's Notes:
# 1. All methods were aliased except for:
#     def update_phase4_step5 in Scene_Battle class
#     def initialize in Sprite class
# 2. SP recovery calculation was taken right out of default calculation
#===============================================================================
class Game_Battler
  attr_accessor :sp_rec_pop               # sp display flag
  attr_accessor :sp_rec                   # sp recovery value
  #-----------------------------------------------------------------------------
  # Initialize
  #-----------------------------------------------------------------------------
  alias jens009_sp_pop_initialize initialize
  def initialize
    @sp_rec_pop = false
    @sp_rec = nil
    jens009_sp_pop_initialize
  end
  #-----------------------------------------------------------------------------
  # item_effect
  #-----------------------------------------------------------------------------
  alias jens009_sp_pop_item_effect item_effect
  def item_effect(item)
    sp_recovery_calculation(item)
    jens009_sp_pop_item_effect(item)
  end
  #-----------------------------------------------------------------------------
  # sp_recovery_calculation
  # notes: I wanted to keep this separate so that if ever algorithms were
  # changed, it would be easy to locate.
  #-----------------------------------------------------------------------------
  def sp_recovery_calculation(item)
    # Clear critical flag
    self.critical = false
    # If item scope is for ally with 1 or more HP, and your own HP = 0,
    # or item scope is for ally with 0 HP, and your own HP = 1 or more
    if ((item.scope == 3 or item.scope == 4) and self.hp == 0) or
       ((item.scope == 5 or item.scope == 6) and self.hp >= 1)
      # End Method
      return false
    end
    # Clear effective flag
    effective = false
    # Set effective flag if common ID is effective
    effective |= item.common_event_id > 0
    # Determine hit
    hit_result = (rand(100) < item.hit)
    # Set effective flag is skill is uncertain
    effective |= item.hit < 100
    # If hit occurs
    if hit_result == true
      # Calculate amount of recovery
      recover_hp = maxhp * item.recover_hp_rate / 100 + item.recover_hp
      recover_sp = maxsp * item.recover_sp_rate / 100 + item.recover_sp
      if recover_hp < 0
        recover_hp += self.pdef * item.pdef_f / 20
        recover_hp += self.mdef * item.mdef_f / 20
        recover_hp = [recover_hp, 0].min
      end
      # Element correction
      recover_hp *= elements_correct(item.element_set)
      recover_hp /= 100
      recover_sp *= elements_correct(item.element_set)
      recover_sp /= 100
      # Dispersion
      if item.variance > 0 and recover_hp.abs > 0
        amp = [recover_hp.abs * item.variance / 100, 1].max
        recover_hp += rand(amp+1) + rand(amp+1) - amp
      end
      if item.variance > 0 and recover_sp.abs > 0
        amp = [recover_sp.abs * item.variance / 100, 1].max
        recover_sp += rand(amp+1) + rand(amp+1) - amp
      end
      # If recovery code is negative
      if recover_hp < 0
        # Guard correction
        if self.guarding?
          recover_hp /= 2
        end
      end
      # Set SP Recovery Amount
      self.sp_rec = recover_sp
    end
  end
  #-----------------------------------------------------------------------------
  # End of definition
  #-----------------------------------------------------------------------------
end
#===============================================================================
# Sprite_Battler
#===============================================================================
class Sprite_Battler < RPG::Sprite
  alias jens009_sp_pop_update update
  #-----------------------------------------------------------------------------
  # update
  #-----------------------------------------------------------------------------
  def update
    jens009_sp_pop_update
    if @battler_visible
      # SP Recovery JENS009
      if @battler.sp_rec_pop
        sp_rec(@battler.sp_rec)
        @battler.sp_rec = nil
        @battler.sp_rec_pop = false
      end
    end
  end
end
#===============================================================================
# Scene_Battle
#===============================================================================
class Scene_Battle
  #-----------------------------------------------------------------------------
  # update_phase4_step5
  # note: Modifications are enclosed by comments
  #-----------------------------------------------------------------------------
  def update_phase4_step5
    # Hide help window
    @help_window.visible = false
    # Refresh status window
    @status_window.refresh
    # Display damage
    for target in @target_battlers
      if target.damage != nil
        target.damage_pop = true
      end
      #-------------------------------------------------------------------------
      #JENS009 Modified Line    
      if target.sp_rec != nil and target.sp_rec != 0
        target.sp_rec_pop = true    
      end  
      #-------------------------------------------------------------------------
    end
    # Shift to step 6
    @phase4_step = 6
  end
end
#===============================================================================
# Module RPG, Sprite
# notes: initialized was re-written
#===============================================================================
module RPG
  class Sprite < ::Sprite
  #-----------------------------------------------------------------------------
  # initialize
  # note: modification is enclosed by comments
  #-----------------------------------------------------------------------------
    def initialize(viewport = nil)
      super(viewport)
      @_whiten_duration = 0
      @_appear_duration = 0
      @_escape_duration = 0
      @_collapse_duration = 0
      @_damage_duration = 0
      @_animation_duration = 0
      #-------------------------------------------------------------------------
      #JENS009 Modified Line  
      @_sp_rec_duration = 0
      #-------------------------------------------------------------------------
      @_blink = false
    end
  #-----------------------------------------------------------------------------
  # dispose
  #-----------------------------------------------------------------------------
    alias jens009_sp_pop_dispose_sprite dispose
    def dispose
      jens009_sp_pop_dispose_sprite
      dispose_sp_rec
    end
  #-----------------------------------------------------------------------------
  # sp_rec
  # description: Creates SP sprite very similar to HP
  #-----------------------------------------------------------------------------
    def sp_rec(value)
      dispose_sp_rec
      if value.is_a?(Numeric)
        sp_rec_string = value.abs.to_s
      else
        sp_rec_string = value.to_s
      end
      bitmap = Bitmap.new(160, 48)
      bitmap.font.name = "Arial Black"
      bitmap.font.size = 32
      bitmap.font.color.set(0, 0, 0)
      bitmap.draw_text(-1, 12-1, 160, 36, sp_rec_string, 1)
      bitmap.draw_text(+1, 12-1, 160, 36, sp_rec_string, 1)
      bitmap.draw_text(-1, 12+1, 160, 36, sp_rec_string, 1)
      bitmap.draw_text(+1, 12+1, 160, 36, sp_rec_string, 1)
      if value.is_a?(Numeric) and value < 0
        bitmap.font.color.set(-255, -50, 200)
        else
        bitmap.font.color.set(-255, -170, 200)
      end
      bitmap.draw_text(0, 12, 160, 36, sp_rec_string, 1)
      @_sp_rec_sprite = ::Sprite.new(self.viewport)
      @_sp_rec_sprite.bitmap = bitmap
      @_sp_rec_sprite.ox = 80
      @_sp_rec_sprite.oy = 20
      @_sp_rec_sprite.x = self.x
      @_sp_rec_sprite.y = (self.y - self.oy / 2) + 20
      @_sp_rec_sprite.z = 3000
      @_sp_rec_duration = 40
    end
  #-----------------------------------------------------------------------------
  # dispose_sp_rec
  # note: dispose sprite
  #-----------------------------------------------------------------------------
    def dispose_sp_rec
      if @_sp_rec_sprite != nil
        @_sp_rec_sprite.bitmap.dispose
        @_sp_rec_sprite.dispose
        @_sp_rec_sprite = nil
        @_sp_rec_duration = 0
      end
    end
  #-----------------------------------------------------------------------------
  # update
  # creates SP sprite path
  #-----------------------------------------------------------------------------
    alias jens009_sp_rec_update_sprite update
    def update
      jens009_sp_rec_update_sprite
      if @_sp_rec_duration > 0
        @_sp_rec_duration -= 1
        case @_sp_rec_duration
        when 38..39
          @_sp_rec_sprite.y -= 4
        when 36..37
          @_sp_rec_sprite.y -= 2
        when 34..35
          @_sp_rec_sprite.y += 2
        when 28..33
          @_sp_rec_sprite.y += 4
        end
        @_sp_rec_sprite.opacity = 256 - (12 - @_sp_rec_duration) * 32
        if @_sp_rec_duration == 0
          dispose_sp_rec
        end
      end
    end
  #-----------------------------------------------------------------------------
  # End of Definition
  #-----------------------------------------------------------------------------
  end
end


[Show/Hide] Jens009's SP+Defend

CODE
#===============================================================================
# Jens009's SP increase on Defend (Add-on to SP Pop up)
# Version 1.0
# Description: Increase defender's sp by 10% (on default)
#===============================================================================
class Scene_Battle
  #-----------------------------------------------------------------------------
  # Include SP increase percent
  #-----------------------------------------------------------------------------
  SP_INCREASE_PERCENT = 10.0   #Percentage of increase
  SP_INCREASE_ANIMATION_ID = 2 #Animation for defending
  #-----------------------------------------------------------------------------
  # make_basic_action_result
  #-----------------------------------------------------------------------------
  alias jens009_make_basic_action_result make_basic_action_result
  def make_basic_action_result
    # Display "Guard" in help window
    if @active_battler.current_action.basic == 1
      @help_window.set_text($data_system.words.guard, 1)
      #Display Animation ID
      @active_battler.animation_id = SP_INCREASE_ANIMATION_ID
      add_sp = @active_battler.maxsp.to_f * SP_INCREASE_PERCENT/100.0
      @active_battler.sp += add_sp.to_i
      @active_battler.sp_rec = add_sp.to_i
      @active_battler.sp_rec_pop = true
      # Set Animation Flag to True
      @active_battler.animation_hit = true
      return
    end
    jens009_make_basic_action_result
  end
end


FAQ
None so far.

Terms and Conditions
This script is for non-commercial use only. Contact me regarding commercial use.
Give credits where it's due.


Credits
Jens009- Script Author

jimmyly
Very nice indeed and edit friendly too. This is a must have script.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.