Enemy Aggression System

I want to have more control over which party member gets targeted and why. By default, the person with the highest Target Rate (TGR) is more likely to be the victim of the enemy's skills (unless they're AoE of course). Since there aren't many options for manipulating TGR in battle, this feature is incredibly limited.

Here's what I'm looking for.
 

  • The amount of damage dealt increases the likely-hood of an enemy targeting that character. DONE!
  • Aggression based skills that multiply the amount of aggression generated from regular skill damage.
  • Aggression based skills that generate aggression without dealing damage.
  • Aggression is individually calculated, so that only the enemy receiving the damage becomes more likely to target their aggressor. DONE!
  • Aggression based skills that reduce or resets an enemy's aggression towards all party members.
  • Healing party members generates aggression from all enemies. DONE!
And what I've tried so far.


I'm thinking about giving enemies a set of variables equal to the number of possible party members in battle. Each time a party member deals damage, 'aggression' is calculated based on the amount of damage dealt. That value is then stored within the variable pertaining to that particular party member. When the enemy is choosing a target, it will compare each aggression variable, do a bit of randomizing, and choose a target based on that. I'm not sure how I should approach this yet though.

Suggestions?
I've moved this thread to Script Request. Please be sure to post your threads in the correct forum next time. Thank you.

This can only be done by scripting, so it belongs in Script Requests.

That said - the following script isn't exactly what you need, but it should provide a base from which to develop the target scopes and filters you need:

http://forums.rpgmakerweb.com/index.php?/topic/30722-target-manager-v10-initial-release/
After reading through the script, I think I'm going to have to create an entirely new set of skills for enemies only in order begin working on it. Since you can create your own filters, there may be way around this, but I wouldn't even know where to start; the script is... complex. Maybe something like user.is_a?(Game_Enemy) to switch from player targeting options to enemy targeting?
Yes, the script is complex - no way around it if you want to have those filtering options. And I have to admit that I haven't had time to use it despite the fact that it was created after a discussion about it between me and enelvon (simply not enough time to work on my own game).

However, check the filter add-on: it already has actor_only, enemy_only, ally_only and foe_only to switch between player and enemy targeting options.

And it also should work with filters like TGR_<: or similiar - basically you should be able to use all existing actor or enemy based values for target filters.

Combining that with new values stored on enemy or actor is possible - I just don't know how much compatibility problems arise when using nasty extra stats or PK8's self-data-suite, or if it's better to request a specific script that not only defines new values but automatically stores data like damage in them.

But working from those filters onward should be easier than letting the default target manager handle it - as you said yourself, its options are very limited...
I saw a script posted on here a few months ago for a threat system which does basically exactly what you are talking about (or, as far as I can tell, it does). Maybe search back through the old posted scripts and see?

Edit: Here is the link to the script I mentioned: http://forums.rpgmakerweb.com/index.php?/topic/31138-euphoria-threat-system/?hl=%2Bthreat+%2Bsystem
 

Yes, the script is complex - no way around it if you want to have those filtering options. And I have to admit that I haven't had time to use it despite the fact that it was created after a discussion about it between me and enelvon (simply not enough time to work on my own game).

However, check the filter add-on: it already has actor_only, enemy_only, ally_only and foe_only to switch between player and enemy targeting options.

And it also should work with filters like TGR_<: or similiar - basically you should be able to use all existing actor or enemy based values for target filters.

Combining that with new values stored on enemy or actor is possible - I just don't know how much compatibility problems arise when using nasty extra stats or PK8's self-data-suite, or if it's better to request a specific script that not only defines new values but automatically stores data like damage in them.

But working from those filters onward should be easier than letting the default target manager handle it - as you said yourself, its options are very limited...
I'm slowly figuring this script out, given enough time, I'm sure I'd be able to create my own filter. I'm looking at the filters provided, and it seems that the Enemy_Only and Actor_Only filters are for skill selection. So if I were to add that to a skill, it will simply restrict the targeting to actors or enemies. That isn't a good idea if enemies and actors are using the same skills?  It seems this script is more about what the skills CAN target as oppose to who skills are used on.

For example TGR_>: Value; would simply check if TGR is greater than a specific value, and have targeting options based on that.
<Target Manager: one>
TGR_>: 1.5
</Target Manager>
This skill wouldn't be able to target anything with a TGR rating of less than 150%.

That doesn't necessary mean that I can't create a filter to suite my needs, but I'm still racking my brain over how to even approach this. There isn't an obvious way to get the skill favor one target over the other without eliminating options entirely.
 

I saw a script posted on here a few months ago for a threat system which does basically exactly what you are talking about (or, as far as I can tell, it does). Maybe search back through the old posted scripts and see?

Edit: Here is the link to the script I mentioned: http://forums.rpgmakerweb.com/index.php?/topic/31138-euphoria-threat-system/?hl=%2Bthreat+%2Bsystem

 
I've seen it before. I'm pretty sure that script replaces the TP system, which is something I need. Also, it doesn't appear to allow for individual aggression towards the player, though that's a sacrifice I may be willing to make. Replacing the TP system, and altering the UI is a bit of deal breaker for me. I'll look into it again just in case.

Edit: What does this '<=>' group of symbols mean in Ruby? I've seen it set up like: VariableA <=> VariableB, but I'm not sure what to make of it. It's the first time I've run into it.
The <=> means:

Code:
self <=> other Compares self with other and returns a positive integer if self is larger, 0 if the two are equal, and a negative integer if self is smaller.
In short.
The <=> means:

self <=> other Compares self with other and returns a positive integer if self is larger, 0 if the two are equal, and a negative integer if self is smaller.In short.
Thank you! That helps a lot.

This is what I have so far.

I'm using Enemy AI: Targeting Manipulator, and N.A.S.T.Y Extra Stats, links are in the first post.

Within N.A.S.T.Y Extra Stats I created a new stat for the actor and enemy called 'agg'.

module Z26 STATS = [:agg] #Default xstat formulas for ACTORS DEFAULT_LEVEL_FORMULA = { :agg => 0, # Actor's Aggression rating. } #Default xstat formulas for ENEMIES DEFAULT_FOR_ENEMIES = { :agg => 0, # Enemy's Aggression rating. }Within the  script, Enemy AI: Targeting Priority Manipulator I added this under line 299

when :high_agg return b.xstat.agg <=> a.xstat.aggThe note tag is <target [action_id] high_agg>

Within my custom damage formula:

a.xstat.agg += x b.xstat.agg -= x / 5Where "x" is equal to the amount of calculated damage. The enemy will now attack the party member with the highest agg stat. Whenever the enemy deals damage to a target, it reduces their aggression by 1/5 of the damage dealt. There's a lot of work to do here, but now I at least have my foot in the door. I want to take this further, but it seems my brain is fried for today. -_-

Edit: Almost forgot. To test it, I used this script call under Troops.

x = $game_actors[1]y = $game_actors[2]$game_variables[100] = x.xstat.agg$game_variables[101] = y.xstat.aggText Box: "P1 = \V[100], P2 = \V[101]"

Condition: Turn 0 + 1, Span: Turn

Edit: Then I stayed up all night because I wanted an individual aggression system.

Aggression_System1.PNG aggression_system2.PNG

There's two party members in battle. Both of them have individual Aggro ratings for each enemy in battle. Enemies will attack the person with the highest rating towards them 90% of the time, works fine with AoE attacks. Alongside individual aggro ratings, actors also have a general rating which is the sum of all aggression generated in battle, I haven't decided how to use it yet... Healing only generates general aggro since it uses the same formula as damage but doesn't have an enemy target.
Update: I've been working on the class system for my project so I kind of neglected this. The stuff on the list above still needs to be done, however, I've made enough progress to feel comfortable with this setup (a real script would still be nice). I'll explain the progress I've made thus far, below.

Within the NASTY Extra Stats script, I created seven stats for actors (and enemies just in case) to keep track of aggression generated in battle. This of course means that I can only keep track of up to six individual enemies; it's fairly easy to expand upon however.

      :agg => 0,  # Actor's Aggression rating.      :agg1 => 0,      :agg2 => 0,      :agg3 => 0,      :agg4 => 0,      :agg5 => 0,      :agg6 => 0,

Within the Targeting Priority Manipulator script, I modified the original setup to account for the new stats. It now allows the enemy's skills to target the party member with the highest aggression towards themselves, or the highest aggression in general. This potentially puts those 'AoE nuke' characters and healers in harms way.

Code:
    when :high_agg_one      x = 1+rand(9)      # x <= 8 ? b.xstat.agg <=> a.xstat.agg : a.xstat.agg <=> b.xstat.agg      case subject      when $game_troop.members[0]        x <= 9 ? b.xstat.agg1 <=> a.xstat.agg1 : a.xstat.agg1 <=> b.xstat.agg1      when $game_troop.members[1]        x <= 9 ? b.xstat.agg2 <=> a.xstat.agg2 : a.xstat.agg2 <=> b.xstat.agg2      when $game_troop.members[2]        x <= 9 ? b.xstat.agg3 <=> a.xstat.agg3 : a.xstat.agg3 <=> b.xstat.agg3      when $game_troop.members[3]        x <= 9 ? b.xstat.agg4 <=> a.xstat.agg4 : a.xstat.agg4 <=> b.xstat.agg4      when $game_troop.members[4]        x <= 9 ? b.xstat.agg5 <=> a.xstat.agg5 : a.xstat.agg5 <=> b.xstat.agg5      when $game_troop.members[5]        x <= 9 ? b.xstat.agg6 <=> a.xstat.agg6 : a.xstat.agg6 <=> b.xstat.agg6      end
    when :high_agg_all

      x = 1+rand(9)

      x <= 8 ? b.xstat.agg <=> a.xstat.agg : a.xstat.agg <=> b.xstat.agg

 

 

Enemy Notetags: <target action_id high_agg_one> and <target action_id high_agg_all>

This is added to the damage formula so that aggression is actually generated. Where 'x' is equal to the pre-calculated damage. I decided to give DPS the advantage when it came to generating aggression, but not by much. Warrior classes tend take turns faster, but generally have less damaging skills and somewhat unreliable accuracy. (CTB battle system)

    f_agro = 0 case x    when 0..5 then a.xstat.agg += 1;  f_agro = 1    when 6..10 then a.xstat.agg += 2;  f_agro = 2    when 11..15 then a.xstat.agg += 3;  f_agro = 3    when 16..25 then a.xstat.agg += 5;  f_agro = 5    when 26..40 then a.xstat.agg += 8;  f_agro = 8    when 41..65 then a.xstat.agg += 13;  f_agro = 13    when 66..105 then a.xstat.agg += 21;  f_agro = 21    when 106..170 then a.xstat.agg += 34;  f_agro = 34    when 171..275 then a.xstat.agg += 55;  f_agro = 55    when 278..445 then a.xstat.agg += 89;  f_agro = 89    when 446..720 then a.xstat.agg += 144;  f_agro = 144    when 721..1165 then a.xstat.agg += 233;  f_agro = 233    when 1166..1885 then a.xstat.agg += 377;  f_agro = 377    when 1886..3050 then a.xstat.agg += 610;  f_agro = 610    when 3051..4935 then a.xstat.agg += 987;  f_agro = 987    when 4936..7985 then a.xstat.agg += 1597;  f_agro = 1597    when 7986..12920 then a.xstat.agg += 2584;  f_agro = 2584    when 12921..20905 then a.xstat.agg += 4181;  f_agro = 4181    when 20906..33825 then a.xstat.agg += 6965;  f_agro = 6765    when 33826..54730 then a.xstat.agg += 10946;  f_agro = 10946    else      a.xstat.agg += 1771 if x > 54730    end        if b.is_a?(Game_Enemy)      case b      when $game_troop.members[0] then a.xstat.agg1 += f_agro      when $game_troop.members[1] then a.xstat.agg2 += f_agro      when $game_troop.members[2] then a.xstat.agg3 += f_agro      when $game_troop.members[3] then a.xstat.agg4 += f_agro      when $game_troop.members[4] then a.xstat.agg5 += f_agro      when $game_troop.members[5] then a.xstat.agg6 += f_agro      end    end        x

It's functional, but kinda all over the place. It'd be nice if someone used these ideas to make this into a single script. *wink* *wink*, I'd do it my self but I'm still a coding novice.

Any suggestions to improve the current setup would be appreciated!

Original thread: https://forums.rpgmakerweb.com/threads/enemy-aggression-system.41858/