[SOLVED]how to check if player is below 25% hp

Started by Zexion, May 23, 2010, 09:10:23 am

Previous topic - Next topic

Zexion

May 23, 2010, 09:10:23 am Last Edit: July 30, 2010, 06:42:39 am by Zexion
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.

SBR*

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...

Aqua

May 23, 2010, 10:33:05 am #2 Last Edit: May 23, 2010, 10:34:13 am by Aqua
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

Blizzard

May 23, 2010, 10:33:56 am #3 Last Edit: May 23, 2010, 10:35:16 am by Blizzard
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
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

SBR*

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!

Zexion


Blizzard

Sorry, oversaw it.

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

Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

SBR*

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.

Zexion


SBR*

July 30, 2010, 02:28:07 am #9 Last Edit: July 30, 2010, 06:41:48 am by Darth Skywalker
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

Zexion

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.

SBR*

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!