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,242
Reaction score
4,369
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 Profile Posts

wake me up when Photoshop stop crashing everytime
Brioche with a crème patissiere filling is so tasty!
A group of Game creators and others who trying to revive the Feel of Multiplayer and TOWN/ROLEPLAY games
Wow, lots of RPG Maker MV stuff on sale on Steam for 50%-75% off. Steam, why you not tell me?!
looking for help on top secret project

Forum statistics

Threads
99,385
Messages
964,677
Members
131,007
Latest member
hotelbones
Top