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

Status
Not open for further replies.

Cyndi4U

Veteran
Veteran
Joined
Jul 2, 2018
Messages
43
Reaction score
3
First Language
English
Primarily Uses
RMMV
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?
 

ThreeSixNine

Veteran
Veteran
Joined
Jan 22, 2019
Messages
469
Reaction score
388
First Language
English
Primarily Uses
RMMV
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.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,511
Reaction score
2,872
First Language
English
Primarily Uses
RMMV
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>
 

Johnny_Ray

Also known as Toby Yasha
Veteran
Joined
Sep 11, 2019
Messages
158
Reaction score
233
First Language
English
Primarily Uses
RMMV
why do you need the -1 in the var value?
can't you just add the - to the user.gainHp(value) ?
 

Cyndi4U

Veteran
Veteran
Joined
Jul 2, 2018
Messages
43
Reaction score
3
First Language
English
Primarily Uses
RMMV
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>
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,511
Reaction score
2,872
First Language
English
Primarily Uses
RMMV
Well, then it's not working because the custom regeneration isn't running at all. Are you sure the actor has that state?
 

Cyndi4U

Veteran
Veteran
Joined
Jul 2, 2018
Messages
43
Reaction score
3
First Language
English
Primarily Uses
RMMV
Ok, I got it to print, and it is saying they're all NaN. Am I somehow accidentally making them a string or something?
 

ThreeSixNine

Veteran
Veteran
Joined
Jan 22, 2019
Messages
469
Reaction score
388
First Language
English
Primarily Uses
RMMV
Have you tried logging the Custom Apply Effect info to the console?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,511
Reaction score
2,872
First Language
English
Primarily Uses
RMMV
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?
 

Cyndi4U

Veteran
Veteran
Joined
Jul 2, 2018
Messages
43
Reaction score
3
First Language
English
Primarily Uses
RMMV
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?
 

ThreeSixNine

Veteran
Veteran
Joined
Jan 22, 2019
Messages
469
Reaction score
388
First Language
English
Primarily Uses
RMMV
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.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,511
Reaction score
2,872
First Language
English
Primarily Uses
RMMV
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.
 

Cyndi4U

Veteran
Veteran
Joined
Jul 2, 2018
Messages
43
Reaction score
3
First Language
English
Primarily Uses
RMMV
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.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,511
Reaction score
2,872
First Language
English
Primarily Uses
RMMV
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.
 

ThreeSixNine

Veteran
Veteran
Joined
Jan 22, 2019
Messages
469
Reaction score
388
First Language
English
Primarily Uses
RMMV
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.
 

Cyndi4U

Veteran
Veteran
Joined
Jul 2, 2018
Messages
43
Reaction score
3
First Language
English
Primarily Uses
RMMV
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.
 

ThreeSixNine

Veteran
Veteran
Joined
Jan 22, 2019
Messages
469
Reaction score
388
First Language
English
Primarily Uses
RMMV
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.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,511
Reaction score
2,872
First Language
English
Primarily Uses
RMMV
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.
 
Last edited:

Cyndi4U

Veteran
Veteran
Joined
Jul 2, 2018
Messages
43
Reaction score
3
First Language
English
Primarily Uses
RMMV
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.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,511
Reaction score
2,872
First Language
English
Primarily Uses
RMMV
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 :wink:
 
Status
Not open for further replies.

Latest Threads

Latest Profile Posts

Furious and deeply saddened about the state of the US. This is the starting domino.
Thunderstorm approaching: *rumble rumble*

Me: "Hmph... so.. you've come..."

And ONLY me: (adapts fighting stance) "...now show me your TRUE POWER!!!"

*Thunderstorm fizzles out. Sunshine and rainbows.*

Seriously, ONLY ME: "No! Come back! I.. I didn't mean..."
The black rose maiden! :kaopride:
vmTLAk8.jpg

Character: Aki Izayoi from Yugioh 5Ds.
Took some trial and error, but I managed to create "visuals" for underground dig path regions.

Forum statistics

Threads
123,039
Messages
1,153,622
Members
161,386
Latest member
RainbowRosePeace
Top