MV Javascript check if augment is equipped (Yanfly AttachAugments)

Hey again all,

Much progress on updating my UI to remove default stats and show players relevant game data. I've even gone so far as to figure out how to make the data change with "if" statements in \evalText:
1715889628632.png

I love that I can have this screen update based on the changes made by an augment. The problem is that the only check I know to make is that the player is affected by the augment (in this case, it puts a state on the player). This means when I look at another item it shows the augment info based on my equipped weapon:
1715889993896.png

You see in the first image I have "Gun Taser" attached so that gives the updated "Effect" text to mention it causes Stun. In the second image I'm looking at a different weapon in a shop which does not have the attachment yet it still shows the Stun Effect. The opposite is also true that if I have a weapon with no attachments and look at a weapon with an attachment it will not show the updated text.

So what I need to do is check if a weapon has a specific augment attached somehow and update the text based on that. Thankfully, in my design players cannot acquire doubles of any weapons so that might make things easier. The only solution I've thought of outside of making a direct check would be to make a switch for every weapon in the game and check for that, but that would be quite cumbersome!

I could also use one variable, but that might be a headache to keep track of...
Can you show some of the code you're using?

The default window that comes with Attachable Augments lists the augments on an item, so it's not clear why you can't use that.
@ATT_Turan Hm, that would be convenient. Is there a description field I'm missing? It would be awkward to use the item name because it would become super long.

Here's the Stun Effect section:
JavaScript:
· \evalText<<if ($gameActors.actor(1).isStateAffected(50) == true) {"Weapon Melee: Causes \I[6] Stunned on hit (cannot perform actions)"} else {"None"}>>
Sorry, I'm not sure from that one line how you're drawing that in the window.

For reference, in Attachable Augments, line 1462 is drawAugmentInfo() which uses the function beneath it, drawAugmentData() to list out what's actually in each slot.

Inside the drawAugmentData() function you could replace the instances of item.name with something else (item.description or some other field you've created) to change what it's drawing for each augment.
@ATT_Turan I started to try to figure out your suggestion, but then I realized it won't work with all the little ways I update the text. I'll show more of the code with comments:

JavaScript:
<Info Text Top>
<br>
\hc[CC0000]\fbWeapon Skill\fb
· Type: \px[300] Ranged, Lethal
· Damage: \px[300] \evalText<<Math.round(80 * (1 + (($gameActors.actor(1).level - 1) * 0.1)))>> Physical
· Hits: \px[300] 2
· Total Damage: \px[300] \evalText<<2*Math.round(80 * (1 + (($gameActors.actor(1).level - 1) * 0.1)))>> Physical
· Uses: \px[300] 3
· Reload Cost: \px[300] \evalText<<Math.floor(6 * (1 - ($gameActors.actor(1).param(3)) * 0.15))>> \I[218]
<br>
//This first section checks if the player has a Gun Blade attachment or not. This is because this attachment changes the damage to lethal, and it is non-lethal in all other cases. I also change color text to highlight this effect
\evalText<<if ($gameActors.actor(1).isStateAffected(30) == true) {"\hc[CC0000]\fbWeapon Melee\fb"} else {"\hc[CCCC00]\fbWeapon Melee\fb"}>>
· Type: \px[300] Melee Strike, \evalText<<if ($gameActors.actor(1).isStateAffected(30) == true) {"Lethal"} else {"Non-Lethal"}>>
//This second section checks both if the player is using a Gun Blade and if they are using a Gun Taser in two different checks. The gun blade increases damage while the Taser changes the type to Energy
· Damage: \px[300] \evalText<<if ($gameActors.actor(1).isStateAffected(30) == true) {Math.round(60 * (1 + (($gameActors.actor(1).level - 1) * 0.1)))} else {Math.round(40 * (1 + (($gameActors.actor(1).level - 1) * 0.1)))}>> \evalText<<if ($gameActors.actor(1).isStateAffected(50) == true) {"Energy"} else {"Physical"}>>
</Info Text Top>
<Info Text Bottom>
<br>
//Here's the original example. It switches text based on whether the player has a Taser or not.
\hc[CC00BB]\fbEffect\fb
· \evalText<<if ($gameActors.actor(1).isStateAffected(50) == true) {"Weapon Melee: Causes \I[6] Stunned on hit (cannot perform actions)"} else {"None"}>>
</Info Text Bottom>

Here's side by side comparisons with each augment:
1715918272424.png


So I'd love to have a condition for "if this augment is equipped to this item", otherwise I guess I'll make a bunch of variables for every weapon in the game and control that with an augment eval. Although that doesn't address the case of when a player sees their augmented item in the store, but I could potentially get that by figuring out a way to do limited stock.
I think the primary disconnect is I'm talking about how to code the actual window to display the information you want, whereas you're looking at adding descriptive text to the...base item? via notetags.

Looking at your code and the section of the plugin I referred you to, the difference is you're using passive states on the player to try to determine what's on the weapon, whereas the plugin code is looking directly at the weapon.

The augments are stored as strings of the item type and the ID - e.g. "item 3". So if you want to ask "does the player's character currently-equipped weapon have item 5 in an augment slot?" you'd do
Code:
if ($gameParty.leader().weapons()[0].augmentSlotItems.includes("item 5"))

- I notice you're using $gameActors.actor(1) everywhere, and I assume that works because it's a one-character game. I used $gameParty.leader() because it's slightly shorter, you can freely replace that with your call for actor 1.

And then you can do the same thing if your shops sell items that have augments already in them, using whatever reference you have to the item being looked at in the shop (usually this._item in a window's code).
@ATT_Turan
JavaScript:
YEP_CoreEngine.js:1098 TypeError: Cannot read property 'includes' of undefined
    at eval (eval at <anonymous> (YEP_X_MessageEvalText.js:105), <anonymous>:1:54)
    at Window_ItemInfo.<anonymous> (YEP_X_MessageEvalText.js:105)
    at String.replace (<anonymous>)
    at Window_ItemInfo.Window_Base.convertEscapeCharacters (YEP_X_MessageEvalText.js:104)
    at Window_ItemInfo.Window_Base.convertEscapeCharacters (YEP_X_InBattleStatus.js:505)
    at Window_ItemInfo.Window_Base.drawTextEx (YEP_CoreEngine.js:2302)
    at Window_ItemInfo.drawInfoTextBottom (YEP_ItemCore.js:2002)
    at Window_ItemInfo.drawItemInfoF (YEP_ItemCore.js:1965)
    at Window_ItemInfo.drawItemInfoF (YEP_X_AttachAugments.js:1457)
    at Window_ItemInfo.refresh (YEP_ItemCore.js:1910)

It seems to not like "includes". I've tried to use it like this:
JavaScript:
<Info Text Bottom>
<br>
\hc[CC00BB]\fbEffect\fb
· \evalText<<if ($gameParty.leader().weapons()[0].augmentSlotItems.includes("item 17")) {"Weapon Melee: Causes \I[6] Stunned on hit (cannot perform actions)"} else {"None"}>>
</Info Text Bottom>

I've also tried with actor 1 and "this._item" but the latter gives more errors.

It sounds like "this._item" would work best because if it's checking $gameParty.leader().weapons()[0] has the augment equipped then it would be the same issue of if the player puts the augment into their current weapon then any weapon they look at would show updated text, wouldn't it?
That's not disliking "includes", it's saying augmentSlotItems is undefined. Which doesn't make too much sense, if you're using Yanfly's Attachable Augments and you know you've installed an augment onto the item.

Open your console and paste in
Code:
$gameParty.leader().weapons()[0]
expand the result with the little arrow next to it, show us what you have.
1715978254823.png


So I have to use actor 1 because I rearrange the party by default (long story, also I tried your code with $gameActors.actor(1).weapons()[0].augmentSlotItems.includes("item 17") and it still gave the error). I equipped the revolver by force so I could pull this up. I'm guessing the rename to "attachment" is relevant somehow?

Edit: Sorry you probably wanted to see it with the attachment in place:
1715979059454.png


Edit 2: @ATT_Turan I came up with a very ugly solution:

JavaScript:
<Info Text Bottom>
<br>
\hc[CC00BB]\fbEffect\fb
· \evalText<<if ($gameActors.actor(1).weapons()[0].augmentSlotItems !== undefined) {if ($gameActors.actor(1).weapons()[0].augmentSlotItems.includes("item 17")) {"Weapon Melee: Causes \I[6] Stunned on hit (cannot perform actions)"} else {"None"}} else {"None"}>>
</Info Text Bottom>

From what I can tell, the augment data doesn't show up until you plug in an augment, so when I check for that specific augment it's returning "undefined" and throwing the whole thing off. So I put in a check that looks to see if the slot is undefined first. If it's NOT, then it can run a check on what's in there and will succeed.

Problems:
1. When I look at another weapon that could use this augment it will show the updated info
2. When I take this item off it doesn't show the updated info

Edit 3 lol: I have a better but still ugly solution:

JavaScript:
<Info Text Bottom>
<br>
\hc[CC00BB]\fbEffect\fb
· \evalText<<if (this._item.augmentSlotItems !== undefined) {if (this._item.augmentSlotItems.includes("item 17")) {"Weapon Melee: Causes \I[6] Stunned on hit (cannot perform actions)"} else {"Weapon Melee: None"}} else {"Weapon Melee: None"}>>
</Info Text Bottom>

This solves problems 1 & 2 above. Even better, it solves a crash that happens if the player has no weapon equipped (which is impossible in my game but still nice to be solved).
From what I can tell, the augment data doesn't show up until you plug in an augment, so when I check for that specific augment it's returning "undefined" and throwing the whole thing off.
That makes sense - I just thought you were testing specifically on the item that had the augment installed.

You don't need to write out multiple full conditionals and nest if statements, you can just use boolean AND. You also don't need to specifically check for the property to not be undefined, just check for it to exist.

Code:
if (this._item.augmentSlotItems && this._item.augmentSlotItems.includes("item 17"))
You don't need to write out multiple full conditionals and nest if statements, you can just use boolean AND. You also don't need to specifically check for the property to not be undefined, just check for it to exist.
Oh, man. That's much better. You're the best!

Original thread: https://forums.rpgmakerweb.com/threads/javascript-check-if-augment-is-equipped-yanfly-attachaugments.168748/