Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: Aqua on June 16, 2009, 04:18:19 pm

Title: [XP] Percentage Health States
Post by: Aqua on June 16, 2009, 04:18:19 pm
Percentage Health States
Authors: Aqua
Version: 1.5
Type: Battle States Add-on
Key Term: Battle Add-on



Introduction

This script makes it so that battlers will gain states when they are below a certain percentage of health.  The states would be automatically lost when the battler's health is above the configured percentage.
Note:  this affects all actors and enemies.

For example, you could have a state for when HP is critical and battlers gain more attack as a last effort to win.


Features




Screenshots

Not really needed.
Imagine that Arshes gains Sharp when his HP falls below 20%


Demo

Don't think it'd be really necessary, but post if you do want one.


Script

Spoiler: ShowHide

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=#
# Percentage Health States Script by TerreAqua
# Version: 1.5
# Type: Battle States Add-on
# Key Term: Battle Add-on
# Date: 6/17/09
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=#

#===============================================================================
# Information
#-------------------------------------------------------------------------------
#
#   This script makes it so that battlers will gain states when they are below a
#   certain percentage of health.  The states would be automatically lost when
#   the battler's health is above the configured percentage.
#   Note:  this affects all actors and enemies.
#
#   If you need to contact me about this script, please go to:
#   http://forum.chaos-project.com
#
#   You should have only gotten this script from http://chaos-project.com
#   Please let me know if you have found it somewhere else.
#===============================================================================
module Aqua
 module HealthStates
#:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~#
#:~:~:~:~:~:~:~:~:~:~::~:~:~: Instructions :~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~#
#:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~#
#===============================================================================
# Configure the below modules in the following format:
#
# MODULE = [[X, Y]]
#
# MODULE is the below modules.  You don't change these, and they all follow the
#    same format.
# X is the percent of health for the state to activate (can be a decimal).
# Y is the state id.
#
#===============================================================================

# HP States that affect all battlers
HP_STATES_ALL = [[25.0, 18]]

# HP States that only affect actors
HP_STATES_ACTORS = []

# Actor specific HP States
# Format is:  when ACTOR_ID then return [[X, Y]]
def self.actor(id)
 case id
 when 1 then return [[95, 5], [70, 4]]
 when 2 then return [[98, 4]]
 end
 return []
end

# HP States that only affect enemies
HP_STATES_ENEMIES = []

# Enemy specific HP States
# Format is:  when ENEMY_ID then return [[X, Y]]
def self.enemy(id)
 case id
 when 1 then return [[99, 5]]
 end
 return []
end

#:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~#
#:~:~:~:~:~:~:~:~:~:~:~:~  End Configure Area  :~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~#
#:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~#

end
end

#===============================================================================
# Credits:
# Aqua (aka TerreAqua) for making this.
# Subsonic_Noise for requesting that I release it.
# Starrodkirby86 for letting me rant to him.
#===============================================================================

#===============================================================================
#  This work is protected by the following license:
# #-----------------------------------------------------------------------------
# #  
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# #  
# #  You are free:
# #  
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# #  
# #  Under the following conditions:
# #  
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# #  
# #  Noncommercial. You may not use this work for commercial purposes.
# #  
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# #  
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# #  
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# #  
# #  - Nothing in this license impairs or restricts the author's moral rights.
# #  
# #-----------------------------------------------------------------------------
#===============================================================================


class Game_Battler
 def hp_percent_states(hp_percent, state_id)
     aqhp = self.hp.to_f
     aqmaxhp = self.maxhp.to_f
     aqhpper = (aqhp / aqmaxhp) * 100
     if aqhpper <= hp_percent
       add_state(state_id)
     else
       remove_state(state_id)
     end
 end
   
 def hp_percent_states_checker
   if self.is_a?(Game_Actor)
     for i in $game_party.actors
       id = i.id
       if self.id == id
         e = Aqua::HealthStates.actor(id)
         for q in e
           hp_percent_states(q[0], q[1])
         end
       end
       for i in Aqua::HealthStates::HP_STATES_ACTORS
         hp_percent_states(i[0], i[1])
       end
     end
       
   elsif self.is_a?(Game_Enemy)
     for i in $game_troop.enemies
       id = i.id
       if self.id == id
         e = Aqua::HealthStates.enemy(id)
         for q in e
           hp_percent_states(q[0], q[1])
         end
       end
       for i in Aqua::HealthStates::HP_STATES_ENEMIES
         hp_percent_states(i[0], i[1])
       end
     end
   end
     
   for i in Aqua::HealthStates::HP_STATES_ALL
     hp_percent_states(i[0], i[1])
   end
 end

   
 alias hp_percent_states_attack_effect attack_effect
 def attack_effect(attacker)
   if hp_percent_states_attack_effect(attacker)
     hp_percent_states_checker
   end
   return
 end
 
 alias hp_percent_states_skill_effect skill_effect
 def skill_effect(user, skill)
   if hp_percent_states_skill_effect(user, skill)
     hp_percent_states_checker
   end
   return
 end
   
 alias hp_percent_states_item_effect item_effect
 def item_effect(item)
   if hp_percent_states_item_effect(item)
     hp_percent_states_checker
   end
   return
 end
 
 alias hp_percent_states_slip_damage_effect slip_damage_effect
 def slip_damage_effect
   if hp_percent_states_slip_damage_effect
     hp_percent_states_checker
   end
   return
 end
 
end



Instructions
New script slot > Below RTP scripts > Above Main

# Configure the below modules in the following format:
#
# MODULE = [[X, Y]]
#
# MODULE is the below modules.  You don't change these, and they all follow the
#    same format.
# X is the percent of health for the state to activate (can be a decimal).
# Y is the state id.




Compatibility

Might not be compatible with exotic scripts.
Compatible with Blizz-ABS.  Paste above if using with Blizz-ABS


Credits and Thanks




Author's Notes

Hope you enjoy this!

I might add Scene_Map checker later.
Title: Re: [XP] Percentage Health States
Post by: Subsonic_Noise on June 16, 2009, 04:21:44 pm
Nice script^^ I'll definitely use it in my game.
AND I'm in the credits XD
level ++
Title: Re: [XP] Percentage Health States
Post by: Seox on June 16, 2009, 04:37:03 pm
Thanks, Aqua!

Been looking for something like this for a LOOOOONG time.
Title: Re: [XP] Percentage Health States
Post by: Reno-s--Joker on June 17, 2009, 05:20:13 am
*levels up*

I'm bookmarking this for a later date since it's such a nifty little feature which could add more to the battle system. :D
Title: Re: [XP] Percentage Health States
Post by: Blizzard on June 17, 2009, 06:30:12 am
Want me to Tons' it?
Title: Re: [XP] Percentage Health States
Post by: Sally on June 17, 2009, 09:57:20 am
what about specific actors? like actor1 gains this at 20%
but actor2 gain something different at 20%.

nice script btw.
Title: Re: [XP] Percentage Health States
Post by: Aqua on June 17, 2009, 12:13:56 pm
@S, S, & Re: Glad you like it.

@Blizz:  Sure! :P

@Sally:  I said in the author's notes that I'll add more features.
Title: Re: [XP] Percentage Health States
Post by: G_G on June 17, 2009, 12:16:06 pm
aqua heres a feature you should add. The state can only be added to the actor if the hp is the right percent and a certain weapon is equipped. I had an idea for this and it required the feature I just said.
Title: Re: [XP] Percentage Health States
Post by: Aqua on June 17, 2009, 12:30:52 pm
Forgot to take slip damage into account... I'll do this now.

@G_G:  You can just do that with the config when I update it to have actor specific states.
It'd be like...
when ID
  if $game_actors[ID].weapon_id == WEAPON
     return [%_HEALTH, STATE_ID]
  else
     return [Whatever XD]
  end


Edit:
I'm also wondering if there's a better place to put my method... hmmm...
Title: Re: [XP] Percentage Health States
Post by: Seox on June 17, 2009, 01:03:07 pm
Quote from: Aqua on June 17, 2009, 12:30:52 pm
Forgot to take slip damage into account... I'll do this now.

@G_G:  You can just do that with the config when I update it to have actor specific states.
It'd be like...
when ID
  if $game_actors[ID].weapon_id == WEAPON
     return [%_HEALTH, STATE_ID]
  else
     return [Whatever XD]
  end


Edit:
I'm also wondering if there's a better place to put my method... hmmm...


Forgot to take slip damage into account? I don't understand. The state that I've been using (Wounded at < 40%) causes SEVERE debilitation, accuracy/attack/etc wise, but they also "bleed out", which is slip damage, and works fine. Just thought it might be relevant.
Title: Re: [XP] Percentage Health States
Post by: Aqua on June 17, 2009, 01:07:53 pm
I mean... didn't take into account that states should activate when slip damage causes you to go under X% of health.

I fixed this in the new version which I'm still working on XD
Title: Re: [XP] Percentage Health States
Post by: Seox on June 17, 2009, 01:11:54 pm
Quote from: Aqua on June 17, 2009, 01:07:53 pm
I mean... didn't take into account that states should activate when slip damage causes you to go under X% of health.

I fixed this in the new version which I'm still working on XD



Ahhhh. Thanks, Aqua ^_^.

Say, I know that it updates when an enemy attacks you, but what if you, say, step on a damaging tile or something? Also, I know that it updates if health is over the given percent, but will it update if you actually heal someone, or do they have to be healed, and then hit, and still be over the percent?

Thank you ^_^
Title: Re: [XP] Percentage Health States
Post by: Aqua on June 17, 2009, 01:37:11 pm
So you're saying I should add a Scene_Map checker? XD
Title: Re: [XP] Percentage Health States
Post by: Seox on June 17, 2009, 01:47:20 pm
Quote from: Aqua on June 17, 2009, 01:37:11 pm
So you're saying I should add a Scene_Map checker? XD


I think that it would be helpful. I don't have any specific occurances of damaging tiles, but it's an army-type thing, so booby-traps/mines/etc are likely. I would definitely get some use out of it, and I think that I wouldn't be alone.

Just saying. Maybe make it configurable?

map_check = true # set to false to ONLY regulate in battle.


something simple like that.

What do you think?
Title: Re: [XP] Percentage Health States
Post by: Aqua on June 17, 2009, 01:59:08 pm
Updated!

Added only actor/only enemy states, actor/enemy specific states & slip damage checker.
Also improved the coding. (I think...)

Edit:
Topic locked.

*points to Tons (http://forum.chaos-project.com/index.php?topic=105.0)*