Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[RMVX] Changing hue through script ?

Jason

Awesome Bro

Hi,

So I'm having a little trouble figuring this out, basically as an addon for the ABS I'm using (Vlads ABS Basic heavily edited by myself), I want to make it so when the actors HP drops below, say... 10%, the hue changes.

I've already got the if statement for the actors HP being 10%, but how would I do the script line that changes the hue ?

Now, I could very easily do this with an event and picture, and if I can't figure this out, then thats what I'll resort to.

Thanks.
 
jbrist":ab7h6xkn said:
Sadly it just gives me an undefined method for 'members'

I never thought something that seems so easy would become such a pest, lol.


here, try this:

Code:
party = $game_party.members

current_percentage = (party[0].hp.to_f / party[0].maxhp.to_f) * 100

if current_percentage <= 10

   tone = Tone.new(240, 0, 0, 170)

   frames = 60

   $game_map.screen.start_tone_change(tone, frames)

end
Apparently, we've all been making mistakes in this one.

Dargor, it's because I left a remnant of his code in mine in the if statement, and that's probably what's giving the error.
 

Jason

Awesome Bro

I'm still getting the undefined method for 'members' o.O

If this is getting too complicated for you two, cause it sure is for me, lol, I'll just abandon using a script and event it.
 
jbrist":2m78ituk said:
I'm still getting the undefined method for 'members' o.O

If this is getting too complicated for you two, cause it sure is for me, lol, I'll just abandon using a script and event it.

You're using vx, correct? If you aren't, we'll have to change the script a little bit. Also, unless you are using a custom script that modifies the Game_Party script, this should work in vx.

Also, which line does it give an error on? The first line I posted? try adding this code to the top of the script:
p $game_party.members

then tell me if it prints out nil, or if it prints out a lot of stuff.
 

Jason

Awesome Bro

Glitchfinder":bdvrjbtr said:
jbrist":bdvrjbtr said:
I'm still getting the undefined method for 'members' o.O

If this is getting too complicated for you two, cause it sure is for me, lol, I'll just abandon using a script and event it.

You're using vx, correct? If you aren't, we'll have to change the script a little bit. Also, unless you are using a custom script that modifies the Game_Party script, this should work in vx.

Also, which line does it give an error on? The first line I posted? try adding this code to the top of the script:
p $game_party.members

then tell me if it prints out nil, or if it prints out a lot of stuff.

Yeah I'm using VX, I'm not using any scripts that modify Game_Party, and I've tried it in a new project too.
I get the error on the first line cause of the word 'members', I keep getting an undefined method for it.
 
jbrist":2twayamt said:
Yeah I'm using VX, I'm not using any scripts that modify Game_Party, and I've tried it in a new project too.
I get the error on the first line cause of the word 'members', I keep getting an undefined method for it.

Did you try adding the line I suggested, to see what value members had? Also, where are you putting this script? If you have it before the party in initialized, then you will get this error. Specifically, if you have it anywhere before the map is called for the first time when you start a new game or load a save file.
 
jbrist":12tc8spb said:
Yeah I added the extra line and still got the error.

I placed the code in the ABS script, below the HP Bar code and above the updates.

Did you place my code right before the script, or after it? Because if you put it after, it wouldn't do anything. Also, does the ABS modify Game_Party? If that still doesn't work, try replacing it with:
p $game_party

Finally, I have one last question:

Does the ABS modify Scene_Title?
 

Jason

Awesome Bro

Okay, the ABS doesn't modify anything. and when I replace p $game_party.members with p $game_party I get a popup saying nil, and then ANOTHER undefined method 'actor' popup.

I think it'd be easier if I just made it using events.
 
Here, pop this into a new slot under the ABS script and tell me if it works. (I just tested it with the blank ABS project, and it worked for me)

Code:
class Game_Map

  alias glitch_vlad_abs_mod_init initialize

  alias glitch_vlad_abs_mod_update update

  def initialize

    @time = 0

    glitch_vlad_abs_mod_init

  end

  def update

    glitch_vlad_abs_mod_update

    check_hp

  end

  def check_hp

    party = $game_party.members

    current_percentage = (party[0].hp.to_f / party[0].maxhp.to_f) * 100

    if current_percentage <= 10

      if @time <= 0 || @time == nil

        tone = Tone.new(240, 0, 0, 170)

        frames = 30

        $game_map.screen.start_tone_change(tone, frames)

        @time = 60

      elsif @time == 30

        tone = Tone.new(0, 0, 0, 0)

        frames = 30

        $game_map.screen.start_tone_change(tone, frames)

        @time -= 1

      else

        @time -= 1

      end

    elsif current_percentage <= 5

      if @time <= 0 || @time == nil

        tone = Tone.new(240, 0, 0, 170)

        frames = 15

        $game_map.screen.start_tone_change(tone, frames)

        @time = 30

      elsif @time == 15

        tone = Tone.new(0, 0, 0, 0)

        frames = 15

        $game_map.screen.start_tone_change(tone, frames)

        @time -= 1

      else

        @time -= 1

      end

    end

  end

end
 
jbrist":3i2ha415 said:
Okay that code works fine, however, is there a way I can change it so it only flashes if the HP is below 5%, but stays when the HP is 6-10% ?

Sure! Here:

Code:
class Game_Map

  alias glitch_vlad_abs_mod_init initialize

  alias glitch_vlad_abs_mod_update update

  def initialize

    @time = 0

    glitch_vlad_abs_mod_init

  end

  def update

    glitch_vlad_abs_mod_update

    check_hp

  end

  def check_hp

    party = $game_party.members

    current_percentage = (party[0].hp.to_f / party[0].maxhp.to_f) * 100

    if current_percentage <= 10 && current_percentage > 5

      tone = Tone.new(240, 0, 0, 170)

      frames = 30

      $game_map.screen.start_tone_change(tone, frames)

    elsif current_percentage <= 5

      if @time <= 0

        tone = Tone.new(240, 0, 0, 170)

        frames = 30

        $game_map.screen.start_tone_change(tone, frames)

        @time = 60

      elsif @time == 30

        tone = Tone.new(0, 0, 0, 0)

        frames = 30

        $game_map.screen.start_tone_change(tone, frames)

        @time -= 1

      else

        @time -= 1

      end

    end

  end

end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top