RPG Maker MV Yanfly Battle Javacode Question

Hello I haven't really been active on the forums at all but I need some help with with regards to Yanfly's Battle Engine for MV. I want to create a small line of code using Yanfly's <Pre-Damage Eval> command from Yanfly's Skill Core Plugin that raises the evasion of an enemy if a specific skill is used. For example lets say I have a Bat foe. This Bat foe has more evasion when sword based attacks are used. I want the foe's evasion to be increased if you use this specific sword attack. Otherwise the bat has the default evasion he usually has. Any suggestions would be fantastic. Thanks in advance of course.
Do you want it so that the evasion rises when hit by a specific skill (like only the skill sword slash for example), or a whole skill type (like sword skills for example)?
Well I want the foe to raise its evasion before the target takes a hit. And I'm refering to one specific skill and not the entire sword skill type. I can't seem to find a way for the game to tell the difference which is why I'm having a hard time making code for it. Since MV registers both basic attack commands and skills the same way there is no way to differentiate them. I want my bat to evade standard sword attacks but that evasion bonus be removed when using a sword skill. Hope that clarifies what I'm asking a bit. Thanks for responding as well Naveed. 🙂
I maybe understood what you're trying to do.

Correct me if I'm wrong: If the player attacks a bat with a normal attack, the bat has a higher chance of evading. If he uses any skill instead of the regular attack, the bat has standard evasion. Am I understanding this right?

Also, are you using Yanfly's passive states plugin? It would be easier to do it with a passive state rather than a skill (it can be done both ways though)
Yes what you said is exactly what I'm trying to do. I have been trying to use states as a way for the game to notice a standard attack from a skill attack but I haven't had much luck. Yes I'm using Yanfly's Passive States Plugin too. How would you get it working using this?
Here's what you could try:

Give the bat a passive state. Then, in the passive state notebox, use the following code:

Code:
<Custom Select Effect>
// Store original evasion of target, so that it can be returned to normal later.
this._realEvasion = target.eva;
// Check is basic attack is used
 if (this.isAttack()) {
  target.eva += x; // Replace x with how much greater evasion you want.
// Note that evasion is calculated as a percentage.
// So, if x is 0.5, that is a 50% increase in evasion.
 }
</Custom Select Effect>

<Custom Deselect Effect>
// This part is to return evasion back to normal

// Check if evasion was raised
if (target.eva > this._realEvasion) {
// Return evasion back to normal
  target.eva = this._realEvasion;
}
</Custom Deselect Effect>

The // Lines are comments and aren't necessary. They're just to explain what each line does, in case you wanted to learn 😉

The code that is needed, without the // lines, would be:

Code:
<Custom Select Effect>
this._realEvasion = target.eva;
 if (this.isAttack()) {
  target.eva += x;
 }
</Custom Select Effect>

<Custom Deselect Effect>
if (target.eva > this._realEvasion) {
  target.eva = this._realEvasion;
}
</Custom Deselect Effect>

Replace x with how much extra evasion you want.
Remember that evasion is calculated as a percentage, so if x=0.5, that's a 50% increase in evasion.

Let me know if there's any errors or it's not working.
Oh wow thank you so much Naveed! This is spectacular! I'll give it a test immedietely. 🙂
Oh right well it didn't work but I think the reason why is because I'm using Yanfly's Weapon Unleash Plugin for replacing different attacks of my default battlers. :/ The sword the battler is using has the <Replace Attack x> which I've been using. So my battler is using a different skill as it's standard attack. Is there a way for me to track it using code?
Oops, my bad. I made a silly mistake. I forgot evasion rate is an xparam, so can only be controlled via traits as far as i know 😅


Do this instead, should also work with the attack replace:

Create another state and in that state, give it an evasion trait bonus (depending on how much extra evasion you want).
For this example, we'll say this state has an id of x.

Then, in the passive state, use this code:

Code:
<Custom Select Effect>
 if (this.isAttack()) {
  target.addState(x);
 }
</Custom Select Effect>

<Custom Deselect Effect>
if (target.isStateAffected(x)) {
  target.removeState(x);
}
</Custom Deselect Effect>

Where x is the id of the state with the evasion bonus.

(I should test m stuff better :rswt2:)
Oh my gosh thank you so much for the java code assistance. It works flawlessly now. Did you just have the game track the name "Attack" so that the foe would always evade? Either way thanks a lot. Really appreciate you taking the time to answer my question and with such great detail as well.
Glad it's working now 🙂

The code checks to see if the skill used has the same skill id as the character's basic attack (which by default is 1, but the Weapon Unleash plugin changes it to the new skill, so the basic attack id of the character is now the id of the new skill, hence why it still works). It then adds the state with id x if it is a basic attack, and the state changes the evasion rate up. The <Custom Deselect Effect> after just removes the state so that the evasion does not last after the attack.
I see I didn't even know the game could track the user's basic attack. Man I have a lot I still need to learn about this program. Well you can mark this problem solved. Again appreciate you answering my question. Honestly thought it would take a few days before I hear anything back. Your the best.

Original thread: https://forums.rpgmakerweb.com/threads/rpg-maker-mv-yanfly-battle-javacode-question.79910/