Making TP reduce when damaged while a specific state is applied

In my current project, TP normally increases only when the character takes damage. I've found the "Charge TP by Damage Suffered" section in the script files, and have successfully implemented a custom TP gain formula that factors in the character's Spirit stat (a.k.a. LUK) for how much TP they gain when damaged.

I have a "Fear" state, and what I have in mind is that when a character with Fear is damaged, they lose TP instead of gaining TP. On top of TCR being unable to be set as a negative number, I don't want to just use the same formula as a deduction to TP, since it'd be odd for someone who is naturally braver to be impacted more heavily by the Fear status.

I know how the formula itself would be written, but what would be the code to check if the character has the Fear state and the if/then code to do "self.tp -= (yadda)" with Fear active and "self.tp += (yadda)" without?

Thanks in advance! =^_^=
You could hard-code this into the "Charge TP by Damage Suffered" method. Have it check if the "Fear" state is present and adjust the formula accordingly.
Although... if you used a localized damage formula (tutorials in my sig), this would be a simple task.
Post stuff like this in one of the Scripting sections in the future, rather than Support.

I believe this is how you would write it:

def charge_tp_by_damage(damage_rate) if self.state?(27) self.tp -= 30 * damage_rate else self.tp += 50 * damage_rate * tcr endendChange 27 to the State ID of "Fear" and modify the first formula as you see appropriate.  Let me know if this doesn't work; I think it's solid code but I didn't test it.
Worked perfectly! Thanks! =^_^=

Original thread: https://forums.rpgmakerweb.com/threads/making-tp-reduce-when-damaged-while-a-specific-state-is-applied.48319/