MV Help with Yanfly Buffs and States Core - JS Code to check for conditions

Hey guys,

Hope you are all well.

I am hoping someone could point me into the right direction regarding a little problem that I am facing.

In my project the Thief class can place a spike trap in combat. It will afflict them with a state dealing damage to melee attackers and with a chance to cause a bleeding state.

I have accomplished that using Yanflys Buffs and State Core and it works fine using the code below:
Plugin here: http://www.yanfly.moe/wiki/Buffs_&_States_Core_(YEP)


<Custom Deselect Effect>

// Check to see if any physical damage is dealt and if it is not a ranged attack (element 8=range)

if (this.isPhysical() && this.item().damage.elementId !== 8) {
user.gainHp(- b.def)
user.startDamagePopup();

var chance = 0.2; // Chance for inflicting state. 0.2 is 20%.

var stateID = 81; // Replace with state id of bleeding state.

if (Math.random() < chance) user.addState(stateID);

if (user.isDead()) {

// If the attacker is dead, make it collapse.

user.performCollapse();

}

}

</Custom Deselect Effect>


I have recently added a "Floating" skill to the game. Characters affected by this would ignore any damage from traps or ground damage of any sort.
My question being now how do I check for this 3rd condition as well? Floating Characters gain a skill called Flying Attack. So if a Flying attack was performed on an enemy that has placed a spike trap, no damage should be dealt to the attacker by the trap.

So my initial thought was:


if (this.isPhysical() && this.item().damage.elementId !== 8) && user.currentAction().item().id !== 7) {
// check if it is a physical attack, check that it is not a range attack, check that it is not Skill 7 which is the Flying Attack

However when the Flying Attack is being used, damage is still dealt to the attacker....

Does someone have any pointers as to how I need to adjust the code to make this work properly?

Any pointers are much aprichiated,

Thank you
I believe (but I can't verify, because I am not at home at the moment) that user refers to the battler that has the state. But you need to check the attack. I believe just using this.item() again instead of user.currentAction().item() would suffice.
I believe (but I can't verify, because I am not at home at the moment) that user refers to the battler that has the state. But you need to check the attack. I believe just using this.item() again instead of user.currentAction().item() would suffice.
Hey @eomereolsson
Thank you for your reply. I have adjusted the code to the below but unfortunately it is still not working as intended. Don't know if I formatted it incorrectly or need to find a different approach...


if (this.isPhysical() && this.item().damage.elementId !== 8) && this.item().id !== 7) {
Wait, I think I spotted an error with your brackets. You should have
JavaScript:
//Note the second ( after if
if ((this.isPhysical() && this.item().damage.elementId !== 8) && this.item().id !== 7) {
//your code here
Otherwise your && this.item().id stands outside of the condition of the if statement.
Wait, I think I spotted an error with your brackets. You should have
JavaScript:
//Note the second ( after if
if ((this.isPhysical() && this.item().damage.elementId !== 8) && this.item().id !== 7) {
//your code here
Otherwise your && this.item().id stands outside of the condition of the if statement.
I adjusted the code but unfortunately the characters still take damage when they perform skill 7 (flaying attack)
Bump
You should get rid of the extra parentheses entirely - they shouldn't be causing a problem, but they're also not doing anything helpful so it's confusing to read.

Once you've done that, put on the next line
Code:
console.log("ID is " + this.item().id);

In game, hit F8 and go to the console tab, and see what it says when the enemy uses the flying attack.
You should get rid of the extra parentheses entirely - they shouldn't be causing a problem, but they're also not doing anything helpful so it's confusing to read.

Once you've done that, put on the next line
Code:
console.log("ID is " + this.item().id);

In game, hit F8 and go to the console tab, and see what it says when the enemy uses the flying attack.
Hi @ATT_Turan
thank you for your reply. I have cleaned up the cote as suggested. It is actually working. I have made a noob mistake too embarrassing to mention 🙂

But just out of curiosity, what was supposed to happen by adding this line of code: console.log("ID is " + this.item().id);

Nothing seems to happen in the consol...

greetings
what was supposed to happen by adding this line of code: console.log("ID is " + this.item().id);
Exactly what it says. console.log() prints to the console whatever text argument you send to the function. So it should print the words "ID is " followed by the action's ID.

If you have it in there and nothing is being sent to the console, then that portion of your code isn't running.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-yanfly-buffs-and-states-core-js-code-to-check-for-conditions.149500/