How would you implement saving throws? [D&D style mechanic]

I am curious because I have MDF-based saving throws planned for my first project, and am getting into skills development now, so I have only just begun to try and implement them.

I have a couple of thoughts of my own, but I am running into a few snags.

The first is to adapt this YouTube tutorial on roll-to-hit mechanics, which creates two separate skills (and several separate common events) for ability checks and effects, but as I had discovered prior to posting this older thread, as far as the roll-to-hit example goes, when an enemy is reduced to 0 HP and a new enemy is autotargeted on that turn, the new enemy’s ID comes up as 1 and its Armor Class is either 0 or whatever default AC has been specified.

Screenshot 2023-07-01 at 12.05.30 AM.png


Screenshot 2023-07-01 at 12.10.08 AM.png


(Some screenshots from the Roll-to-Hit tutorial.)

That is to say, it works for VisuStella's STB system, where attacks happen one by one, but it won't work in an Active Battle System (or even in the default Turn Based System). In the case of saving throws, this would mean an automatic failed saving throw on the part of an autotargeted creature whenever the player had targeted a creature which was KO’d before the spell could take effect.

Since I decided to use @ATT_Turan's much more elegant custom hit formula plugin, which doesn't seem to be compatible with VS STB, I am back at square one with my initial question in that thread, which was, "How do I make it so that the battle system can check a target variable ... on the fly"? Or more precisely, how do I check the MDF of an autotargeted foe?

@Archeia and @caethyril's Script Calls spreadsheet has the following to say about the matter:

"MZ offers Control Variables > Game Data > Last for some action-related data. This might not update early enough, e.g. target index updates immediately after the action is applied (damage/heal) after the animation."

I have an intuition that this can be handled with VisuStella’s <JS Pre-Damage>, etc. notetags, so if this needs to be moved from MZ Support to Plugin Support on that basis, my apologies.

I understand much more about Troop events now, and the Battle System, but I am still not sure how to proceed. My second thought is to replace MDF with Magic Evasion (MEV), but won't that only work for spell attacks (a different breed from saving throw mechanics)?

I am just thinking very generally about how other users would approach the problem of spells which target one or several targets, which would require the targets to make a saving throw to avoid or mitigate the effects of the spell, such as damage. How would you approach the issue?
I am going to bump this with the incremental amount of progress that I have made. I am using @ST0RMTiger's SelectMultipleTargets plugin, so this thread may have to get moved.

My thought is to set up at least one skill, if not two (one for the saving throw, and a second as a forced action on the condition of a failed saving throw). Here's a screenshot of where I'm at so far, with ST0RMTIGER's <multipleDifferentTargets: x> notetag.

Screenshot 2023-07-04 at 4.38.00 AM.png


Here's where it gets tricky. I haven't made much progress, because as you can see, the only way AFAICT to call the enemy targeted is the Last Target Enemy Index command. I will return to this screen after taking a look at the two other common events which I have 'modularized' (they would be called somewhere within this common event, as well as within any common event involving saving throws).

Screenshot 2023-07-04 at 4.40.53 AM.png


The third piece of the puzzle is the bonuses to the spell save difficulty check (DC), which are (1) the proficiency bonus (which scales based on level), and (2) the MAT modifier of the caster. I think I have this sorted out for my purposes in the common event shown below.

Screenshot 2023-07-04 at 4.44.48 AM.png


Now, here's the problem: I know I am definitely doing something wrong in the next screenshot, in fact I know *what* I'm doing wrong (Enemy ID checks the Enemy database, so Enemy ID 1 is 'Goblin', not the troop leader), so it would make more sense to cut out the middleman and change the Control Variables for Variable #0015 (through 23, theoretically) in the first screenshot to the MDF of troop members 1-9. But like I said at the outset, I am confused as to how I can identify the target of the spell in a conditional branch.

Screenshot 2023-07-04 at 5.05.25 AM.png


That's my progress so far. It's barely any meaningful work, honestly it's a mess, and I'm sure someone will take the time to tell me I'm overcomplicating things. I've looked at the code in ST0RMTIGER's plugin but I'm not making any headway there. I'd appreciate feedback.
If you're using VisuStella's plugins I suspect you're making this way more complicated than it needs to be.

What are your actual requirements for the roll and its result?
@Trihan, in order to count as a success, the roll needs to meet or beat a difficulty check whose value equals 8 + the actor's proficiency bonus + the actor's MAT modifier (the MAT score's distance from 10, divided by 2) as shown in screenshot #3. I have those formulae devised and could swap out the actor calls for a.level and a.mat easily.

The effects of the spell typically only occur on a failure, or else there will be a case where the target takes full damage on a failure and half damage on a success.

Even if I can manage to sort this out using VisuStella plugins (which would be ideal, given the common event bloat that this projected method would entail), there are a few spells that are complicated enough to warrant a common event. Take, for example, my rendition of Confusion:

Five creatures must succeed on a MDF saving throw when you cast this spell or be affected by it. An affected target must roll 1-10 at the start of each of its turns to determine its behavior for that turn. From 1-6, the creature doesn’t take actions this turn. From 7-8, the creature uses its action to make a melee attack against a randomly determined creature. From 9-10, the creature can act normally. At the end of each of its turns, an affected target can make a MDF saving throw. If it succeeds, this effect ends for the target. When you cast this spell using a spell slot of 5th level or higher, one additional creature can be targeted for each slot level above 4th.
Okay, and if I'm reading your event correctly you're using level as a stand-in for proficiency bonus?

Are you using the Enemy Levels plugin, then?
Okay, and if I'm reading your event correctly you're using level as a stand-in for proficiency bonus?

Are you using the Enemy Levels plugin, then?

I'm using Math.round(.25*(a.level)+1.25) as a pretty accurate estimation of proficiency bonus, of which level plays a part, yes.

I was actually planning on using the Enemy Levels plugin a while back, when I bought the 8 Waves Collection, but forgot I was going to implement it. I'm unclear on whether I will implement it, but clearly defined saving throws are more important to my game.

For simplicity's sake I was planning on dropping proficiency from the saving throw formula itself, and just applying it to the spell save DC instead. You could say I want to see people fail, but that's not quite it. I want to see them succeed. Succeed by others' failures.

I don't know how LUK will affect these formulas, either, since I was intending to boost the default LUK state chance by a significant amount. I hope that isn't introducing too many variables. Maybe depending on how saving throws are designed to work, the LUK state chance rule won't even hold.
In the skill notetags for VS Skills and States Core, you should be able to reference "targets". And if not, you could use an action sequence.
I’ll play around with that today, see if I can get a nice Acid Splash effect. You know, I’ve even read that documentation closely and it didn’t occur to me. Mostly because I was thinking I couldn’t handle this in notetags, thought it had to be in a common event. Should be smooth sailing for all skills if I can get this to work even once.

I plan to use Action Sequences for the half damage/full damage effect spells such as Fireball. Thank you!

EDIT: With @Trihan's guidance I was able to set up exactly the kind of saving throw mechanic I was looking for in this thread. Feel free to use for your own project, no credit required (though, if you're adopting proficiency bonus and spell save DC, you will want to look into the D&D SRD under Creative Commons in order to give proper credit where credit is due. [EDIT: See below for further improvements.] Without further ado, I present Acid Splash:

JavaScript:
<JS Pre-Apply>
const proficiencyBonus = Math.round(0.25 * user.level + 1.25);
console.log(proficiencyBonus);
const intBonus = (user.mat - 10) / 2; //this can be matBonus, wisBonus, or whatever you want to call it
console.log(intBonus);
const dc = 8 + proficiencyBonus + intBonus;
console.log(dc);
const roll = Math.randomInt(20) + 1 + ((target.agi - 10) / 2); //replace agi with whatever stat you wish
console.log(roll);

if (roll < dc) {
var subject = user;
subject.forceAction(XX, target); //where XX is a second skill that applies intended effects of the spell
BattleManager.forceAction(subject);
}
</JS Pre-Apply>

Screenshot 2023-07-04 at 10.13.04 AM.png


Screenshot 2023-07-04 at 10.13.14 AM.png


I suppose I should add that you can easily hide the Damage skill inside and outside of battle using VisuStella notetags.

Required plugins: VisuStella BattleCore, ST0RMTIGER's SelectMultipleTargets

EDIT: Well, this is happening...



Goblin B is targeted, but Goblin A takes the damage. So, this isn't fully functional yet. But I will keep you all updated.
Have you tried changing the order of my plugin and the STB in your plugin manager? A few people said in the thread that it's compatible with the basic Battle Core, I think, and I don't see off the top of my head why the STB would overwrite that specific code.

Unless it entirely rewrites Game_Action.apply() without any aliasing.
Have you tried changing the order of my plugin and the STB in your plugin manager? A few people said in the thread that it's compatible with the basic Battle Core, I think, and I don't see off the top of my head why the STB would overwrite that specific code.

Unless it entirely rewrites Game_Action.apply() without any aliasing.
I do use it alongside BattleCore, but above it, per others' recommendations. So I can't change the order, since VisuStella's plugin order is locked. But it's funny that you mention rearranging plugins, that's exactly what I was just doing since the fireworks were keeping me up, so I'd be happy to try it out.

Any idea why the 'target', Goblin B, becomes the troop leader, Goblin A?
Any idea why the 'target', Goblin B, becomes the troop leader, Goblin A?
Your forceAction() call is incorrect. It doesn't take a battler as an argument, it takes an index.

So this:
Code:
subject.forceAction(XX, target);

should be:
Code:
subject.forceAction(XX, target.index());

For what it's worth, I don't think I would go the route of having an entire separate skill that you force depending on the result of the saving throw...I'd just put it into an action sequence or a JS Post-Damage as User notetag. I think your route can absolutely work, but might be overcomplicated leading to potential bugs.
Your forceAction() call is incorrect. It doesn't take a battler as an argument, it takes an index.

So this:
Code:
subject.forceAction(XX, target);

should be:
Code:
subject.forceAction(XX, target.index());

For what it's worth, I don't think I would go the route of having an entire separate skill that you force depending on the result of the saving throw...I'd just put it into an action sequence or a JS Post-Damage as User notetag. I think your route can absolutely work, but might be overcomplicated leading to potential bugs.
Yes, that's it! Thanks much.

That's sound advice. But I am having trouble with calling the use of the skill (moving to Pre-Damage) within the same skill. How does one do that?
That's sound advice. But I am having trouble with calling the use of the skill (moving to Pre-Damage) within the same skill. How does one do that?
Let's say you're casting Tasha's Hideous Laughter.

You have the Laughter state that has the Cannot Move restriction on it - let's say that's state ID 42.

In your skill, you would just put:
Code:
<JS Post-Damage as User>
if (Math.randomInt(20)+1+target.whatever < 12+user.whatever)
    target.addState(42);
</JS Post-Damage as User>

You'd replace the "whatever" with whatever parameter or function you're using to determine attribute bonuses and all that stuff. So if their roll plus bonuses doesn't meet the spell's DC plus bonuses, you apply the state. Boom, two lines of code.

The really long code you have above and the whole notion of using extra skills via force action just seems like over-complicating it to my viewpoint.

You can do the exact same thing in a damage formula. Let's say you're casting...dunno, a little acid orb that does 1d6 damage, reflex save half.
Code:
let dam=Math.randomInt(6)+1; dam = Math.randomInt(20)+1+target.whatever < 11+user.whatever ? dam/2 : dam; dam
Let's say you're casting Tasha's Hideous Laughter.

You have the Laughter state that has the Cannot Move restriction on it - let's say that's state ID 42.

In your skill, you would just put:
Code:
<JS Post-Damage as User>
if (Math.randomInt(20)+1+target.whatever < 12+user.whatever)
    target.addState(42);
</JS Post-Damage as User>

You'd replace the "whatever" with whatever parameter or function you're using to determine attribute bonuses and all that stuff. So if their roll plus bonuses doesn't meet the spell's DC plus bonuses, you apply the state. Boom, two lines of code.

The really long code you have above and the whole notion of using extra skills via force action just seems like over-complicating it to my viewpoint.

Well, the point of using console.log at this point is just for sanity checks. I need to check my own work because as you can see I'm still in a stage where there are a lot of errors. I'm aware that that's how you'd apply a state, but that wasn't my question.

You can do the exact same thing in a damage formula. Let's say you're casting...dunno, a little acid orb that does 1d6 damage, reflex save half.
Code:
let dam=Math.randomInt(6)+1; dam = Math.randomInt(20)+1+target.whatever < 11+user.whatever ? dam/2 : dam; dam
This doesn't answer my question either, I don't think, because it doesn't specify what element/type of damage is being inflicted. Unless that is somehow pulled from the skill parameters?
I'm aware that that's how you'd apply a state, but that wasn't my question.
Then please restate your question. You asked something about "calling the use of the skill" which aren't words that mean anything to me 😉

I demonstrated how to make your skill do something when the target fails their saving throw, entirely contained within one skill.

This doesn't answer my question either, I don't think, because it doesn't specify what element/type of damage is being inflicted. Unless that is somehow pulled from the skill parameters?
...yes?
Screenshot 2023-07-05 124254.png
Then please restate your question. You asked something about "calling the use of the skill" which aren't words that mean anything to me 😉
Forgive me, that is what I said, but I was referring to the same skill we had been discussing, Acid Splash, which does HP damage.
OK, that solves it. Thank you for your time and patience.

EDIT: I noticed a small problem with @ATT_Turan's damage formula, it still used 'user' and 'target' from the VisuStella variables instead of 'a' and 'b', so here is my rendition of Acid Splash, which adds a LUK modifier into the equation on both sides and which deals 0 damage on a success:

Code:
let dam=Math.randomInt(6)+1; dam = Math.randomInt(20)+1+((b.agi-10)/2)+((b.luk-10)/2) < 8+(Math.round(0.25 * user.level + 1.25))+((a.mat-10)/2)+((a.luk-10)/2) ? 0 : dam; dam

For something like Thunderwave, with reflex save half damage, you could put:

Code:
let dam=Math.randomInt(6)+Math.randomInt(6)+2; dam = Math.randomInt(20)+1+((b.mdf-10)/2)+((b.luk-10)/2) < 8+(Math.round(0.25 * user.level + 1.25))+((a.mat-10)/2)+((a.luk-10)/2) ? dam/2 : dam; dam

Feel free to use for your own project, no credit required (though, if you're adopting proficiency bonus and spell save DC, you will want to look into the D&D SRD under Creative Commons in order to give proper credit where credit is due.

MAJOR DISCLAIMER: This method won't extend to circumstances where one damage roll is made for multiple targets AFAICT.

Original thread: https://forums.rpgmakerweb.com/threads/how-would-you-implement-saving-throws-d-d-style-mechanic.158859/