Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: Zexion on May 23, 2010, 09:10:23 am

Title: [SOLVED]how to check if player is below 25% hp
Post by: Zexion on May 23, 2010, 09:10:23 am
I am trying to make a sound play when hp is lower than 25% by using events. Is there any script that i can call to check if the players hp is lower than 25%?

EDIT: I knew i made a similar topic so i didn't want to make a new post lol.
Anway i need to know how to check if the actors hp is greater than 95% but less than 100% I need to do this through the call script event.
Title: Re: how to check if player is below 25% hp
Post by: SBR* on May 23, 2010, 10:28:27 am
hp = $game_party.actors[0].hp / $game_party.actors[0].max_hp * 100

The percentage. Well, I can't find 'hp' as an attribute or method in Game_Actors, but I hope this works...
Title: Re: how to check if player is below 25% hp
Post by: Aqua on May 23, 2010, 10:33:05 am
That will make it always equal 0 or 100 XP

You gotta make one of those numbers a float such as adding a .to_f after the .hp

And it's .maxhp XP

hp = $game_party.actors[0].hp.to_f / $game_party.actors[0].maxhp * 100
Title: Re: how to check if player is below 25% hp
Post by: Blizzard on May 23, 2010, 10:33:56 am
You can do it with events as well.

SBR's code should work if you add the float conversion Aqua suggested. Just don't store it in a variable, but check if in a a condition directly. Maybe like this:

Code: conditional branch, script
$game_party.actors[0].hp.to_f / $game_party.actors[0].max_hp < 0.25
Title: Re: how to check if player is below 25% hp
Post by: SBR* on May 23, 2010, 10:40:58 am
Quote from: Aqua on May 23, 2010, 10:33:05 am
That will make it always equal 0 or 100 XP

You gotta make one of those numbers a float such as adding a .to_f after the .hp

And it's .maxhp XP

hp = $game_party.actors[0].hp.to_f / $game_party.actors[0].maxhp * 100



Ah, I see. So that's what .to_f means  :^_^':. I knew it a long time ago, but forgot it. Sorry :P!
Title: Re: how to check if player is below 25% hp
Post by: Zexion on May 23, 2010, 03:12:54 pm
I tried it and it said:
(http://img269.imageshack.us/img269/619/errorta.png)
Title: Re: how to check if player is below 25% hp
Post by: Blizzard on May 23, 2010, 04:50:06 pm
Sorry, oversaw it.

Code: conditional branch, script
$game_party.actors[0].hp.to_f / $game_party.actors[0].maxhp < 0.25

Title: Re: how to check if player is below 25% hp
Post by: SBR* on May 23, 2010, 04:57:40 pm
Quote from: Blizzard on May 23, 2010, 04:50:06 pm
Sorry, oversaw it.

Code: conditional branch, script
$game_party.actors[0].hp.to_f / $game_party.actors[0].maxhp < 0.25




Yeah, I just discovered that.
Title: Re: how to check if player is below 25% hp NEW QUESTION 7-29-2010
Post by: Zexion on July 30, 2010, 12:15:15 am
I gots a new question lol
Title: Re: how to check if player is below 25% hp NEW QUESTION 7-29-2010
Post by: SBR* on July 30, 2010, 02:28:07 am
I don't see how the hp could pass 100%, but let me just answer your question :P.

s.../s: ShowHide
$game_party.actors[0].hp.to_f / $game_party.actors[0].maxhp > 0.95


In a conditional branch as script. It's exactly the same code as Blizz provided, but I changed the 'smaller than' sign to a 'greater than' sign and I changed 0.25 (25%) to 0.95 (95%). If your HP IS able to pass 100%, use this piece of code:

$game_party.actors[0].hp.to_f / $game_party.actors[0].maxhp > 0.95 && $game_party.actors[0].hp.to_f / $game_party.actors[0].maxhp < 100
Title: Re: how to check if player is below 25% hp NEW QUESTION 7-29-2010
Post by: Zexion on July 30, 2010, 06:24:45 am
TYVM! Exactly what i needed lol i was gonna do it with like 100 conditional branches lol.

The hp doesnt go over 100% but what i wanted to do was make an evented hud. If they are at 100% it shows a pic 95-99% shows a different pic etc.
I already had the long version and it works but i wanted to shorten the event alot lol.

I kind of thought of adding && and then repeat and change the code, because of java, but I didn't know it would work the same in rgss lol.
ANYWAYS: THANKS!!

By the way i don't know if i should level u up or down lol.
Title: Re: how to check if player is below 25% hp NEW QUESTION 7-29-2010
Post by: SBR* on July 30, 2010, 06:39:19 am
Quote from: Zexion on July 30, 2010, 06:24:45 am
TYVM! Exactly what i needed lol i was gonna do it with like 100 conditional branches lol.

The hp doesnt go over 100% but what i wanted to do was make an evented hud. If they are at 100% it shows a pic 95-99% shows a different pic etc.
I already had the long version and it works but i wanted to shorten the event alot lol.

I kind of thought of adding && and then repeat and change the code, because of java, but I didn't know it would work the same in rgss lol.
ANYWAYS: THANKS!!

By the way i don't know if i should level up or down lol.


YW! Ah, now I see what you mean. *slaps himself*

Well, the problem is that it's almost impossible for people with a level lower than 10 to get a good level... You see: some noobs level people down... So... up? TY!