MV Predetermine enemy attacks

Haven't posted on this forum in forever, so forgive me if I make a mistake.

I'd like a feature similar to Xenoblade's Visions, where if the next enemy attack would kill/severely damage anyone in your party, you'll get a warning and a chance to prevent it. (This feature would also need to be unlocked for plot reasons, so it would require some kind of toggle.)

There's a number of ways it could be implemented, but the system I want hinges on enemy attacks and targets being decided before they get a chance to execute, i.e. at the start of the player's turn.

I've seen threads that accomplish something similar to this ([1] [2]), but I've never gotten it to work and it seems very hack-y and not what I want anyway.

Given that information, I'm sure some kind of common event or plugin or algorithm could be run to see what the attack's outcomes would be, and if it would kill or severely damage anyone, it could make some kind of pop-up appear to warn the player. But before that's possible, I'd like to know if there's any existing battle engine plugins or settings that can decide what the enemy's next attack will be, let the player have their turn, and then have the enemy execute that predetermined attack.

(Also--would this screw anything else up? What problems could I possibly expect from this type of engine change?)
I can't think of any simple way to go about this. But it depends on exactly what the player's "chance to prevent it" is.

Is it just factoring into their choice of action? Is there, like, a QTE game that pops up and the target in mortal danger has a chance to avoid the skill entirely?
Yeah, it's just that the player would get to decide their party's next actions based on the warning.

(Wouldn't be opposed to a QTE either, but that would be an entirely different system, and probably not too relevant to this discussion)

EDIT: I don't know a lick of Javascript, so I have no idea how complicated this kind of change would be; if it would just take a quick shuffling of existing code or if I'm asking for a complete engine overhaul.
Okay - so the first thing is that inside BattleManager.startInput(), the party calls makeActions() before the troop does.

So your plugin would reverse the order of those two things.

Secondly, the target of the enemy's action isn't even chosen at that point. The action is, but the target of it isn't determined until it becomes an enemy's turn in battle and they choose the target immediately before starting the selected skill. See BattleManager.startAction() -> action.makeTargets()

Then there's the actual displaying of some kind of notification. This could just be a state placed on the target that has a warning icon, but if you want something fancier, it'll be more complex.

So it would require pretty substantial retooling of the default engine's battle sequence to do what you want. As I've never heard of a plugin that does this, I think you'd have to commission something.

It would be easier, although not simple, to incorporate it into the skill. You could use Yanfly's Action Sequences and SRD's QTE things (I forget the name, Timed Input?) to check whether a skill could kill its target, and if yes, pop up a QTE that would force it to miss.

I dunno if anyone else has a different thought of how to go about this.
As mentioned, I know absolutely nothing about Javascript, but I decided to at least try taking a crack at it myself. I made an empty .js plugin and copied some existing code over to tweak, and then placed it at the bottom of my Plugins list so it would overwrite everything else.

1695937514043.png


This somehow works.

I set up some Slimes to always Attack at full health, but always Guard if at 99% or lower. Then I had my party attack them first; because their health was lower than 100%, they ordinarily would have used Guard for their first turn. Instead, they used Attack, but then used Guard for their next turn. This shows that the Slimes were executing attacks that were decided before the player's turn. I can't believe this actually worked.

Of course, as you mentioned, this isn't really helpful unless the enemy's target can be predetermined as well. I've had significantly more trouble with this; I tried the same as above, and to copy what looked like the script to determine enemy targets into a space between Troop.makeActions() and Party.makeActions(), but it either crashes or doesn't give the player the chance to choose their own actions.

1695938383844.png


(I could probably keep experimenting, but admittedly, I have some schoolwork I need to do, so I wanted to post this update before I focused on that.)

Also as mentioned, this isn't even approaching the warning the player would need. Setting aside anything about a UI for now, if anyone knows how to call on the variables needed to determine if the next attack would kill a party member -- presumably by fetching the attack ID, and then running the damage algorithm for that attack against the player's and enemy's stats, but again, I don't know Javascript -- any pointers would be helpful. Maybe this could even be done with common events and script calls?

I'll edit or update with any new info I come across.
As mentioned, I know absolutely nothing about Javascript, but I decided to at least try taking a crack at it myself. I made an empty .js plugin and copied some existing code over to tweak, and then placed it at the bottom of my Plugins list so it would overwrite everything else.

View attachment 278279

This somehow works.

I set up some Slimes to always Attack at full health, but always Guard if at 99% or lower. Then I had my party attack them first; because their health was lower than 100%, they ordinarily would have used Guard for their first turn. Instead, they used Attack, but then used Guard for their next turn. This shows that the Slimes were executing attacks that were decided before the player's turn. I can't believe this actually worked.

Of course, as you mentioned, this isn't really helpful unless the enemy's target can be predetermined as well. I've had significantly more trouble with this; I tried the same as above, and to copy what looked like the script to determine enemy targets into a space between Troop.makeActions() and Party.makeActions(), but it either crashes or doesn't give the player the chance to choose their own actions.

View attachment 278281

(I could probably keep experimenting, but admittedly, I have some schoolwork I need to do, so I wanted to post this update before I focused on that.)

Also as mentioned, this isn't even approaching the warning the player would need. Setting aside anything about a UI for now, if anyone knows how to call on the variables needed to determine if the next attack would kill a party member -- presumably by fetching the attack ID, and then running the damage algorithm for that attack against the player's and enemy's stats, but again, I don't know Javascript -- any pointers would be helpful. Maybe this could even be done with common events and script calls?

I'll edit or update with any new info I come across.
The issue with the next bit is that you not only need to determine the action's targets at the beginning of the turn, but also calculate the damage the attack will actually do. Otherwise, if you just run the damage algorithm, assuming there's any kind of variance you may end up having an initial calculation that does/doesn't kill the target and an actual calculation that doesn't/does, meaning your warning would either be unnecessary or absent.
The issue with the next bit is that you not only need to determine the action's targets at the beginning of the turn, but also calculate the damage the attack will actually do. Otherwise, if you just run the damage algorithm, assuming there's any kind of variance you may end up having an initial calculation that does/doesn't kill the target and an actual calculation that doesn't/does, meaning your warning would either be unnecessary or absent.
There's that, although the OP did say "kill/severely damage," so anything in that realm is probably okay? The real trick is the fact that missing and evading is all a part of that method.

So not only might you not end up doing enough damage to kill the target you've said could die, you might not even hit them unless you further pull apart and modify the attack resolution process.

@Wrongful I dunno - you do you, but I don't think it makes sense to try to modify things (especially a complex system like this) if you don't know anything about coding.

The odds of you accidentally happening to type the correct letters in the exact sequence you need to achieve what you want are asymptotic to zero. I think you'd be better off either spending that time doing tutorials/courses so you do know what you're doing, or saving up dollars to commission Trihan or somebody 😉
That's probably for the best, unfortunately. I may just take your earlier suggestion and incorporate forecasting into certain enemy skills (somehow) -- probably focusing on stronger Boss skills, at least giving the illusion of "prediction." Thank you all for the thoughts and help anyway 🙂

Original thread: https://forums.rpgmakerweb.com/threads/predetermine-enemy-attacks.161556/