Thursday, March 20, 2014

Enemy AI : Targeting Priority Manipulator

The default VX Ace's enemy targeting behavior just pick a random target for any actions.
This script adds some AI targeting priority. With this script, the enemies become able to pick a target based on the action specific priority.

Download the script here. You might also want to look at the patches below.
Installation

Put this script below ▼ Materials and above ▼ Main Process.

Usage

In an enemy notebox, you can add some tags.
<target [action_id] [shortcut]>
where [action_id] corresponds to the enemy's action list, and [shortcut] corresponds to one of the implemented targeting priority method.

Example:
<target 1 high_hp>
This will make the enemy target the battlers with the highest HP value when using action number 1 (by default Attack).

<target 2 low_hp_rate>
This will make the enemy target the battler with the lowest HP percentage when using action number 2. If the action no. 2 is set to Heal, the enemy will proceed to heal its ally with the lowest percentage of health.

Available targeting shortcut is as follows:
low_hp
high_hp
low_hp_rate
high_hp_rate
low_mp
high_mp
low_mp_rate
high_mp_rate
low_tp
high_tp
low_tp_rate
high_tp_rate
self
not_self

If you want to make your own targeting condition, use
<target eval [action_id]>
[eval]
</target eval>
where [eval] is a ruby expression that takes returns -1, 0, or 1.
In the eval, a and b denotes the battlers that would be sorted.

For example, to make the enemy prioritize Eric when doing its ultimate skill, the tag will be
<target eval 8>
if a.name == "Eric"
-1
elsif b.name == "Eric"
1
else
a.hp <=> b.hp
end
</target eval>


Do note that target selection is done at the start of the turn, like actors. The enemy will not suddenly change target mid-turn, for example if its target had already healed.
Also, TGR have no effect on acquiring target.

Patches:
There is a patch for Schala Battle System here.

4 comments:

  1. Is there a possibly modification of this script that would give party members on auto-battle have the same characteristics of being able to target?

    Thanks,

    MinisterJay

    ReplyDelete
    Replies
    1. It can be done, yes. The logic is the same.
      It's been a long time since I did anything with rpg maker though (don't even have one installed on my machine) so me playing with script is kind of impossible right now.

      Delete
  2. Can I use this in a commercial game? You asked to be contacted first, so I want to respect that wish.

    ReplyDelete
    Replies
    1. Yes, you can. I just want proper credit and to be informed of the title (So I may be able to purchase it if I want to :) )

      Delete