MV Adding TGR to self based on damage dealt (w/ YEP_BattleAICore)

Hi everyone, thanks for checking this out.

I have an addon to YEP_BattleAICore (by Ramza) that uses highest TGR in monster AI for a proper threat eval. i.e. Random 37% : SKILL 1683, Highest TGR I use in an example monsters AI.

That seems to work fine, however, of course, I want to be able to change TGR rate dynamically so enemies can recognise threat a bit better.

I'm thinking I need a hidden passive status effect applied to Player Actors that has a Custom Establish Effect that 'buffs' TGR based on (value) from damage dealt or healed, but my brain is derping on the implementation of that. Can someone help me out on that?

Also, most of my attacks will use this rather than random targets; but another thing would be great for more versatility: and that would be making Random target also respect TGR (i.e. by pooling all actor TGR, and then selecting a random based on those values relative to one another), could have sworn I remember a thread that ATT_Turan helped someone implement that but can't for the life of me find it any more after 40 mins looking googling it.

Thanks again.
Hmmm, not sure I understood everything, but is there a reason you don't want to use their aggro plugin for stuff like that?
You're right, I did some years ago, but I have a better solution now than that post.

For the first part, I'd say look up a Dynamic Traits plugin (there are a few, I think Shaz and Eli/Hakuen Studio have them) and tie it in with Yanfly Buffs & States notetags to increase tgr every time the state is applied, then remove the state at the end of battle.

As for the Battle A.I. part, changing line 1194 to read:
Code:
    var target = group.randomTarget();
should cause the random targeting to respect the tgr trait. You may also want to do line 938
Code:
    var randomTarget = group.randomTarget();

is there a reason you don't want to use their aggro plugin for stuff like that?
Assuming you mean Yanfly's Taunt, there are no degrees involved in that - a battler has a taunt status or doesn't. In order to use that for what the OP is discussing, it would be more complicated wherein every action would have to check the entire party to see if that actor should have the highest value, remove Taunt from everyone else, and apply it to them.

It also isn't as flexible to be honored or ignored within a single Battle A.I. condition, you'd have to go around flagging all the skills you wanted to Bypass Taunt.

Edit: I see Olivia does have an Aggro Management plugin for MV, but I couldn't recommend anyone spend money on her plugins when there have been numerous instances of reported bugs and she doesn't support her products at all. And it's just not that difficult to make this system using free, unobfuscated plugins.
Ah okay cool yeah I thought Yanfly had aggor control since VisuStella has one, but yeah it was the Olivia plugin.
Ah okay cool yeah I thought Yanfly had aggor control since VisuStella has one, but yeah it was the Olivia plugin.

Yeah, I did buy one Olivia plugin on a 50% off at Xmas (Visual Battle Effects one) and it basically doesn't do alot for me since I've upgraded to pixi 5, which I was kind of cross about since it's unsupported. I keep it basically because the state apply icons are alright.

Therefore I was wary about using that aggro plugin especially given my other small battle modifications. I am already using Taunt as well (actually each tank is different in game, one taunts, one substitutes, one massively buffs Defend and gives it to people, one siphons ally damage to themselves, one reduces damage for rows, etc.) but I want to also build the system that works besides those mechanics.

You're right, I did some years ago, but I have a better solution now than that post.

For the first part, I'd say look up a Dynamic Traits plugin (there are a few, I think Shaz and Eli/Hakuen Studio have them) and tie it in with Yanfly Buffs & States notetags to increase tgr every time the state is applied, then remove the state at the end of battle.

As for the Battle A.I. part, changing line 1194 to read:
Code:
    var target = group.randomTarget();
should cause the random targeting to respect the tgr trait. You may also want to do line 938
Code:
    var randomTarget = group.randomTarget();
Thanks, I do have Eli Dynamic Parameters in my box of unused things, and I forgot about it.

Hm, so looking at the documentation, to clarify, I assume I should create a dynamic parameter, add <DynParams: TemplateNameX> to a state, and then use state counters with a yanfly state (like I do with my burning and poison stacks), but with an unlimited duration/stack size and remove at battle end. That sound correct?

Any idea what sort of formula in the dynamic parameter setup that would retrieve the damage just dealt? Something like Math.Floor(this.value / 100). No that can't be right, this probably can't recover that value in a state. Hmm...

Also, someone also remind me, the default TGR value is 1, right? So I actually want to like /1000 and not flooring it, so that on the damage so TGR is not going from like 1 to 345 from a single strike, but to 1.34 instead. Or have I just pulled that idea from my butt?
Hm, so looking at the documentation, to clarify, I assume I should create a dynamic parameter, add <DynParams: TemplateNameX> to a state, and then use state counters with a yanfly state (like I do with my burning and poison stacks), but with an unlimited duration/stack size and remove at battle end. That sound correct?
No, looking again at how you want to do this, I wouldn't recommend that.

If you want it based off damage, you can have a passive state on each actor that has:
Code:
<Custom Battle Effect>
user.damageDealt = 0;
</Custom Battle Effect>

<Custom Confirm Effect>
user.damageDealt += value;
</Custom Confirm Effect>

Then you set up the dynamic trait plugin parameter to reference user.damageDealt (or this.damageDealt or whatever Eli's instructions are to reference the actor, I haven't used the plugin).

Also, someone also remind me, the default TGR value is 1, right? So I actually want to like /1000 and not flooring it, so that on the damage so TGR is not going from like 1 to 345 from a single strike, but to 1.34 instead. Or have I just pulled that idea from my butt?
Yes, default is 1 so whatever calculation you do in the plugin parameter would divide damageDealt by...whatever amount. I don't know what kind of damage your game does.
As for the Battle A.I. part, changing line 1194 to read:
Code:
    var target = group.randomTarget();
should cause the random targeting to respect the tgr trait. You may also want to do line 938
Code:
    var randomTarget = group.randomTarget();
Actually this breaks, now I've implemented it (didn't notice until now as I was doing tests on a dummy with no AI).
1775399390252.png


Ramza's TGR addition does alias that method, so I tried commenting it out it there as well, but that just changes the error:
1775399547927.png

Also tried only replacing 1194, rather than both lines, but the same error occurs.

(note: line numbers might be off by 1-2 lines, I commented out the old entries rather than replace).
Actually this breaks
Ah! That's why I did it the way I did in the original post you referenced - Yanfly isn't passing in the unit, but an array of battlers to consider as targets.

So do it the way I said there...paste this into a text editor, save as a *.js file, and include as a plugin below Battle A.I.

Code:
AIManager.setRandomTarget = function(group)
{
    let tgrRand = Math.random() * group.reduce((acc, val) => acc + val.tgr, 0);
    let target = null;
    group.forEach(member =>
    {
        tgrRand -= member.tgr;
        if (tgrRand <= 0 && !target)
            target = member;
    });
    this.action().setTarget(target.index())
};
Ah! That's why I did it the way I did in the original post you referenced - Yanfly isn't passing in the unit, but an array of battlers to consider as targets.

So do it the way I said there...paste this into a text editor, save as a *.js file, and include as a plugin below Battle A.I.

Code:
AIManager.setRandomTarget = function(group)
{
    let tgrRand = Math.random() * group.reduce((acc, val) => acc + val.tgr, 0);
    let target = null;
    group.forEach(member =>
    {
        tgrRand -= member.tgr;
        if (tgrRand <= 0 && !target)
            target = member;
    });
    this.action().setTarget(target.index())
};
Thanks for that. I couldn't find that thread again to save my life. 😅

Now for the fun part, trying to figure out how I can monitor TGR in battle for debug. Maybe I can get the state to check to compare TGR among the party and display an animation if it's the highest. I'll likely need something like that to help inform the player in any case.
You can give actors a passive state with
Code:
<Custom Passive Condition>
let highest = user;
for (let i = 0; i < $gameParty.aliveMembers().length; i++)
{
    if ($gameParty.aliveMembers()[i].tgr > highest.tgr)
        highest = $gameParty.aliveMembers()[i];
}
condition = highest == user;
</Custom Passive Condition>

Then either give that state an icon to be seen or a state overlay animation as you like.

You could make that more efficient by putting the loop into a custom action end notetag then just doing the equality check for the passive condition, but then you'd have to externally initialize it somehow - like with a base troop event. I don't expect the above will cause any performance issues.
You can give actors a passive state with
Code:
<Custom Passive Condition>
let highest = user;
for (let i = 0; i < $gameParty.aliveMembers().length; i++)
{
    if ($gameParty.aliveMembers()[i].tgr > highest.tgr)
        highest = $gameParty.aliveMembers()[i];
}
condition = highest == user;
</Custom Passive Condition>

Then either give that state an icon to be seen or a state overlay animation as you like.

You could make that more efficient by putting the loop into a custom action end notetag then just doing the equality check for the passive condition, but then you'd have to externally initialize it somehow - like with a base troop event. I don't expect the above will cause any performance issues.
Thanks again. That works fine and it does show up in YEP_InBattleStatus... except it seems like MOG_Battlehud doesn't display the icon. It cycles between blank and other statuses if present:
ThreatIcon.gif

Which is a bit weird, but probably not something we can do anything about so don't worry about it (Battlehud is the bane of my existence but it's by far the best of it's kind for a front-view system to look distinct and pretty with my busts).

Thankfully, I've also added a custom action end that just plays an animation popup with "Highest Threat" on it (I do this for a fair few things to communicate guard, defensive support, evasion, etc.) so I guess that will do.

I do use State Overlay animation and could use that... but the problem for that is that it's basically locked into showing our current row (can be seen as Vanguard above, that's a single frame of animation on endless loop) and that's something I don't want to be cycling like status icons do since it's the only way we can express that information in front-view (yes there is a extension to show multiple overlay animations at once, but it also forces animations to below my battlers, z-wise, and cannot be raised from there in my attempts, which makes it unusable, sadly).

I did have the idea to possibly mod InBattleStatus to show TGR (or somehow use ExtMsgPack2's \atrg[x] in the text, though I can't declare THIS/USER in an escape code lol so thats probably a silly idea).
So to help those also trying to do this kind of aggro system later, here's the full summary so far:
Since this passive state can otherwise appear outside of battle, I also slightly modded the "highest threat" state to the following:
Code:
<Custom Passive Condition>
if ($gameParty.inBattle()){
let highest = user;
for (let i = 0; i < $gameParty.aliveMembers().length; i++)
{
    if ($gameParty.aliveMembers()[i].tgr > highest.tgr)
        highest = $gameParty.aliveMembers()[i];
}
condition = highest == user;}
else {condition = false;}
</Custom Passive Condition>

<Custom Action End Effect>
target.startAnimation(29);
for (var i = 0; i <= $gameParty.members().length; i++) {
$gameParty.members()[i].refresh();
}
</Custom Action End Effect>
The animation is a pop-up showing "Highest Threat!". The Refresh was me trying to get MOG_Battlehhud to recognise it, but sadly it still doesn't work, will try other things for this.

Then the actual aggro counting state has:

Code:
<DynParams: Aggro>
<Custom Battle Effect>
user.damageDealt = 0;
</Custom Battle Effect>
<Custom Confirm Effect>
user.damageDealt += (value);
</Custom Confirm Effect>
And the Dynamic Param is setup as such:
1775545181712.png

Then we give all actors these two passive states by default.
I'm going to pop in here again to say I found a fix for the notorious "no state counters and no state durations" for MOG_BattleHUD (as well as remove the need for WR_MOG fix entirely)!

This is all thanks to google randomly pulling up this result from a Japanese page where the amazing hero jie119168 has built out a full compatibility fix here: https://rpg.blue/thread-491922-1-1.html

Requires taking a hacksaw to your MOG_BattleHUD and inserting many new parts, as well as entirely replacing the updatestates 1 & 2 methods (I translated the instructions as I went, they make sense). DO NOT use a full-page translation, however, as it randomly breaks parts of the code.
1776035732831.png

State Durations! State Counters from Yanfly!! 😂
Moreover, even works fine with Line Mode and with Passive States.

Original thread: https://forums.rpgmakerweb.com/threads/adding-tgr-to-self-based-on-damage-dealt-w-yep_battleaicore.183134/