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,828
Reaction score
4,763
First Language
English
Primarily Uses
RMMZ

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
351
Reaction score
136
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
 

Latest Threads

Latest Profile Posts

Today *Fix the game UI
RMMZ maxRows make me tired.
The game supports real-time language switching (really interesting).
8laFKAa.png


jBYDFzZ.png


lYbvPth.png

mY99lgU.png

Swag collecting in the new randomly generated area. Now the mini map also shows the randomly generated features... And even illustrates the whole "bubble" system" that I made to manage memory... Though that part's inadvertent. We'll just call that "the fog of war"... Yes, that's what we'll do. Nobody will be the wiser! :kaopride:
not me being not lazy for 5 seconds and drawing another char portrait (her name is hazel)
its_hazel.png
Been a while since the last time I made a song remix. Had a blast making this
One thing those jp developer still get wrong about boob physic is that... men's muscly hard pecs can jiggle too.

Forum statistics

Threads
110,454
Messages
1,053,436
Members
143,542
Latest member
Back-AlleySnowman
Top