Rotten Flesh (Castlevania)

I'm not sure if it is the place to ask for such a thing... If it is, I apologize in advance.


I'm trying to recreate an item from Castlevania, which is the Rotten Flesh, which cause you to lose HP when eaten... Unless you have a specific state on, which makes it recover HP instead.


I don't know if it requires a plugin or if it can be done using the damage formula notebox, can anyone help me?
http://yanfly.moe/2015/11/07/yep-25-damage-core/


There are some lunatic mode codes in this plugin that you can probably work with.  I'm thinking something like this in the item notetags:


<damage formula>
if (target.isStateAffected(10)) {


   value = -500;


} else {


   value = 500;


}
</damage formula>


I'm not certain that negative numbers will heal, though.
It doesn't work. I don't think negative numbers does heal. Isn't there another way?
After trying, damage formula indeed does not use negative value. It will just make the damage or heal 0 if the value is negative (or NaN).


You could use a common event and a few script calls for the desired effect. Or search for a plugin.


Using a common event has the drawback that it will close the menu upon use of the item, but apart from that, works flawlessly.


How to do it with a common event:

Spoiler
First the script calls:



$gameParty._targetActorId //will return the id of the actor the last item used targeted
$gameActors.actor(actorId)._states //will return the states inflicted upon an actor in an array [stateId1,stateId2,...,stateIdn]
arr.contains(value) //will return true if the array given contains the value


The common event:



Spoiler



t4vbodm.png



You actually don't have to store the id in a game variable. I just did to show you that it can be memorized for other things too.

The item:

Spoiler
MVHYwZl.png



Tested and working in my project.
After trying, damage formula indeed does not use negative value. It will just make the damage or heal 0 if the value is negative (or NaN).


You could use a common event and a few script calls for the desired effect. Or search for a plugin.


Using a common event has the drawback that it will close the menu upon use of the item, but apart from that, works flawlessly.


How to do it with a common event:

Spoiler
First the script calls:




$gameParty._targetActorId //will return the id of the actor the last item used targeted
$gameActors.actor(actorId)._states //will return the states inflicted upon an actor in an array [stateId1,stateId2,...,stateIdn]
arr.contains(value) //will return true if the array given contains the value


The common event:



  Reveal hidden contents



t4vbodm.png



You actually don't have to store the id in a game variable. I just did to show you that it can be memorized for other things too.

The item:

Spoiler
MVHYwZl.png



Tested and working in my project.



While this could work, I can think of a simpler way to do this involving Yanfly's Skill Core.


http://yanfly.moe/2015/10/13/yep-8-skill-core/


And yes, this should work for items as well.  Try this code in the item:


<After Eval>


if (target.isStateAffected(10)) {


   target.gainHp(500);


} else {


   target.gainHp(-500);


}
</After Eval>


Make the item usable on allies, but issue no effects when used except that note tag.
@shockra I'm going to have to question the fact that adding several plugins to a game, and learning its custom language to produce the desired effect, is simpler than making an object call a common event and use a script call.


While undeniably the proper solution if you don't want the menu closing when you use the item, it's basically doing what I do, but with the added risk of using a plugin (which is possible incompatibilities).


Doing it via a common event also means that you can then do everything you want with event commands without any additional scripting as well.


But, ultimately, what matters is to use what you are more familiar with and works best for you, I guess. If you're already using yanfly's plugins and know how to work with them, go for it.

Original thread: https://forums.rpgmakerweb.com/threads/rotten-flesh-castlevania.64279/