MV Skill that has specific effects under IF condition

Hello again ♥♥♥ 😅
Here I am, once again, feeling lost but now and then I breathe it in to let it go (....cringe 😅)
I was trying to create another Skill on MV with a specific effect, but I'm struggling way more than I would have thought.
What I am trying to do, is to have a Skill (in this case is not an attack skill, it just add a state upon enemies, but I don't think this is crucial) that has a secondary effect (in this case, cure the user) at the end of the execution ONLY IF another skill has been learned by a member of the Party. Perfect would be if that cure could heal both the user of the Skill and the Actor that actually KNOW the trigger Skill itself. I have most of Yanfly's plugin already on, but can't quite figure it out.

So I try to put it simple

SKILL: "Black Fog". It blind the enemies.
No damage. Add BLIND within a certain %
IF another character knows the Skill "Into the Dark" then:
- heal the user 20% hp
- heal the character that know "Into the Dark" 20%
(optional) - add a State to both character

I was trying out something like:
Code:
<Before Eval>
if user.isLearnedSkill(41) {
  user.gainHp(value * 0.20)
}
</Before Eval>
Where SKILL 41 was "Into the Dark". I know that in this script (OF COURSE IT'S WRONG, it doesn't do shplip) I even put the "IF" check for the skill on the user, but it was just for testing purpose. Must seem like a total mess, but I swear I thought it was easy 😔
Try this, and let me know if it does what you want. I'm assuming you already have Yanfly's Skill Core, since you're trying to use a Before Eval.
This goes into your 'Blind' skill. Change the bolded values to match your game.
Spoiler: Skill Notetag
<After Eval>
for (var i = 0; i < user.friendsUnit().aliveMembers().length; ++i) {
var member = user.friendsUnit().aliveMembers();
if(member.hasSkill(12)) {
member.gainHp(Math.ceil(member.mhp*.2));
member.startDamagePopup();
member.startAnimation(3);
var trigger = 1;
}
}

if(!user.hasSkill(12) && trigger === 1) {
user.gainHp(Math.ceil(user.mhp*.2));
user.startDamagePopup();
user.startAnimation(3);
}
</After Eval>



I made this assuming the entire party can learn 'Into The Dark', including the caster of 'Blind', hence why I did a lil workaround with the var trigger. It's...not the prettiest workaround, but it does work haha.
Spoiler: Code Explained
I used an After Eval instead of Before in personal preference.
The for loop will go through the entire user's party
The if statement inside the loop checks if that member has the skill ID 12 - change it to whatever you 'Into The Dark' skill ID is
Then, the member gains 20% of their max hp. I show the damage popup, and a little animation just for fun.
I also declare a variable and name it trigger. This is important for the workaround. If I put user.gainHP in the same bracket as the party member, then it would proc for every party member, meaning if 3 other members had the trigger skill, the user would be healed all 3 times! And if the user knows the skill as well, they'd get healed 4 times. So I made a workaround.
Outside the for loop, in the second if statement. If the user doesn't know the trigger skill (if they did, they would have already gained their HP from inside the for loop, as they count in the friendsUnit eval) and the var trigger is 1, then the user gains HP. The var trigger is important, to make sure an ally actually has the trigger skill. If nobody has the skill, the trigger doesn't exist and the user won't be healed.
Let me know how that works out for you!
@Cythera thank you for your reply and the amazing explanation! 😊♥♥♥ Unfortunately, it seems like I can't make it work. I tried the code into another simple Skill as well (a very basic skill with just a damage formula, since I was afraid some other code must be a bother to this) but nothing happens. The execution of the Skill is regular, but the Healing doesn't trigger. 😩 The Skill Core Plugin must operate well, since I'm using other tags like HP cost, and it goes smooth.
Of course I edited the Skill ID to match my situation, but I can't get it out of this. 😔

I put the code into "Deep Fog" Skill (A no-damage Skill, that only causes BLIND)
I made it so the values are met, changing:
if(member.hasSkill(27)) (27 is: "Into the Dark")
if(!user.hasSkill(27)
and added party members with Skill 27 (The user itself and another that knows "Into the Dark")
But nothing happens when I cast "Deep Fog"


Removing the if condition and make it just cure always like this
Code:
<After Eval>
user.gainHp(Math.ceil(user.mhp*.2));
user.startDamagePopup();
user.startAnimation(130);
</After Eval>
makes the cure appear correctly, so I don't think it's the Plugin that fails, but the IF condition itself?
Or... Am I making something wrong? (chances are YES:kaomad2:)
Alright, time to do some trouble shooting then, as this works just fine for me in both a new project and my current project.
1. Copy-paste me everything that is in your skill note box
2. Check your plugins and make sure they're in the right order as posted by the writer (this makes a way bigger difference than a lot of people realize)
@Cythera ALL RIGHT-Y CAP! 👋
Here's what my Skill Note looks like. It's just the code you gave me, and another for an AOE effect!


Code:
<After Eval>
for (var i = 0; i < user.friendsUnit().aliveMembers().length; ++i) {
var member = user.friendsUnit().aliveMembers();
if(member.hasSkill(27)) {
member.gainHp(Math.ceil(member.mhp*.2));
member.startDamagePopup();
member.startAnimation(130);
var trigger = 1;
}
}

if(!user.hasSkill(27) && trigger === 1) {
user.gainHp(Math.ceil(user.mhp*.2));
user.startDamagePopup();
user.startAnimation(130);
}
</After Eval>
<AOE Radius: 70>

As for plugins order... here's my list! I always tried to put attention to the order suggested, especially with Yanfly's ones, but I have to admit that I tought about the Plugin Order as a reason for some problems myself! So I... 😅 must have moved things around a little from time to time, to test out things 😅😅 I checked immediatly the SKILL CORE, but being a Parent Plugin I only found out that OTHERS need to be under it. Everything else I put out together till now went smooth, so maybe I wasn't even aware of a potential disaster because of my Plugin order 😅😅😅

EDIT: I tried it into another Project with WAY less Plugins on, but it doesn't work there either çç I'm starting to suspect I needed to change some other thing other than the Skill and the Animation ID? Something with the variable? NGH-- I'm such a noob-erus noob with Java, maybe I haven't see the obvious 😩

ANYWAY, thank you so much for the support and help you're giving me, it's so super much appreciated 😊♥♥♥
Sorry, I fell back asleep :3 I am not a morning person.
Anyways! Your problem is with your var member line. It needs to be
JavaScript:
    var member = user.friendsUnit().aliveMembers()[i];
There's no [i /] in yours, which means it isn't moving through the various members; it has no index to check!
Looking back I see the code I originally gave you didn't have the [i ]/ in it either, so that's on me. Forgive my copy-past fail haha!
Edited because I just realized [i /] is an italics code...
@Cythera Oh please, don't apologize for something like that ♥ You're giving me your time and help, feel free to reply when you feel like it 😍
ALSO, YEAH, THIS WORKED LIKE A CHARM ♥♥♥♥♥ Oh yeah!!!♥♥♥ 👋♥♥♥ Thank you SO much! What I intended to do iS there, now!

Uhm--- Since you were so patient with me~ can I ask you for one more favour? 😩

I am willing to complete this combination of Skills/States perfectly, and I was wondering if there is a way to have the CRIT RATE as a stackable buff?
I already have the Skill that trigger a State, and this State is stackable and working fine~

Code:
<Custom Apply Effect>
// Default the stockpile stacks to 0.
user._stockpile = user._stockpile || 0;
// Increase the stockpile stack by 2
user._stockpile += 2;
// Cap the stockpile stack at 10
user._stockpile = Math.min(user._stockpile, 10);
// Update the state counter for the stockpile stack
user.setStateCounter(stateId, user._stockpile);
</Custom Apply Effect>

<Custom Remove Effect>
// Set the user's stockpile stack to 0
user._stockpile = 0;
// Update the state counter for the stockpile stack
user.setStateCounter(stateId, user._stockpile);
</Custom Remove Effect>

What I don't know is, what is the right call to write, to have that any stack raises ATK and Critical Rate by, uhm, a 10% ? And WHERE should I put it? I tried to add "user.addCri(0.10 * user._stockpile);" right below "user._stockpile += 2;" but it goes wrong an break it, so when I put the State on an actor, it doesn't stack anymore. :kaomad2:

That said, this is relevant in my Skill/State combination, because I was also willing to tie this Crit Rate buff (WHEN I'LL BE ABLE TO DO IT 😅 to an IF condition, exactly like the Skill we did before!! 😊Doing so, the raise in the ATK & CRIT RATE BUFF occurs only if the actor knows a certain Skill, like the problem we already solved. The question is, is it possible to do it for States too? Can I use the exact same code you gave me?? 😅 Like... This State generates stacks and has its own effect BUT IF the target knows a precise Skill, then the State add the Crit Rate buff too. Can it be done?
If it can't be done, it would still be amazing to learn how to stack ATK & Crit Rate nicely, with the already finished State 😩 😩 😩

I am so extremely sorry if I'm taking advantage of your immense courtesy 😍I hope you don't mind too much, but feel free to reply when you feel like it! sigh sob salabim
Glad it's working for you now!

So for your question, you're trying to buff crit rate and attack? As in, for every member that has the trigger skill, they gain a buff to their crit rate and attack? If that's the case, that is very easy to do; simply create a state that buffs critical rate and attack in the state traits by whatever % you like, and add member.addState(X); in to the previous code, right below the animation effect. Change member to user in the 'user' bracket.
If you mean stack crit rate and attack, erf, that's a lot harder because, as far I know, you can't actually do that. You need a workaround to create the same effect. In this case, you mean you'd want to buff the user's crit rate and attack by 10% for every stack - regardless of how that stack was gained. For now, I'm just going to assume a 'stack' is gained when the previous effect activated. So every time someone casts Blind and an ally has Into The Dark, they gain a stack. And their crit rate and attack are increased by 10% per stack.
As I said, I don't think that's actually possible in state code. You can use stacks for damage over time, healing over time, influencing damage, but not for actually influencing player stats like that. You would need a workaround - my workaround here would be to have different states for each level. So crit rate +10%, crit rate +20%, for 30%, etc. The more states, the more tedious this would be, so there'd need to be a cap. For dev sanity.
Then, every time a 'stack' is gained, I'd check to see if they had one of those states applied. If so, remove it and apply the next level one. If not, then apply the first level one.

I'd honestly suggest making another post here in the forums, either in plugin requests or plugin/JS support for that one. Someone else might have a better way to 'stack stats' like that.
I did a quick Google for stacking states and came up with this - you'll have to skip over the posts from the OP getting stuff wrong, but Msoulwing provides the plugins and code necessary.
The downside is that neither of the plugins involved (Yanfly's and Quxios') allow you to directly affect ex-params, such as crit rate. Attack is easily done, though.
@Cythera Thank you so super much for your suggestion and support one again 😩 ♥ You're super nice~ Yes, you got EXACTLY what I wanted to do, and I think I'll follow your suggestion! 😊 It was simple and clean, thank you for your time and dedication ♥♥♥ Also, thanks to the link provided by @ATT_Turan too, I'm sure I can work a way for what I need! It's super usefull, Turan, thank you!!! I will unite this with Cythera suggestion and my work will go forward so much easier ♥♥♥ Thank you guys, really 😍 bless you~

Original thread: https://forums.rpgmakerweb.com/threads/skill-that-has-specific-effects-under-if-condition.135989/