How can I alter the status infliction formula?

ok I got some semi-related questions.

1) how can i edit the status infliction formula? I know by default it isnt editable, but i also have access to the yanfly plugins. I know the Hit Accuracy plugin makes custom accuracy formulas possible, but i think that they by default use agility to derive hit rate, and I wanted to use Luck instead, and be able to edit how much Luck is weighted in that formula

the goal would be making a skill that has a custom accuracy formula that compares relative luck stats of the targets without checking agility, but has a base 100% chance to inflict the target with the status that it carries if it hits. So even if the skill hits, it can get resisted if the target's status defences are high, but also it makes it much more consistent when you want to inflict a status on something because you can buff your luck and know what it does in terms of status infliction.

I mainly am asking this because i dont know if the damage box would just be able to do that comparison by itself. set it to magic attack or certain hit, put an if statement in the damage box where it compares the two combatant's luck, and if (a.luck + (random number from 0-5) >= b.luck + (random number from 0-5)) then inflict status x, but if not display a miss. idk.

2) related, how would I make a kind of curated silence status? say i have skills divided into several categories, A, B, and C, and party members have access to skills from multiple categories. They're all under the Skills Type, but the default silence-like status just blocks access to Skills from the menu. What i'd like is a way to have someone inflicted with Seal A Skills, and they can open up their skills menu but can only actually use category B or C (or etc) skills. Basically im trying to reverse engineer the bind statuses from the Etrian Odyssey games.

(i tried yanfly's multi-type skills plugin, but that didnt work. it seems Seal just checks for the command on the menu, rather than for individual skills in the skill window of that type.)

3) also also related- how would one make it so that a target can only be afflicted with either Poison or Blind or whatever, but only one at a time? Notably, there'd be other statuses on them just passively, this would refer to a particular type of status. I'd call it an Affliction, to separate it from other buffs and debuffs im using states for.

thanks!
1) how can i edit the status infliction formula? I know by default it isnt editable
That's not really true - the entire code for the engine is there in your js folder, so technically everything is editable. Just not necessarily in an interface that puts it into English rather than JavaScript 😛

the goal would be making a skill that has a custom accuracy formula that compares relative luck stats of the targets without checking agility
So it's a little hard to give you a specific example because you don't say what that luck comparison would be, but you'd take the Hit Accuracy Accuracy Formula parameter and add a custom exception for your specific skill.
Code:
skill.id==X ? luck formula : skillHitRate * (userHitRate - targetEvadeRate)
where X is the ID of this luck-based skill. And then you need to make "luck formula" be something that evaluates out to a decimal chance (with 1.0 being a guaranteed hit).

I mainly am asking this because i dont know if the damage box would just be able to do that comparison by itself. set it to magic attack or certain hit, put an if statement in the damage box where it compares the two combatant's luck, and if (a.luck + (random number from 0-5) >= b.luck + (random number from 0-5)) then inflict status x, but if not display a miss. idk.
So...for one thing, I'm now confused about how you want this to work. In your prior chunk, you talked about luck affecting the skill's chance to hit but then the chance to get the state would be affected by the target's state rate as normal.

But now you're describing disregarding that and having the entire state application based on this randomized comparison of luck. So I'm not sure exactly what you're going for.

As far as the damage formula portion, that happens when a skill hits. So it's too late to change it into a miss or evasion at that point. The most you can do is make it hit for 0 and do nothing else, which can perhaps not look great to the player.

2) related, how would I make a kind of curated silence status? say i have skills divided into several categories, A, B, and C, and party members have access to skills from multiple categories. They're all under the Skills Type, but the default silence-like status just blocks access to Skills from the menu. What i'd like is a way to have someone inflicted with Seal A Skills, and they can open up their skills menu but can only actually use category B or C (or etc) skills. Basically im trying to reverse engineer the bind statuses from the Etrian Odyssey games.
I would do this with the Custom Requirement notetag from Yanfly's Skill Core. Give skills the notetag
Code:
<Custom Requirement>
value=!user.isStateAffected(x);
</Custom Requirement>
where x is the ID of the state that will block that skill. Then, when afflicted with the state, that skill will be greyed out.

3) also also related- how would one make it so that a target can only be afflicted with either Poison or Blind or whatever, but only one at a time?
Put traits on those states that give state resistance to the other affliction states.
thanks! this is very very helpful!
the custom requirement thing is especially helpful, thank you.

to be more specific with the infliction formula, i kinda want to reverse engineer some aspects of the Etrian games, so I actually looked and found how they implement their status ailment formula. its like this :

Spoiler: credit to DrFetus from gamefaqs
(taken from etrian 5, which was probably reused from nexus. ill link the txt file i got this from)

Infliction Rate
===============
aScore = (aStat * 2) + aLUC

If the skill being cast is a STR-based attack, aStat = STR.
If the skill being cast is a INT-based attack, aStat = INT.
Else, aStat = LUC.

A = [(aScore + 76.5) / ((dLUC * 3) + 76.5)] * 10

IR = Skill's infliction rate

If A <= 2, B = IR
If A > 2 & A < 50, B = IR * A
If A >= 50, B = IR * 50

C = B * Resistance * Difficulty Factor * Modifiers

Resistance = Base Resistance + Accumulative Resistance
Difficulty Factor for players is 1 on Advanced, and 1.2 on Basic. For enemies, this is 1 on Advanced and 0.8 on Basic.

If C is greater than 1500, then set it to 1500.
Then roll a number between 0 and 1000.
If that number is lower than C, then the ailment lands.

I think this formula tranlsates to MV's variables pretty cleanly. the Base Resistance would just be a series of variables in the monster's stat block, and the Infliction Rate is basically the percentile number you'd put in when making a skill. Modifiers is for buffs and debuffs that affect status infliction, specifically, as it'd pull the buffed or debuffed stats earlier because its' evaluating current atk or int or luk rather than base values.

current plan: as far as i understand it, i'd just figure out the proper javascript formatting so i can place the above sequence of checks in the hit accuracy plugin exceptions section. like with your sample skill.id==x ? luck formula example but replacing luck formula with the above sequence, and then just make sure i keep that section updated with the skill id numbers of the status inflicting skills.

then, to make things easier i'll probably just have multiple copies of this formula in the hit formula section for each status that i would want to use this method. so the skills that inflict poison would be filed under one copy of the formula that has the poison resistance variable in the resistance section, the blind skills have a copy of the formula with blind resist in it, etc etc.

does this sound like a good way of implementing this?

also, with the etrian games, when an enemy is inflicted with an Affliction and then gets hit with another it overwrites the first affliction and adds a accumulative resistance modifier to the monster. your suggestion on raising their resistances to the other afflictions is a sort of first status wins style scenario that is much easier to implement and simpler compared to a "last status wins" scenario.

I think i can do the last status wins style scenario though by messing with the "on application" and "on removal" sections in the yanfly states core notetags. on application it checks if the other Affliction category statuses are on the target, and if so it removes those statuses. and then, separately, on expiration it applies an "ailment resistance" state to whoever it's on that would be like 8 turns of 80% status resistance before wearing off. (or maybe like 8 stacks of 10% status resistance that tick down every turn? idk both are doable)

Thanks for your help! I know i write a freaking novel when i have questions but your answers are very useful and well done, thank you!
but i think that they by default use agility to derive hit rate, and I wanted to use Luck instead, and be able to edit how much Luck is weighted in that formula
the first part is wrong as long as you don't edit the engine.

By default the only thing affected by AGI is the turn order or action speed (depending on the battle system).
HIT% is a direct value of the traits that has absolutely nothing to do with AGI at all.

In the same way, LUC only affects state rate - exactly what you want to achieve is already there by default. However in this case I can see the desire to edit the weight of luck, because by default having the target have maximum luck (9999) and the user have minimum luck (1) will only drop the chance to 50%, which is why most people never see that influence of luck on states. Their luck values are simply too near each other to have a detectable effect on state rate.
the first part is wrong as long as you don't edit the engine.

By default the only thing affected by AGI is the turn order or action speed (depending on the battle system).
HIT% is a direct value of the traits that has absolutely nothing to do with AGI at all.

In the same way, LUC only affects state rate - exactly what you want to achieve is already there by default. However in this case I can see the desire to edit the weight of luck, because by default having the target have maximum luck (9999) and the user have minimum luck (1) will only drop the chance to 50%, which is why most people never see that influence of luck on states. Their luck values are simply too near each other to have a detectable effect on state rate.
right, and not knowing how to tweak how much luck influences things is annoying and why im looking for ways to either work around that formula or change it so i can make luck a little more consistent and easier for players to factor into their strategizing
so I actually looked and found how they implement their status ailment formula. its like this :
...
current plan: as far as i understand it, i'd just figure out the proper javascript formatting so i can place the above sequence of checks in the hit accuracy plugin exceptions section.
So you still seem to be talking about two different things, which makes it confusing to help (which I tried to express in my first reply, but perhaps not clearly enough).

In RPG Maker (and, in fact, in Etrian Odyssey) whether the skill hits and whether the state takes effect are two different checks. So it's confusing to see you talk about wanting to emulate those games and then about modifying the hit formula in the same sentence.

To put everything explicitly in RPG Maker terms, you make one check based on the battler's hit parameter and this determines whether the skill hits. That determines a number of things, such as whether it does the damage, and then it goes through the Effects.

If one of the Effects is Add State, you have a percentage there. That percentage has its own effectiveness calculation which takes into effect the target's State Rate and the two battlers' luk values.

So by what RPG Maker expects and if you're emulating Etrian Odyssey, you would be modifying that second function, not anything to do with the original hit accuracy portion.

does this sound like a good way of implementing this?
No - and it's not your fault, if you don't have coding experience, but pretty much any time you think of typing the same thing out multiple times, it's probably a bad way of implementing it 😉

If you confirm that I'm describing the first portion accurately, we can help you implement it efficiently.
So you still seem to be talking about two different things, which makes it confusing to help (which I tried to express in my first reply, but perhaps not clearly enough).

In RPG Maker (and, in fact, in Etrian Odyssey) whether the skill hits and whether the state takes effect are two different checks. So it's confusing to see you talk about wanting to emulate those games and then about modifying the hit formula in the same sentence.

To put everything explicitly in RPG Maker terms, you make one check based on the battler's hit parameter and this determines whether the skill hits. That determines a number of things, such as whether it does the damage, and then it goes through the Effects.

If one of the Effects is Add State, you have a percentage there. That percentage has its own effectiveness calculation which takes into effect the target's State Rate and the two battlers' luk values.

So by what RPG Maker expects and if you're emulating Etrian Odyssey, you would be modifying that second function, not anything to do with the original hit accuracy portion.


No - and it's not your fault, if you don't have coding experience, but pretty much any time you think of typing the same thing out multiple times, it's probably a bad way of implementing it 😉

If you confirm that I'm describing the first portion accurately, we can help you implement it efficiently.
yeah that does sound like what im trying to convey! honestly by being able to just change the affliction part of things rather than the skill accuracy part sounds like a much better way of going about things because that allows me to actually construct skills that apply multiple statuses way easier.

i think where i was getting stuck was how i knew i had a plugin to influence the hit accuracy formula, but i had no idea how to go about changing the status infliction formula so I tried to construct a potential workaround using the stuff i knew i had the resources for that just made things more confusing. learning how to actually change the status affliction formula will be way better than the convoluted nonsense i wrote way too much on earlier.
i think where i was getting stuck was how i knew i had a plugin to influence the hit accuracy formula, but i had no idea how to go about changing the status infliction formula
That's what the JavaScript support forum is for 😛

What exactly do you want the formula to be? Are you exactly duplicating Etrian Odyssey as you posted above, or something else?
That's what the JavaScript support forum is for 😛

What exactly do you want the formula to be? Are you exactly duplicating Etrian Odyssey as you posted above, or something else?
An exact duplication would be a good place to start, cause then I at least know how it's supposed to feel from a player's perspective
So here's what RPG Maker does:
Code:
Game_Action.prototype.itemEffectAddNormalState = function(target, effect) {
    var chance = effect.value1;
    if (!this.isCertainHit()) {
        chance *= target.stateRate(effect.dataId);
        chance *= this.lukEffectRate(target);
    }
    if (Math.random() < chance) {
        target.addState(effect.dataId);
        this.makeSuccess(target);
    }
};


And here's simply expressing what you pasted above as JavaScript. A fair amount of it is rather inefficiently done, but it's matching as well as possible.

Code:
Game_Action.prototype.itemEffectAddNormalState = function(target, effect) {
// aScore = (aStat * 2) + aLUC - if you want to differentiate between skill types to use ATK or MAT,
// you can do that later, but right now we'll presume the default of LUK
    var aScore=this._subject.luk*3;

// A = [(aScore + 76.5) / ((dLUC * 3) + 76.5)] * 10: I'm not expressing the outer brackets because
// they're mathematically meaningless
    var A=(aScore+76.5)/((target.luk*3)+76.5)*10;

// IR = Skill's infliction rate
    var IR=effect.value1;

// If A <= 2, B = IR
// If A > 2 & A < 50, B = IR * A
// If A >= 50, B = IR * 50
    var B;
    if (A<=2) B=IR;
    else if (A>2 && A<50) B=IR*A;
    else B=IR*50;

// C = B * Resistance * Difficulty Factor * Modifiers: using the State Rate as the Resistance, no
// difficulty factor, I don't know what could go for modifiers.
    var C=B*target.stateRate(effect.dataId);

// If C is greater than 1500, then set it to 1500.
    C=Math.min(1500, C);

// Then roll a number between 0 and 1000. If that number is lower than C, then the ailment lands.
    if (Math.randomInt(1001)<C)
        target.addState(effect.dataId);
};
thank you!
would this work if i just took this and saved it as a .js plugin?
ok so looking over these- if i were to simply put a conditional at the beginning to detect if the skill used is a physical, magical, or certain hit, that would make it so that I can easily switch which initial formula it's using, right?

(also as far as i understand it the order of operations is attack accuracy, then damage dealt, then effects applied)

so an idea (a bad one because it messes with the certain hit designation but whatever this is more about logic gates.)
Code:
if(this.CertainHit()) {
var aScore=this._subject.luk*3;
}
else( 
if(this.PhysicalAttack()) {
var aScore=this._subject.atk*2+this._subject.luk;
}
else(
var aScore=this._subject.matk*2+this._subject.luk;
))
}

the issue I can see is that this gets rid of certain hits definitely applying the state, which makes applying buffs and debuffs awkward.

i could do a different approach where I somehow detect if the target has taken damage as part of this action, and if yes, if( the skill used was a physical attack use the this._subject.atk*2 formula, else, use the matk formula) and otherwise use the luck*3 formula. that frees up certain hits for buff/debuff use

is there an easy way to check if the target has taken damage this turn? if any given character acting is a turn, then a check if the target has taken damage this turn could work and wouldnt necessarily alter the infliction formulae for slower party members' skills because those are other turns in a Round.
so an idea (a bad one because it messes with the certain hit designation but whatever this is more about logic gates.)
Your syntax is wrong.
1 - You don't need any braces, because if statements automatically apply to the next single code statement. You only use braces to create code blocks if there are multiple statements in there. So:
Code:
if (this.isCertainHit())
    aScore=this._subject.luk*3;

2 - By putting a parentheses after "else" you're telling the code that this is a function, which is wrong.

3 - JavaScript (as well as pretty much every other coding language) supports "else if," so there's no reason to do else, create a code block, and put another if right inside.
the issue I can see is that this gets rid of certain hits definitely applying the state, which makes applying buffs and debuffs awkward.
Buffs and debuffs aren't states.

I think that makes the rest of your musing unnecessary.
thanks!

does using apply.state(x) bypass all this? cause if so, then i can just use that for stuff like regen on allies and non-direct stat boost buffs and debuffs
ok hows this look

JavaScript:
var aScore = 0;
if (this.isCertainHit())
    aScore = this._subject.luk*3;
    else if (this.isPhysicalAttack())
    aScore = this._subject.atk*2 + this._subject.luk;
    else (aScore = this._subject.mat*2 + this._subject.luk);

and then the rest of the code.
Just to mention it, we're not supposed to double post. If you need to say something else and no one else has replied yet, you can just edit your post.

ok hows this look
Fine.

does using apply.state(x) bypass all this?
There's no such code.

But addState() ignores "all this" which you should be able to see because this function uses it at the end to put the state on...😛
Just to mention it, we're not supposed to double post. If you need to say something else and no one else has replied yet, you can just edit your post.


Fine.


There's no such code.

But addState() ignores "all this" which you should be able to see because this function uses it at the end to put the state on...😛
thanks a ton for all your help!

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-alter-the-status-infliction-formula.152647/