MV YEP_EquipBattleSkills.js

Hello, so I'm making a conditional for a skill, and I need to check if another skill is "Equipped". Would anyone know the correct term/script for that? This is the plugin I'm referring to:

So basically, I'm doing a <Custom Show Eval> notetag and this is what I've got so far:
JavaScript:
<Custom Show Eval>
if (!$gameParty.inBattle()) {
  visible = true;
} else if ("skill #1337 is equipped") {
  visible = true;
} else {
  visible = false;
}
</Custom Show Eval>

Edit: So far, I've figured out that $gameParty.menuActor().battleSkills() gives me the array of skills that are equipped to the current actor. Now, I just need to check for a specific skill ID. In my case, I want to check for skill 271.

Edit2: I also tried $gameParty.menuActor().battleSkills().includes(271) but it returned false, despite skill #271 clearly being shown as equipped (both in console and in-game).
1608699631403.png

tl;dr...I need to check an Array for a certain Skill ID, thx!

I was also looking at the code in Yanfly's Stormflurry tip 'n tricks and noticed it also deals w/ an array of skills. However, I'm not sure if it'll even be of any help...
Spoiler: Stormflurry
JavaScript:
<Category: Enchant>
<Help Description>
For \c[4]5\c[0] turns, if unit uses \c[4]Volt\c[0] skills, unit has a \c[4]20%\c[0] chance to strike an additional time for \c[4]40%\c[0] of damage dealt; This effect can chain off itself
</Help Description>

<Custom Establish Effect>
var skills = [];
var skillTypes = [];
// Insert the skills this passive can be used with.
skills.push(681, 689, 697, 705, 713, 719);
// Insert the skill types this passive can be used with.
skillTypes.push(18);

if (this.isSkill() && (skills.contains(this.item().id)) || skillTypes.contains(this.item().stypeId)) {
  if (target && target.result() && target.result().hpDamage > 0) {
    var originalResult = JsonEx.makeDeepCopy(target._result);
    target.clearResult();
    var extraDmg = Math.ceil(0.40 * originalResult.hpDamage);
    var successRate = 0.20;
    var struck = 0;
    var maxHits = 5;
    for (;;) {
      if (target.isAlive() && Math.random() < successRate) {
        struck += 1;
        target.gainHp(-extraDmg);
        target.startDamagePopup();
        if (target.isDead()) {
          target.performCollapse();
        }
        target.clearResult();
        if (struck >= maxHits) {
          break;
        }
      } else {
        break;
      }
    }
    if (struck > 0) {
      target.startAnimation(5);
    }
    target._result = originalResult;
  }
}
</Custom Establish Effect>
Ooh, I need this answered too! It'll be for different purposes perhaps, but the solution would be the same. As in, I'd also like to know how to single out a skill ID out of an array of skills.

Edit: I just noticed...maybe the forEach method will be required? It looks like an array of objects, and you need to check for "id" (or if id == 271 in OP's case).
I've tried all these, and thus far...I've only managed to find out that $gameParty.menuActor().battleSkills()[0].id == 271 returns true, which makes sense since it's equipped in the 1st slot. However, I need to check for every skill slot (the amount of which varies). So I think you're right, I'm gonna need something like the forEach method. I definitely need help w/ syntax though...
1608712229917.png

Edit: I also tried the following, but it didn't seem to work...😔
JavaScript:
<Custom Show Eval>
if (!$gameParty.inBattle()) {
  visible = true;
} else {
  var x = 0;
  for (var i = 0; i < $gameParty.menuActor().battleSkills().length; ++i) {
    if ($gameParty.menuActor().battleSkills()[i].id == 271) {
      x += 1;
    }
  }
  if (x > 0) {
    visible = true;
  } else {
    visible = false;
  }
}
</Custom Show Eval>
1608725454470.png

Ugh, I really need help with this...😢
You can use array.some() for this.

some returns true if any of the elements in the array meet the requirement.

So you take your $gameParty.menuActor().battleSkills() and turn it into $gameParty.menuActor().battleSkills().some(function(ele){ele.id === 137}). It will return true if any of the elements in your array have id 137.

You could make this a little differently by matching the skill object instead, too. $gameParty.menuActor().battleSkills().some(function(ele){ele === $dataSkills[137]})

Matching objects in an array is a bit shaky, sometimes though, so the id method is probably better.
You can use array.some() for this.
Lol yay! Simple solutions are the best, thank u!
Edit: Unfortunately, it gave me errors:
1608744866857.png

This is what I used:
JavaScript:
<Custom Show Eval>
if (!$gameParty.inBattle()) {
  visible = true;
} else if ($gameParty.menuActor().battleSkills().some(function(ele){ele.id == 271})) {
  visible = true;
} else {
  visible = false;
}
</Custom Show Eval>
What did I do wrong? I think using the some() method is the correct approach though.
you could use the equip state notetag. the state would then have addskill for the skill you equipped but then could also double as an if .isStateAffected.

im no good with scripting so i always find these work arounds, although im sure a script method would cause less strain and lag.
you could use the equip state notetag. the state would then have addskill for the skill you equipped but then could also double as an if .isStateAffected.

im no good with scripting so i always find these work arounds, although im sure a script method would cause less strain and lag.
Yea, I considered that but since some of my skills' effects count how many states are applied (even blank passive states), that will interfere w/ those calculations. It was actually my 1st go-to workaround, but for the reason I just mentioned, I need to use a more direct (hardcoded) method. It seems like the some() method approach is the way to go, we just need to tweak the function in the parenthesis some more to get it working. Right now, I think it's having trouble getting to each array object due to TypeError: Cannot read property 'id' of null.
@ramza Awesome, I think we're getting closer! A shame it threw errors though...
@Tiamat-86 Thanks for the idea, I think that approach can come in handy...
@Frostorm Looks like you are very close to the solution now...
:popcorn:
Sounds like the array has a null in it somewhere, possibly at the beginning. It could also be that $gameParty.menuActor() doesn't always have something in it, so the error happens when, say, you're not in the menu. Since you're using this on a passive state, target or this might work instead.

target.battleSkills().some(function(ele){ele && ele.id === 137})
The change inside the brackets makes sure it doesn't bother to check the id if ele doesn't exist or is null, so it shouldn't cause the error. Changing it to target should make it so that the state actually becomes active if the menuActor() function returns null, likely if you're not currently in the menu, though I'm not so sure about that.
Sorry if this has already been given but if not:
user.isLearnedSkill(number)
user.skills().contains($dataSkills[number])
Sorry if this has already been given but if not:
user.isLearnedSkill(number)
user.skills().contains($dataSkills[number])
A learned skill is not necessarily an equipped skill. I appreciate the effort though!
Since you're using this on a passive state, target or this might work instead.
I'm actually not using this on a passive state. I believe that was an alternative @Tiamat-86 suggested.
I will try your new code now, but for reference, this is what I get when I type
$gameParty.menuActor().battleSkills() in the console:
1608749046406.png

...and $gameParty.menuActor().battleSkills()[0] gives me:
1608749059964.png

Edit: Ok, so I got 2 results to share:
$gameParty.menuActor().battleSkills().some(function(ele){ele && ele.id === 271}) was error free, but the equipped skills did not show (meaning it returned false).
target.battleSkills().some(function(ele){ele && ele.id === 271}) yielded the following error:
ReferenceError: target is not defined

Btw, I really appreciate everyone's help! ^.^
(I hope to get this working soon lol)

Edit2: using "user" instead of "target" was also error-free, but alas the skills did not show so I guess the function is yielding false, despite the skill being equipped.
I'm also fairly certain $gameParty.menuActor() is acceptable since the game clearly processes the notetag when I go to select the skills during battle (I can tell cuz of the split-second lag).

@ramza
I find it weird that the following returned false, despite the array clearly showing the skill being there!
1608750247878.png


Edit2: @Johnny_Ray I must formally apologize for dismissing your suggestion too early. I tweaked your post and typed the following into the console:
$gameParty.menuActor().battleSkills().contains($dataSkills[271])
...and it yielded TRUE!😤
I'm gonna try it out, I hope it works lol...
Hmm. We could try using the console to see what it's actually getting each time.

$gameParty.menuActor().battleSkills().some(function(ele){ console.log(ele); return (ele && ele.id === 271)}) When you use that instead, it should output... something to the console. I suspect it'll only do it once, but it might do it for each element since it finds false for the first one.
@ramza Ok, this is what it spat out in the console:
1608751396098.png

Also, it looks like $gameParty.menuActor().battleSkills().contains($dataSkills[271]) also works!!
AHHHHH, I'M SO HAPPY LOL!! 😂

Weird how 2 different but working solutions just fell into my lap all of a sudden haha.😛

Thank you, @ramza & @Johnny_Ray! I've learned so much today, it was an invaluable lesson.

Edit: I am still confused why $gameParty.menuActor().battleSkills().some(function(ele){ console.log(ele); return (ele && ele.id === 271)}) returned true, but didn't do so before (when we didn't have the console.log(ele))...@ramza Do you know why? Seems squite strange...
I think the difference between what I told you to do originally and that last one was the added return in there.
I think the difference between what I told you to do originally and that last one was the added return in there.
Ah gotcha, so "return" was all that was missing eh? That's good to know. I'm definitely saving this thread cuz I know ima have to reference this in the future at some point. Thank you!

I'm so glad I didn't have to resort to the passive state method since that would mean having to create ~200+ dummy states in the database lol.

Original thread: https://forums.rpgmakerweb.com/threads/yep_equipbattleskills-js.131302/