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.
 
Code:
$game_screen.start_tone_change(@current_tone, frames)

This is taken directly from the Day/Night script in my WSSDK. (Clickie the siglink!)

Anyway, here is the actual way to do it:

Code:
tone = Tone.new(red, green, blue, gray)

frames = 60

$game_screen.start_tone_change(tone, frames)

Now, the explanation is fairly simple. Red, green and blue are numbers from 255 to -255, with them being brigther when they are higher. Gray is a number form 0 to 255, and the higher it is, the more monochrome the game becomes. (At 255 the game should be various shades of the exact color you specified) frames is the number of frames you want the change to take, at the speed of 60fps.
 
One strange thing with VX is that you can't change the hue of characters directly in the editor. the Bitmap class holds the hue_change method. So, all you need to to is retrieve the bitmap of your sprite and apply the method like that:

sprite.bitmap.hue_change(x)
x is the hue rotation from 0 to 360.

It is not recommended to change a bitmap hue multiple times, the bitmap quality might drop during the process.

EDIT: BTW glitch, hue is different than tone and, tell me if I'm wrong, but I think jbrist wants to change the hue of a single sprite, right? The start_tone_change affects viewports and everything that comes with it.

Hope it helps!
-Dargor
 

Jason

Awesome Bro

I get an undefined method for start_tone_change

Any ideas ?

Edit~

Didn't see your post Dargor, it seems like your changing the hue of the character only, correct ? I'm trying to make the character AND map (Everything onscreen) to change, but I'll try it nonetheless, as I might be sticking with it.

@ Dargor, I get an undefined method with sprite

However, when I change it to;

@sprite.bitmap.hue_change(260) (Basically add a @)

The undefine method moves onto bitmap

Any ideas there ?
 
If you want it to affect the whole spriteset (Spriteset_Map), you could always add a method in Spriteset_Map that gets all the sprite and their bitmaps, and then change their hue. But I really don't recomment doing that multiple times.

In that case, a tone change would be beter even if it's not the same thing as a hue change.
 
Dargor":6y5ty5js said:
EDIT: BTW glitch, hue is different than tone and, tell me if I'm wrong, but I think jbrist wants to change the hue of a single sprite, right? The start_tone_change affects viewports and everything that comes with it.
-Dargor

That was how I read it too. If you're going to be doing this frequently, I'd do something like changing the graphic in the sprite. Just create a couple extra character_sets that are tinted, and swap them out when necessary.
Or you could create extra bitmap objects in memory, tint them, and then swap those out.

Be Well
 
Ahh, I found the problem with what I posted. Here, it should be this:

Code:
tone = Tone.new(red, green, blue, gray)

frames = 60

$game_map.screen.start_tone_change(tone, frames)

Well guys, I know he said hue, and I know there's a difference between hue and tone. I made the assumption that since he was using an ABS, and since he wanted to change a color when the character was below a certain amount of HP, that he wanted to change the screen to a red tone, and may have mistyped and put hue instead of tone. I've never seen an ABS that didn't have an obvious "you're about to die!" warning like a red screen, unless it simply didn't have a warning at all. In fact, changing the character hue would usually be used only when the character gets attacked, like a red flash for the sprite. And, based on his second post, I may have been right.
 

Jason

Awesome Bro

Glitchfinder":32dt5pf7 said:
Ahh, I found the problem with what I posted. Here, it should be this:

Code:
tone = Tone.new(red, green, blue, gray)

frames = 60

$game_map.screen.start_tone_change(tone, frames)

Well guys, I know he said hue, and I know there's a difference between hue and tone. I made the assumption that since he was using an ABS, and since he wanted to change a color when the character was below a certain amount of HP, that he wanted to change the screen to a red tone, and may have mistyped and put hue instead of tone. I've never seen an ABS that didn't have an obvious "you're about to die!" warning like a red screen, unless it simply didn't have a warning at all. In fact, changing the character hue would usually be used only when the character gets attacked, like a red flash for the sprite. And, based on his second post, I may have been right.

Yeah sorry about that, it was actually meant to be tone, not hue, not sure how I got the two mixed up.

The code works perfect, thanks Glitch !

Just another question now, how can I check if the actors hp is below 10% of the max hp ? I can check if it's 10%, but not less than 10%, any ideas ?
 
jbrist":2o5yfq7x said:
Yeah sorry about that, it was actually meant to be tone, not hue, not sure how I got the two mixed up.

The code works perfect, thanks Glitch !

Just another question now, how can I check if the actors hp is below 10% of the max hp ? I can check if it's 10%, but not less than 10%, any ideas ?

That's pretty easy. Find out what percentage of the HP is, and then check with the following:

Code:
if current_percentage <= 0.10

#whatever you need

end

Or, if you have the percentage as a whole number instead of a decimal, just change the 0.10 to 10
 

Jason

Awesome Bro

I'm afraid I don't follow, should I set it out as;

Code:
 

if $game_player.actor.hp current_percentage <= 10

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

   frames = 60

   $game_map.screen.start_tone_change(tone, frames)

end

 

Where exactly would I implement the current_percentage ?

Thanks.
 
jbrist":lfhk00h5 said:
I'm afraid I don't follow, should I set it out as;

Code:
 

if $game_player.actor.hp current_percentage <= 10

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

   frames = 60

   $game_map.screen.start_tone_change(tone, frames)

end

 

Where exactly would I implement the current_percentage ?

Thanks.

Change it to this:
Code:
current_percentage = ($game_player.actor.hp.to_f / $game_player.actor.maxhp.to_f) * 100

if $game_player.actor.hp current_percentage <= 10

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

   frames = 60

   $game_map.screen.start_tone_change(tone, frames)

end
 
unless the ABS adds the actor attribute to Game_Player, you should use $game_party.
In XP, the syntax should be $game_party.actors[actor_id].hp.to_f
but in VX it's $game_party.members[actor_id].hp.to_f

actor_id 0 is the party leader
 
Dargor":147t4y0m said:
in XP, the syntax should be $game_party.actors[actor_id].hp.to_f
but in VX it's $game_party.members[actor_id].hp.to_f

Ahh, there's the problem. I didn't check to see whether his script call was correct, and instead used it as though it was. You'll need the second one, jbrist. Also, you'll have to fix the second call in my script so that is is the same thing, only it will have to end in .maxhp.to_f
 

Jason

Awesome Bro

I don't understand why, but I keep getting an undefined method for 'member', I can see myself doing this completely wrong for some reason, but here's the piece of code thats supposed to do it;

Code:
 

current_percentage = ($game_party.member[0].hp.to_f / $game_party.member[0].maxhp.to_f) * 100

if $game_party.member[0].hp current_percentage <= 99 #10

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

   frames = 60

   $game_map.screen.start_tone_change(tone, frames)

end

 
 
That's not normal. By default, the 'members' method is already defined in Game_Party.

It sais undefined method 'members' for ... for what? NilClass or Game_Party? I hope it isn't any of them.
 

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