MV Yanfly Buffs and States Core - user.gainHp(-x) not damaging.

Hi! I'm using Yanfly's Buffs and States Core, and have some code to try to make is so the longer you have this state the more damage it deals to the character. The note tags read as follows:
<Help Description> They're freezing cold. Find some way to warm them up quickly, as their hp drains fast. </Help Description> // Make this status apply when temperature // is 0. <Passive Condition: TP Below 5> <Custom Apply Effect> this._freezingCounter = 1; </Custom Apply Effect> <Custom Regenerate Effect> var n = this._freezingCounter / 16; var value = Math.floor(n * user.mhp * -1); user.gainHp(value); this._freezingCounter += 1; // If you're above 4 degrees, remove "freezing" if (user.tp >= 5) { user.removeState(12); } </Custom Regenerate Effect>

I have no idea why this isn't working. I've tried rewriting the code and am wondering if maybe the gainHp function just doesn't support negative values?
I just checked the gainHp function and it definitely supports negative values.

I would try logging the values to the console as they are assigned so you can be certain of the values that are being passed into each step.
It supports negative values just fine, you can see it in tons of Yanfly's Tips & Tricks and the damage formula threads here.

I don't see anything off the top of my head that looks wrong with your code. Are you making sure that after you make any changes to this, you save your project and launch a new playtest, not load a save game?

Aside from that, I'd suggest adding some console logs. Get into a fight and hit F8, go to the console tab, to watch for the output. For example:

<Custom Regenerate Effect> var n = this._freezingCounter / 16; console.log("n is " + n); var value = Math.floor(n * user.mhp * -1); console.log("value is " + value); user.gainHp(value); this._freezingCounter += 1; // If you're above 4 degrees, remove "freezing" if (user.tp >= 5) { user.removeState(12); } </Custom Regenerate Effect>
why do you need the -1 in the var value?
can't you just add the - to the user.gainHp(value) ?
That's strange. When running that, nothing is printed in the console.
It supports negative values just fine, you can see it in tons of Yanfly's Tips & Tricks and the damage formula threads here.

I don't see anything off the top of my head that looks wrong with your code. Are you making sure that after you make any changes to this, you save your project and launch a new playtest, not load a save game?

Aside from that, I'd suggest adding some console logs. Get into a fight and hit F8, go to the console tab, to watch for the output. For example:

<Custom Regenerate Effect> var n = this._freezingCounter / 16; console.log("n is " + n); var value = Math.floor(n * user.mhp * -1); console.log("value is " + value); user.gainHp(value); this._freezingCounter += 1; // If you're above 4 degrees, remove "freezing" if (user.tp >= 5) { user.removeState(12); } </Custom Regenerate Effect>
Well, then it's not working because the custom regeneration isn't running at all. Are you sure the actor has that state?
Ok, I got it to print, and it is saying they're all NaN. Am I somehow accidentally making them a string or something?
Have you tried logging the Custom Apply Effect info to the console?
why do you need the -1 in the var value?
can't you just add the - to the user.gainHp(value) ?
That would make it a negative of the value, which could have been rounded down to 0 by Math.floor. Putting * -1 inside of Math.floor guarantees at least -1 for the damage.

Ok, I got it to print, and it is saying they're all NaN. Am I somehow accidentally making them a string or something?
Stick a console.log inside of the Custom Apply Effect, make sure that's happening properly. If the freezing counter isn't getting initialized properly, referencing it when undefined will result in NaN in all equations.

It shouldn't be the cause, but I meant to ask before - why are you going back and forth between using this and user?
That would make it a negative of the value, which could have been rounded down to 0 by Math.floor. Putting * -1 inside of Math.floor guarantees at least -1 for the damage.


Stick a console.log inside of the Custom Apply Effect, make sure that's happening properly. If the freezing counter isn't getting initialized properly, referencing it when undefined will result in NaN in all equations.

It shouldn't be the cause, but I meant to ask before - why are you going back and forth between using this and user?
Ok, so I don't think that the Custom Apply Effect is working, because it's not logging anything.

Also, if I'm being honestly, these are bits and pieces of code I've slapped together. I'm still trying to figure out how to code these things in RPG Maker, ehehe. Are the two interchangable?
It shouldn't be the cause, but I meant to ask before - why are you going back and forth between using this and user?
I was thinking the same thing, in this case, 'this' and 'user' may not be pointing to the same object.

Try replacing 'this._freezingCounter' with 'user._freezingCounter' and logging that.
Also, if I'm being honestly, these are bits and pieces of code I've slapped together. I'm still trying to figure out how to code these things in RPG Maker, ehehe. Are the two interchangable?
Only if the method that's executing the code is a member of the battler/actor. I think these are, but it's good practice to use any built-in variables (like user) if the author of the plugin provides them. You can try changing all of your this to user, but I don't think that's your problem.

Are you applying the state through a skill while playing the game? If you're doing a battle test or if you're adding it with a console command, it might not work properly.
I was thinking the same thing, in this case, 'this' and 'user' may not be pointing to the same object.

Try replacing 'this._freezingCounter' with 'user._freezingCounter' and logging that.
No change.
Try replacing 'this._freezingCounter' with 'user._freezingCounter' and logging that.
Yeah, that wouldn't be the problem when the OP said putting a log inside of the Apply wasn't happening at all - whatever this was pointing to, the log command would be executed if the code was being run.

Cyndi, check your plugins. Make sure all of your Yanfly plugins are in the order listed on the YEP library Web site. Make sure they're all of the newest version and your MV project file is 1.6.2. Turn off everything except Buffs and any requirements.
Yeah, that wouldn't be the problem when the OP said putting a log inside of the Apply wasn't happening at all - whatever this was pointing to, the log command would be executed if the code was being run.
Okay, that does make sense.

Isn't there an existing issue with the passive states not running the custom apply effect code? I might remember running into this at one point myself...iirc Trihan had posted something about this in another thread...I'll see if I can find it.
Yeah, that wouldn't be the problem when the OP said putting a log inside of the Apply wasn't happening at all - whatever this was pointing to, the log command would be executed if the code was being run.

Cyndi, check your plugins. Make sure all of your Yanfly plugins are in the order listed on the YEP library Web site. Make sure they're all of the newest version and your MV project file is 1.6.2. Turn off everything except Buffs and any requirements.
Changing it to user and turning off all of the other things except for the things i'd need (Passive states and Rolling HP for some reason), and still NaN.
Okay, that does make sense.

Isn't there an existing issue with the passive states not running the custom apply effect code? I might remember running into this at one point myself...iirc Trihan had posted something about this in another thread...I'll see if I can find it.
If that's true, that's 100% the problem, and could be a big issue for me.
Changing it to user and turning off all of the other things except for the things i'd need (Passive states and Rolling HP for some reason), and still NaN.

If that's true, that's 100% the problem, and could be a big issue for me.
You could try it as a non-passive state to check.
turning off all of the other things except for the things i'd need (Passive states and Rolling HP for some reason), and still NaN.
Wait, this is a passive state? I totally missed that line in your original post...that's why I asked you back in post 12 if you were applying this state via a skill. I'm sorry for that, this whole thread was pointless.

Passive states don't have apply effects, because they are not applied/removed from an actor, only switched on and off.

You can go to my snippets post in my signature, I have a modification to the plugin to allow apply effects to work on passive states. I haven't tested it extensively, but you can give it a try.

The other alternative is if your actors have this state for the entire game, just make an autorun event on your first map that gives them the freezing counter variable. But then I'm curious about the remove state bit when TP is high enough, are you trying to do that to remove a passive state? That shouldn't work, either.

You should use that part to reset the freezing counter, and let the passive condition turn the state off.
Wait, this is a passive state? I totally missed that line in your original post...that's why I asked you back in post 12 if you were applying this state via a skill. I'm sorry for that, this whole thread was pointless.

Passive states don't have apply effects, because they are not applied/removed from an actor, only switched on and off.

You can go to my snippets post in my signature, I have a modification to the plugin to allow apply effects to work on passive states. I haven't tested it extensively, but you can give it a try.

The other alternative is if your actors have this state for the entire game, just make an autorun event on your first map that gives them the freezing counter variable. But then I'm curious about the remove state bit when TP is high enough, are you trying to do that to remove a passive state? That shouldn't work, either.

You should use that part to reset the freezing counter, and let the passive condition turn the state off.
Oh, sorry, ehehe. I guess I just assumed that the state was added when the criteria was met.

As for the remove state bit, yeah that was a bit of redundancy, I'll be removing that.
Not just redundancy, it won't do anything, you can't remove a passive state that way. Like I said, replace that command with resetting the counter to 1 and you should be good 😉

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-buffs-and-states-core-user-gainhp-x-not-damaging.144141/