Modifying Yanfly Phoenix Ring

Hello! I am trying to modify the Phoenix Ring to be a Hidden Item or Key Item that has the same effect as I don't want to tie up my characters accessory slot the whole game and would like them to be able to use it more then once in a battle.

I want characters to purchase or start with the ability to come back to life in battle. They can start the game with X amount of Resurrections type deal. If it's not possible to do that, I would like to tie it to an item they can keep in their inventory.

I took the Original Script and Created a Hidden A Item.

Then I tried plugging it into the Notes under state to generate this effect with no luck, the code works normally with the ring, so I have the proper plug ins running. I just don't know enough to modify it properly.

Original Yanfly Script.

<Custom Apply Effect>
if (target.isActor()) {
var ring = $dataArmors[1541];
if (target.hasArmor(ring)) {
target.discardEquip(ring);
target.startAnimation(42);
var hp = Math.floor(target.mhp * 0.25);
target.gainHp(hp);
target.startDamagePopup();
}
}
</Custom Apply Effect>

My Modifications

<Custom Apply Effect>
if (target.isActor()) {
var ring = $dataItems[0021];
if (target.hasItems(ring)) {
target.discardItems(ring);
target.startAnimation(42);
var hp = Math.floor(target.mhp * 1.00);
target.gainHp(hp);
target.startDamagePopup();
}
}
</Custom Apply Effect>

Any help would be appreciated!
Welcome! Whenever you post code, you should always use the CODE tag (the </> symbol on the edit bar). That preserves indentations and prevents the forum from eating stuff inside brackets.

The first problem is:
Code:
var ring = $dataItems[0021];

Putting leading zeros on a number causes the JavaScript engine to treat it as an octal value, which is not what you want. Even though it's displayed in your database that way (for some reason), the ID is just 21.

Then it also looks like the lines right after that you just made up. There's no such thing as hasItems() or discardItems()...it's okay to not know things and ask (or look up the script call lists on the forums), but making up code has an approximately zero percent chance of working 😉

So you should have:
Code:
var ring = $dataItems[21];
 if ($gameParty.hasItem(ring)) {
   $gameParty.gainItem(ring, -1);

Let us know if that gets you sorted!

Original thread: https://forums.rpgmakerweb.com/threads/modifying-yanfly-phoenix-ring.152768/