I'm SRD HUD Maker, it by default doesn't have any function for changing HP Bar depending on how much HP the player have (the famous green bar that becomes red when is low), but HUD Maker works with Javascript and have script-based conditions, but i don't make any ideia of how can i check the party leader hp with script, does anyone can help me?
MV How can i make an script that checks if the party leader HP is below some percentages?
Javascript/Plugin SupportYou can do this with events. Set 1 variable to the leaders HP outside of combat, and then in a second set variables, divide the number by something that will get the number you want to check below
then when you need to call upon a check set a second variable (in a separate event) to the leaders current HP. Then in a conditions branch, check if the second variable is below the first variable
then when you need to call upon a check set a second variable (in a separate event) to the leaders current HP. Then in a conditions branch, check if the second variable is below the first variable
$gameParty.leader().hp - returns current HP of leader
$gameParty.leader().mhp - returns total HP (how much leader can have)
to calculate percentage of HP you need to do simple math:
$gameParty.leader().hp / $gameParty.leader().mhp * 100, you will get percentage result.
so setting game variable will look like this:
I've put the equation into Math.floor() method to avoid comma values and to have a nice, round result.
$gameParty.leader().mhp - returns total HP (how much leader can have)
to calculate percentage of HP you need to do simple math:
$gameParty.leader().hp / $gameParty.leader().mhp * 100, you will get percentage result.
so setting game variable will look like this:
I've put the equation into Math.floor() method to avoid comma values and to have a nice, round result.
I know you tried to help, but in my case i can't make with events, it has to be scripted
If you need to script it then the best would be to use a ternary statement:
explanation:
x - is your desired value where below it something happens
a - is your action when the condition is met within x value
b - action if a is above x value
Example of usage in SRD hud maker:
I replaced X with 20, so, when % of hp is equal or below 20, text will show "I'm dying" otherwise it will show "I'm okay".
But you don't need that, you can use native method from core files:
$gameParty.leader().isDying() - it will return true when HP drops below 25% so your code will be:
Code:
Math.floor($gameParty.leader().hp / $gameParty.leader().mhp) * 100 <= x ? a : b
x - is your desired value where below it something happens
a - is your action when the condition is met within x value
b - action if a is above x value
Example of usage in SRD hud maker:
Code:
Math.floor($gameParty.leader().hp / $gameParty.leader().mhp) * 100 <= 20 ? "I'm dying!" : "I'm okay"
I replaced X with 20, so, when % of hp is equal or below 20, text will show "I'm dying" otherwise it will show "I'm okay".
But you don't need that, you can use native method from core files:
$gameParty.leader().isDying() - it will return true when HP drops below 25% so your code will be:
Code:
$gameParty.leader().isDying() ? "I'm dying!" : "I'm okay"
when are you checking the HP and how?
If what I know about HUD maker is right, you could also do this with events. If you put the HP check event in a parallel then then set the condition of your green gauge to when your variable for HP% is >= 50, and flip on the red gauge when that variable is < 50, wouldn't that work?
I use the SRD's HUD maker, too, and it's pretty flexible, but I guess that might not speak to what you need. Well, hope it helps anyway, but if not @Soulrender has you covered on script!
I use the SRD's HUD maker, too, and it's pretty flexible, but I guess that might not speak to what you need. Well, hope it helps anyway, but if not @Soulrender has you covered on script!
You don't actually need to do this; there's already a built-in hpRate() function that performs the calculation for you.
Ok, now, what script code should i use to check if an variable is equals an pre-difined number
ex: $gameVariables.value(1) = 1 (i know thats not the right way because an error occours when i try it)
@Trihan
Oh yeah, your right, but it by default returns comma value ranged from 0.00 (dead) to 1.00 (100%) but that I already covered earlier.
Oh yeah, your right, but it by default returns comma value ranged from 0.00 (dead) to 1.00 (100%) but that I already covered earlier.
Code:
$gameVariables.value(1) == x ? "I am equal to X" : "I'm different than X"
How can i use it for setting a variable value?, like, if the HP is 75%, them the variable is also 75 too
$gameVariables.setValue(1, $gameParty.leader().hpRate());
that gives values below 0, i tried multiplying it to 100 with events, but every HP below 100% returns to 0
Hehehe...
Code:
$gameVariables.setValue(1, Math.floor($gameParty.leader().hpRate() * 100))
if ($gameVariables.value(1) <= 75){
//do some stuff
} else {
//do something else stuff
}
One last thing, how can i use an script to detect the weapon that the party leader have equipped? vanilla RPG Maker commands sucks because you can't get the ID of the equipped weapon in Game Data Variables, so you have to create an giant conditional branch just to check every weapon in the game
Oh, by the way, i discovered what i was doing wrong when i was making wrong in the life bars, HUD Maker only allows you to use one single condition, and i was trying to use more than one, in this way only the last works, i solved it creating an common event that controls an variable according to what is happening
Oh, by the way, i discovered what i was doing wrong when i was making wrong in the life bars, HUD Maker only allows you to use one single condition, and i was trying to use more than one, in this way only the last works, i solved it creating an common event that controls an variable according to what is happening
Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-make-an-script-that-checks-if-the-party-leader-hp-is-below-some-percentages.146563/