Covering Allies and Cover Conditions

This article discusses the cover mechanic in RPG Maker. Covering is the act of one battler taking a hit for another battler. For example, if you had a healer that was critically wounded, and any attack would be fatal, another actor could step in and take the hit in place of the healer, giving the healer time to heal itself.

Default Cover

RPG Maker by default supports covering. If you look at your states database, you will see a state called “Cover”. In its list of features, you will see a special flag called “substitute”.

coverActorConditions1

This tells the engine that the actor with this state can cover others. However, if you added this during a battle and everyone had full health, you will notice that no one actually covers anyone. Is the cover state broken?

When it comes to covering, there are two types of people: those that cover, and those who are covered. Let’s look at the latter first.

Who Can be Covered?

Before an actor can be covered, a set of conditions must be met. These are called “cover conditions”. There is a method defined in Scene_Battle called “check_substitute” that reads

b.hp < b.mhp / 4 && (!i || !i.certain?)

Which translates to

  • Target’s HP has less than a quarter of their total HP, and
  • The item (or skill) is not “certain hit” (which I guess means it doesn’t always hit its target or something)

So if everyone had full health, the first cover condition is not met, and therefore no one can be covered. This is why the cover state doesn’t do anything.

Custom Cover Conditions

What happens if you don’t want to use these conditions? Or what if you want the conditions to change depending on various factors such as whether you are wearing certain equips, or a certain state, or maybe your actor just naturally always get covered by others.

We introduce a script called Cover Conditions that extends the cover conditions concept to allow you to specify formulas of your own. These conditions can be added to actors, classes, weapons, armors, states, or enemies.

The priority of the conditions are based on the priority of the object. The order is as follows, from highest to lowest

  1. States
  2. Weapons and Armors
  3. Actors
  4. Classes

This means that if an actor has a cover condition, and it has a state that also has a cover condition, then the state’s cover condition will be checked instead of the actor’s cover condition.

Custom cover conditions behave the same way as the default cover conditions: it checks whether the target (of an action) can be covered or not.

Who Will Cover?

We now have the ability to control when someone can be covered, but we still don’t have much control over who will be covering. We have the “substitute” flag, but all that does is say “this actor will cover anyone and everyone whenever they can”

Which may be enough, but if you wanted to say “Hime will only cover Yuki”, the substitute flag wouldn’t solve the problem because it doesn’t provide any context. There isn’t really a way to check whether the target is Yuki or not; it could be some other person and you would be blindly going in to cover.

A script called Cover Target is available as an example of how you could potentially control the cover target conditions (it provides a very specific condition, and that is checking whether the target has been registered as a covered target or not), but another script can be written to generalize the “target cover conditions” (these would be different from the cover conditions that specify eligibility for being covered).

How to Cover a Specific Ally

Given only the two scripts I’ve presented, Cover Conditions and Cover Targets, we can use it to create a skill that allows Hime specifically cover Yuki when a state is added, and no one else, even if someone else has the same state. Replace the names with your own actor names as needed.

Setting up the Cover Condition

coverActorConditions2

1. Create a state that will specify the cover conditions. In our case, the state will say

<cover condition>
   true
</cover condition>

Which means when this state is applied, the battler can always be covered.

To test that this state works, first add the “substitute flag” to Hime, and then apply the state to Yuki. You should see that whenever Yuki is targeted, Hime with the sub flag will always jump in to take the hit.

Choosing the Cover Targets

coverActorConditions3

We now set it up so that Hime will only cover Yuki, even if a third actor has the same state added.

2. Create a second state that will be used to control our cover target. This will allow us to specify that only a specific target will be covered. Note-tag the second state with

<cover target>

Putting it all Together

Now you are ready.

First, create a skill that will allow Hime to cover Yuki. Second, have the skill add both states. The cover target script will register Yuki as the target to cover, and the cover conditions script will make it so that she is always eligible for covering.

coverActorConditions4

Summary

The default cover mechanic in RPG Maker provides a good base for providing cover, but it doesn’t give you any control over when or how the cover should be performed. By using scripts such as Cover Condition and Cover Targets, you can then specify when covering should occur and who you would cover.

More work can be done in the scripts to provide a completely flexible covering solution.

Spread the Word

If you liked the post and feel that others could benefit from it, consider tweeting it or sharing it on whichever social media channels that you use. You can also follow @HimeWorks on Twitter or like my Facebook page to get the latest updates or suggest topics that you would like to read about.

You may also like...

59 Responses

  1. Anonymous says:

    I put this together like you instructed and its not working. Where do you place the Substitute Flag? Is it in Actor or Class traits?

Leave a Reply

Your email address will not be published. Required fields are marked *