The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on May 16, 2010, 05:05:28 PM

Title: Revive State
Post by: modern algebra on May 16, 2010, 05:05:28 PM
Revive State
Version: 1.1
Author: modern algebra
Date: May 16, 2010

Version History



Description


This script allows you to make states that will revive the actor who has it immediately upon KO. You can set to what health it revives them to, either directly or by percentage, and you can set the SE and message that plays when it works.

Features


Instructions

Please see the header of the script for instructions.

Script


Code: [Select]
#==============================================================================
#    Revive State
#    Version: 1.1
#    Author: modern algebra (rmrk.net)
#    Date: May 16, 2010
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script allows you to make states that will revive the actor who has
#   it immediately upon KO. You can set to what health it revives them to,
#   either directly or by percentage, and you can set the SE and message that
#   plays when it works.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Paste this script into its own slot in the Script Editor (F11), somewhere
#   below Materials but still above Main.
#
#    To set a state to revive, all you need to do is put the following code in
#   its note field:
#      \revive[x]
#         x : the health you want the actor to return to. If you wish to set it
#           to a percentage, simply put a % sign after the value, so:
#      \revive[x%]
#
#    If you want the state to dissipate upon reviving the actor, then make sure
#   you set it as a State to Cancel in your Incapacitated state. Otherwise, it
#   will remain until it is naturally removed.
#
#  If you wish, you can also set states up to have special revive SEs with the
# code in the note field:
#    \REVIVE_SE[se_name, volume, pitch]
# If you don't set this, then it will default to the DEFAULT_REVIVAL_SE, as
# found and setup at line 48. If you set it, but exclude volume or pitch, then
# they will default to 100.
#
#  You can also set states to have special revive messages when it works, by
# using this code in the note field:
#    \REVIVE_MSG[ message]
# If you exclude it, it will default to whatever message you have set at line
# 52.
#==============================================================================
#  CONSTANT
#==============================================================================
#  Here, you can set the default revival SE for all revive skills. Set it as:
#    DEFAULT_REVIVAL_SE = "se name", volume, pitch
#  If you exclude volume or pitch, they default to 100.
DEFAULT_REVIVAL_SE = "Raise1", 100, 120
#  You can set the default revival message for all revive skills. Set it as:
#    DEFAULT_REVIVAL_SE = " message"
#  Prior to this message, the actor or enemy's name who it affects will be
# printed.
DEFAULT_REVIVAL_MSG = " was knocked out but is revived!"
#==============================================================================
# ** RPG::State
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - revival_health; revival_se; revival_message
#==============================================================================

class RPG::State
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Revival Health
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def revival_health
    if !@revival_health
      @revival_health = 0
      if self.note[/\\REVIVE\[(\d+)(%?)\]/i] != nil
        @revival_health = $2.empty? ? $1.to_i : [($1.to_f / 100.0), 1.0].min
      end
    end
    return @revival_health
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Revival SE
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def revival_se
    if !@revival_se
      @revival_se = DEFAULT_REVIVAL_SE
      @revival_se = [@revival_se] if !@revival_se.is_a? (Array)
      if self.note[/\\REVIVE_SE\[([^,\]]+),?\s*(\d*),?\s*(\d*)\]/i] != nil
        @revival_se = [$1.to_s]
        @revival_se.push ($2.to_i) if !$2.empty?
        @revival_se.push ($3.to_i) if !$3.empty?
      end
    end
    return RPG::SE.new (*@revival_se)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Revival Message
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def revival_message
    if !@revival_message
      @revival_message = self.note[/\\REVIVE_MSG\[(.*?)\]/i] != nil ? $1.to_s : DEFAULT_REVIVAL_MSG
    end
    return @revival_message
  end
end

#==============================================================================
# ** Game_Battler
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new accessor variable - revival_message
#    aliased method - add_state; states_active?
#==============================================================================

class Game_Battler
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Public Instance Variable
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  attr_accessor :revival_message
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * States Active?
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modal_rvvest_avestat_6yh2 states_active?
  def states_active? (*args)
    return true if @revival_message
    return modal_rvvest_avestat_6yh2 (*args)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Add State
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias ma_revive_adstae_8ik5 add_state
  def add_state (state_id, *args)
    rs = nil
    rh = 0
    if state_id == 1 # If Incapacitated State
      self.states.each { |state|
        rh2 = state.revival_health
        rh2 = [(self.maxhp*rh2).to_i, self.maxhp].min if rh2.is_a? (Float)
        if rh2 > rh
          rs = state
          rh = rh2
        end
      }
    end
    ma_revive_adstae_8ik5 (state_id, *args) # Run Original Method
    if rs != nil # If revive state engaged
      begin
        rs.revival_se.play
      rescue
      end
      self.hp = rh
      @revival_message = "#{self.name}#{rs.revival_message}" if !rs.revival_message.empty?
    end
  end
end

#==============================================================================
# ** Scene_Battle
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - display_added_states
#==============================================================================

class Scene_Battle
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Display Added States
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias moda_rvval_dspadst_4tg9 display_added_states
  def display_added_states (target, *args)
    moda_rvval_dspadst_4tg9 (target, *args) # Run Original Method
    if target.revival_message != nil
      @message_window.replace_instant_text (target.revival_message)
      wait(20)
      target.revival_message = nil
    end
  end
end

Credit



Thanks


Support


Please post in this topic at RMRK.net for support.

Known Compatibility Issues

No currently known compatibility issues. Should work with almost any battle system, though it might not show the message.
Title: Re: Revive State
Post by: cozziekuns on May 16, 2010, 05:10:50 PM
So it's basically like a Re-raise status in FF? Sounds pretty cool.

Though I'm not sure if I like the fact that it simply plays a sound. It should write something in the text like "%s was Re-Risen".
Title: Re: Revive State
Post by: modern algebra on May 16, 2010, 07:29:39 PM
Well, I'll quickly write a new version that can, but it likely won't work for a number of custom battle systems :(
Title: Re: Revive State
Post by: Grafikal on May 16, 2010, 08:16:46 PM
If you get this to compatible with Tankentai SVBS, that'd be great :)
I haven't actually checked if it wasn't yet. Just assuming this being probably one of those "custom battle systems" it won't work with.
I'm actually making a game this time :O

(and get this, I plan on using all the scripts I've asked for in the past lol, including the tutorial and inventory scripts :D)
Title: Re: Revive State
Post by: modern algebra on May 16, 2010, 08:48:33 PM
Well, the function almost certainly will. The only thing I have reservations about is whether the message will show up, but I can check it out.

EDIT::

I looked at it for a little - it does work but it's weird. Anyway, I don't think it's useful since they already have some sort of autolife feature built into Tankentai. I haven't looked into how to use it, but I'm sure it works so I wouldn't bother using this script if you have Tankentai.
Title: Re: Revive State
Post by: JFace on July 09, 2010, 08:22:06 PM
Ok...I'm not a complete idiot (I don't think)...

I know how the basics of scripting and whatnot, but one big problem is holding me back...

When I copy scripts, the formatting is not carried over, so that when I paste, all the code is on one line. What's the deal?

(I would have posted this on the sticky note about how to copy scripts, but it's locked)
Title: Re: Revive State
Post by: modern algebra on July 09, 2010, 08:24:13 PM
It's a problem with Internet Explorer and SMF2. Just use another browser to copy scripts for now and it will hopefully be fixed some time in the future. I attached a text document with this script to this post. If you don't have another browser, you can just get it from there.