Iavra Auto States

Description

Introduces new notetags that allow actors/enemies/equips/states to automatically add and remove states based on current hp/mp/tp percentage.

Prerequisites

None

How to Use

Add the following tag to the notebox of an actor, enemy, equippable item or state:

<state (id) (param) (min)% (max)%># (id) id of the state, that should automatically be added/removed.# (param) one of hp/mp/tp.# (min) minimum percentage of the parameter.# (max) maximum percentage of the parameter.# Example<state 1 hp 10% 100%>You can define multiple restrictions for a state like this:
Code:
<state (id>  <(param) (min)% (max)%>  <(param) (min)% (max)%>  ...</state># Example<state 1>  <hp 10% 20%>  <hp 50% 80%>  <mp 0% 0%></state>
Note, that only one of those restrictions has to be met, not all of them.During updates, the script will check the restrictions for each actor, its equipped items and states, as well as for each enemy and its states and test if any restriction returns true:

- If at least one restriction is true and the state is addable to the actor, the state is added and its id is pushed to a list.

- If there is no valid restriction for a previously added state, it will be removed.

In addition, whenever a state is removed from the actor/enemy, its id is also removed from the list. The list is there to prevent the script from removing states that were added by other means than the script itself.

Configuration

If the maximum value for a parameter is 0, this can be either interpreted as 0% or 100%. Set ZERO_MAX according to your game's definition:

ZERO_MAX = 1.0You can define, if you automatically want to remove added states at end of battle. Note that the script will only update while in battle:
Code:
REMOVE_STATES_AFTER_BATTLE = true
By default, the script checks restrictions at the start and end of every turn as well as battle itself. This behaviour can be modified by editing UPDATE:
Code:
UPDATE = [  :battle_start,   :battle_end,  :turn_start,   :turn_end]
Terms of UseFree to use for both commercial and non-commercial games. Please give credit.

Credits

Iavra

FAQ

None so far

Changelog

- 0.01: First version.

- 0.02: Changed the script to only affect combat. Now updates at the start and end of every turn as well as at the start and end of battle.

- 0.03: Fixed a possible error when either max mp or max tp are 0.

- 0.04: Added the option to configure what methods should update states.

- 0.05: Fixed a bug, where the script wouldn't correctly remove states if the state id wasn't present in the restrictions anymore.

- 0.06: Added the option to remove all automatically added states at end of battle.

- 0.07: If a state is added by other means than the script, its id will now be removed from the list. If the restriction is still true, the id will be re-added with the next update.

- 0.08: Added support for learned (passive) skills.

- 1.00: Release version.

Special Thanks

- Vox Novus: For coming up with the script idea.

- Josephkhland: For testing.

Download

Script: http://pastebin.com/ggukpY82
This looks like a great script.  Thank you.

There is a particular use that I would like, but I can't work out if it is possible.  What I would like to happen is this:

As a reward for some action, a chest gives the player a choice about who will learn a passive skill (I think that's how it would have to be).  This passive skill is to have a particular protective auto-state.

I cannot, therefore, tag an actor as I don't know who it will be, and a tag would operate from the beginning of the game and I want this to be a late game reward.

I don't want to do this via a piece of equipment, as I do not know who will have it and therefore which piece of equipment to tag.

So it looks like it has to be a passive skill, but I don't see skills listed as a possibility to add tags to.

Have I overlooked something?
@ksjp17: I forgot about learned skills, but it was easy to add. So now the script will also take learned skills into account.
This sounds great! Can't wait until I can experiment around with what I can do with it; I hope you get bored and open to script suggestions more often 🙂
Thank you for the addition. 

One thing I was wondering about.  In the tag, where it has (param) does it make a difference if I put (hp) or its ID number, so (0)?
Everything that is not "hp", "mp" or "tp" (case-insensitive) will be skipped. It's not so hard to add more stats, though.

Outside the configuration area is this constant:

Code:
PARAMS = {  :hp => :mhp,   :mp => :mmp,   :tp => :max_tp}
The keys will be matched against the (param) section and also symbolize the function that holds the current value of the parameter. The values indicate which functions hold the maximum value. If you add additional parameters, you need function for the current as well for the maximum value, which have to be available to both actors and enemies (though the enemy versions can simply return 0).
Sorry to be a nuisance on this, but I'm obviously doing something wrong, because I can't get this to work.

In the note box of my skill I put this

<state (86) (hp) (1)% (25)%>

with scope sent to None, because obviously I don't want her to have to select it, I just want it to run automatically.

As that state is altering stats such as EVA and CEV, which are very difficult to test for, I also added the restriction 'unable to move', so that I could see that the state had been applied.

I had an event teach the skill to the actor, and reduce her HP to 10 (mhp = 210)

Before going into battle, I checked that the skill appeared in her skill list and that her hp had been reduced.  

However, in battle, she could still attack, so I assume that the restriction 'unable to move' had not been applied, and therefore the state itself had not been applied.

Can you point out what mistake I've made?  Thanks.
You are the second person pointing me to this, so i'm adding an example to a the OP. Basically, all you have to do is dropping the brackets "()".
Oh the brackets!!!  I thought from the way it was set out in the comments that they were an integral part of things.

Removed, and now all is as it should be.

Thank you very much.
So, i currently can't think of what else to add (which is a good thing, because i usually tend to overengineer everything) and unless one of the people using this found some bugs/incompatibilities with commonly used scripts, i will advance the version to 1.00 and ask a mod to move this to completed scripts.
Could I make a tiny suggestion?

That you add the example to the comments at the beginning of the script, because I think a lot of people will otherwise make the mistake with the brackets.

Other than that, I think this script is excellent.  So thank you for it.
For some wierd reason, it does not add the states on ATB battle systems. Am I missing something?

The notetag is set like this:

<state 44 hp 0% 20%>

I am using Formar's ATB Script.
The tag looks fine, but may not trigger depending on how the script handles turns. Could you link it?
Awesome Script Iavra! I've been looking for a way to add states based on HP/MP percentages! I'll DEFINITELY be giving this a try when I get back from work!

I have a suggestion, if you're up to it: Would it be possible to add an optional % chance of a state applying upon meeting the requirements?

For example, you have a "Berserk" type state that has a say 10% chance of activating when an actor/enemy falls below 25% HP?

Just a suggestion, thanks for the script!
I don't know if this would work the way it should. By default, the script checks the restrictions twice every turn (at start and end) and not only once the stat reaches the trigger area.


Even with an added percentage, the state will trigger eventually.
Gotcha, well awesome script nevertheless!
It may be old (as I have Version 1.5, he only has Version 1.3), but this may help:

http://cobbtocs.co.uk/wp/?p=64
I only did some searches, but it seems like the script never calls battle_start, battle_end and turn_end and also overrides turn_start. Did you try changing script order? Otherwise, you may try changing the UPDATE constant so the script trigger during a different method of BattleManager.
Switching the order does not help. So, how do I change this?
I would like to do a quick debug, before changing this.

Make sure that my script is positioned under the battle system, enable the console ("Game -> Show Console" in Ace) and add this after line 153 (self.update):

Code:
p "update called"
This will print to the console whenever the script update is called. So we will see, if the script is called at all.

Original thread: https://forums.rpgmakerweb.com/threads/iavra-auto-states.40847/