How to make this happen?

Been trying to figure out how to make a skill be twice as effective if user is at or below 50% max HP, but neither trying out stuff nor Google search is of any help... So, how to make this happen?
What have you tried so far? The easiest way should be an if in the damage formula deciding which formula to use.
Not even the final version of the skill yet, because I don't even know how to make it detect HP or MHP.

Like, I was trying first to make it detect if actor has max 22 HP, then heal 10 or 5, depending on if it meets the condition or not, but all I get is Actor took no damage in the damage log when using the skill (even though it's set to recover HP).

Code:
a.mhp?22 ? 10 : 5
Try something like this

[SIZE=10.5pt]if (a.hp / a.mhp) <0.5; big_damage_formula_here; else; normal_attack_formula_here; end[/SIZE]
That won't work because a.hp / a.mhp will always be 0.

a.mhp == 22 ? 10 : 5
You got no damage, because there's no such thing as

Code:
a.mhp?22
The formula would have failed with an error, which would have been ignored, and the result set to 0.
Are you sure about that?  If my mhp is 120 and my current hp is 60

60/120 = 0.5

I don't see how it would always be zero.
Try something like this

[SIZE=10.5pt]if (a.hp / a.mhp) <0.5; big_damage_formula_here; else; normal_attack_formula_here; end[/SIZE]
Yeah, that works perfectly, although I wish I could have figured it out on my own, lol. I'm not familiar with all the formulae terms and the way they're supposed to be used and in which order.

edit: Wait, after testing it a few times, it seems to only work if actor is at 100%HP, otherwise it takes the other formulae.
Are you sure about that?  If my mhp is 120 and my current hp is 60


60/120 = 0.5


I don't see how it would always be zero.
Yes, because 60 and 120 are both integers. You forgot that an operation involving two integers will always produce an integer result. 0.5 will become 0.


Don't believe me? Put it in a damage formula and see what it does 🙂

edit: Wait, after testing it a few times, it seems to only work if actor is at 100%HP, otherwise it takes the other formulae.
See 😉


It will ALWAYS return 0 unless hp = mhp


@Milennin, you want this:

Code:
a.hp.to_f / a.mhp < 0.5 ? 10 : 5
Oh, I see.

What does the .t_f mean?
to float - it converts the variable to one that holds a number with decimals instead an integer
Guys, can I have a question? Why you every single fu**ing time want to make something even that simple looking by some type of weird~long~complicated~hard-to-understand script or formula? =.=
@Milennin, you want this:

a.hp.to_f / a.mhp < 0.5 ? 10 : 5
Ah, yes. This definitely works. Made sure to try it out at different HP levels this time, and seems to works flawlessly. Yeah, there's no way I could have figured that out on my own, lol. 😀
Guys, can I have a question? Why you every single fu**ing time want to make something even that simple looking by some type of weird~long~complicated~hard-to-understand script or formula? =.=
Because not everything that is simple-looking can be done by something simple.Shaz and I usually tell people not to use scripts unless absolutely neccessary - if we start with coding, then you can be sure that all other methods are more complex, no matter how simple something might look at first glance.

In this case, the damage formula is the only place that can change the damage at the correct place in the default damage sequence - theoretically you could have the skill calling a common event and check there, but common events are executed at the end of a battleturn, no matter when called - which means the actor possibly has taken more damage during the rest of the turn.

EDIT:

By the way, now that I think about it - simpler would have been

Code:
(a.hp < a.mhp/2) ? 10 : 5
to float - it converts the variable to one that holds a number with decimals instead an integer
Thanks for the explanation.

And yes, version 2 is even better.
Guys, can I have a question? Why you every single fu**ing time want to make something even that simple looking by some type of weird~long~complicated~hard-to-understand script or formula? =.=
Honestly, I don't appreciate the language here. Surely you're capable of asking without resorting to that? Especially when it's not even your thread.


Take a look at the damage formula in the default skills. This is not weird~long~complicated~hard-to-understand if you understand that ? means "if true" and : means "if false". Unfortunately, the damage formula only allows one line, and has a limit on how many characters you can use. The same thing in a script would take 7 lines, but we don't have 7 available.


If you don't like that method, instead of criticizing, show us how you would write it instead, so that it takes one line, is readable/understandable, and works?
a.hp_rate < 0.5 would be the even easier way to do it, since that's alright defined in the library.
If you don't like that method, instead of criticizing, show us how you would write it instead, so that it takes one line, is readable/understandable, and works?
Sorry, I was out of internet for a day...

I meant something like that...

Spoiler
W4k0XPk.png
Spoiler
oZ5d4aY.png
Didn't actually try if it really works, but it should... Yea, yea, I know, it isn't working only for one skill, but I haven't much time, so I have done just basics... Now it should be easy to apply this only for one skill... (If I'm right, like that whith my luck and knowledge of mechanics I won't... =.=')

-Edit-

Ok, worked little bit more on it and it won't be easier, but it is universal... Sorry! My bad! Never'll speak again!
Didn't actually try if it really works, but it should...
No, it won't work the same because of the timing problems as I described in post #13.
And you can speak as much as you want - we would just prefer if people test their solutions to make sure they work exactly as requested, because a good part of the untested answers aren't working.
I know, I know, I just though that I already used something like that and it worked, but when I look closer... It was just cooperation betwen item and

specified actor through state inside of common event, once again, sorry...

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-this-happen.45781/