Percentage HP

Joined
Jun 5, 2020
Messages
8
Reaction score
0
First Language
Italian
Primarily Uses
RMXP
Hi guys! I need some help to fix this trouble.

I'm scripting a Scene that simulates a wrestling pinfall.
During the action the player needs to push a button repeatedly, that adds one point of HP any time, to reach 30% of MAXHP to escape.

I have two problems:

- In time update I put percentage formula but it doesn't work. There's no difference if i write extended or not ($game_actors[1].hp / 100 * 30 )
- I need to stop time if the condition of 30% is reached

There is my script :

Code:
  def time
     @time += 1
     case @time
     when 100
        @conteggio.bitmap = RPG::Cache.picture("3") rescue nil
     end
     case @time
     when 50
        @conteggio.bitmap = RPG::Cache.picture("2") rescue nil
     end
      case @time
      when 0
        @conteggio.bitmap = RPG::Cache.picture("1") rescue nil
        end
     if @time > 150
       if  $game_actors[1].hp >= 30%
         $game_variables[5] += 1
         $game_switches[1] = true
         $game_map.need_refresh = true
         $scene = Scene_Map.new
       else  $game_actors[1].hp <= 30%
       $scene = Scene_Gameover.new
       end
       end
     end

The result is... The game continue in the same way... With 0 or 100% HP
 
Last edited:

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,313
Reaction score
4,418
First Language
English
Primarily Uses
RMMV

I've moved this thread to Learning Ruby and RGSSx. Please be sure to post your threads in the correct forum next time. Thank you.

 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
173
Reaction score
62
First Language
English
Primarily Uses
RMXP
When dividing with integers, particularly for finding percentages of something, it's imperative that you multiply first then divide. Integer division does not convert to decimals.

50 / 100 * 30 = (50 / 100) * 30 = 0 * 30 = 0
50 * 30 / 100 = (50 * 30) / 100 = 1500 / 100 = 15

Whereas something like this is okay (note the 100.0, turning this into a floating point division).
50 / 100.0 * 30 = 0.5 * 30 = 15.0

But integer division is faster than floating point division, so it's best you stick with the first solution.

Code:
def time
  case @time
  when 0
    @conteggio.bitmap = RPG::Cache.picture("1")
  when 50
    @conteggio.bitmap = RPG::Cache.picture("2")
  when 100
    @conteggio.bitmap = RPG::Cache.picture("3")
  end
  @time += 1

  if @time < 150
    if $game_actors[1].hp >= $game_actors[1].maxp * 30 / 100
      $game_variables[5] += 1
      $game_switches[1] = true
      $game_map.need_refresh = true
      $scene = Scene_Map.new
    end
  else  
    $scene = Scene_Gameover.new
  end
end
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

*when the One Map Challenge is the only time you can finish a game*
Drifty wanted to make sure the default MV spark animation lived on, so he made it in Effekseer for the contest :guffaw::guffaw::guffaw:
Thanks to a post in a forum thread we can better create MV/MZ plugins in Haxe.
Latest video of my adventures in Kingdom Hearts 3~
Imagine every unfunny joke gets a laugh track, and it doesn't top until you genuinely laugh at that unfunny joke.

Forum statistics

Threads
99,564
Messages
966,751
Members
131,198
Latest member
tofire
Top