Struggling with Javascript Evals and Equip Requirements

So, in my game, every ranged weapon uses items as ammunition, by way of Yanfly's "Weapon Unleash" and "Skill Cost Items" plugins. And since the game is all about a struggle to survive and manage sparse resources, ammo is naturally hard to find, making guns powerful but costly weapons. The problem comes up when the player inevitably runs out of ammo items, and is suddenly left helpless when their gun won't work but they have no way of equipping something else. For various design reasons, I REALLY don't want to put in a "Battle Equip" plugin, so I figured the best compromise was simply to have the gun only replace the attack skill when the player had adequate ammunition (so that the attack skill would revert to the normal one when the player lacked ammo). I also considered using yanfly's "Equip Requirements" plugin (which I'm already using for other reasons) to introduce an equip requirement where the player needs to have adequate ammo to equip the gun, but I didn't know if that method'd work the way I want it to. I'll just focus on changing the attack skill for now, at the very least.

The only problem with this is that I'm awful at javascript, and can't actually figure out how to make this eval happen without incurring several dozen "undefined is not a function" errors. This is the code I'm using now:

Code:
<Custom Replace Attack>
if ($gameParty.item_number($dataItems[3]) >= 1) {
  id = 4;
} else {
  id = 1;
}
</Custom Replace Attack>

Any help with this issue is immensely appreciated! Thanks a million in advance! ^^

~Blackjack
Try This:

<Custom Replace Attack>
if ($gameParty.hasItem($dataItems[3])) {
id = 4;
} else {
id = 1;
}
</Custom Replace Attack>
Works like a charm! Thanks so much for the assist! ^^

Original thread: https://forums.rpgmakerweb.com/threads/struggling-with-javascript-evals-and-equip-requirements.80540/