Zane

Food for thought
Veteran
Joined
Jun 9, 2013
Messages
913
Reaction score
110
First Language
US English
Primarily Uses
Hey whats going on community.

I have a question regarding a scripted variable bar.

I understand and have scripted numerous health bars for huds using the .hp_rate etc.

But I want to know is this a exception for variables?

Here is how a health bar would be drawn:

def draw_life(actor, x, y)    bitmap = Cache.system("Bar")    rect = Rect.new(0, 0, bitmap.width * actor.hp_rate, bitmap.height)    contents.blt(x, y, bitmap, rect)    bitmap.dispose  end
My question is how can I apply this to a variable?

Or is this method not possible?
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,211
Reaction score
15,549
First Language
English
Primarily Uses
RMMV
I'd do something like this:

def draw_generic_bar(x, y, current, max) bitmap = Cache.system("Bar") rect = Rect.new(0, 0, bitmap.width * current / max, bitmap.height) contents.blt(x, y, bitmap, rect) bitmap.disposeendA gradient bar requires TWO values - the current and the maximum. For an actor's hp, that calculation is done inside the hp_rate method.So you need to replicate that, by sending in the current value and the maximum value. This may require two variables, or a variable and a constant.
 
Last edited by a moderator:

Zane

Food for thought
Veteran
Joined
Jun 9, 2013
Messages
913
Reaction score
110
First Language
US English
Primarily Uses
The only slight issue I see with this is that the variable is chosen at random and therefore the max and current value would be different every time. Reason backing this is because I was planning on doing a evented battle type game which this bar would define the enemy's health and the random number would depend on difficulty. I can do it easily with the numbers but was hoping to draw it via a graphic or a regular gradient.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,211
Reaction score
15,549
First Language
English
Primarily Uses
RMMV
If you can figure out the numbers, you know what to send in to the method.


How are you choosing "the variable" at random, and why?
 

Zane

Food for thought
Veteran
Joined
Jun 9, 2013
Messages
913
Reaction score
110
First Language
US English
Primarily Uses
These Variables are for the A.I actor

All stats are designed by variables

1 Variable is the health

When starting a new game it can range depending on difficulty

when easy

100...250

when normal

250...400

when hard

400...1000

This was all set up with a event which works really good. If you were to write this out in a message window it would work out correctly, You can even script the variable on screen if you wanted to without any problems. Doing a graphic bar is more of a eye candy to the user and it would look nicer then 4 sets of numbers.

(However on a small note I might be able to get away with setting up all the actors in the database but this method allows me to randomize it more.)
 
Last edited by a moderator:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,211
Reaction score
15,549
First Language
English
Primarily Uses
RMMV
Well, you still know, at the time you're battling a monster, what the HP and MAXHP are going to be, aren't you? Otherwise what use is the bar if you don't know what the maximum is, or what % they have remaining?
 

Zane

Food for thought
Veteran
Joined
Jun 9, 2013
Messages
913
Reaction score
110
First Language
US English
Primarily Uses
Idk if you were wondering about scene switching. It happens all on the map in case you were wondering.

As soon as I call the random number that's when I will have the value for the max life.

That's exactly where I stopped scripting it because there's is no way to determine the bar really, as where actor.hp_rate is hard coded in more.

Hence why I had to bring up this question.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,211
Reaction score
15,549
First Language
English
Primarily Uses
RMMV
If you call a random number to get the value for max life, save that into one variable. Use another variable to keep track of current life (HP).


There are the two values you pass into the method. I assume you determine the max life before you make the bar appear.
 

Zane

Food for thought
Veteran
Joined
Jun 9, 2013
Messages
913
Reaction score
110
First Language
US English
Primarily Uses
Ah that's something to look into however how am I gonna tell var 2 to check var 1.

Var 1 is the life itself. Well now Max what am I using for var 2? Like the operation of that.

I know it has to operand var 1
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,211
Reaction score
15,549
First Language
English
Primarily Uses
RMMV
The operation is =.


If you have your random number in var1 (current life), set var2 to be equal to var1 at the start. Then as the battle goes on, var1 will decrease, but var2 will stay the same.
 

Zane

Food for thought
Veteran
Joined
Jun 9, 2013
Messages
913
Reaction score
110
First Language
US English
Primarily Uses
And then put the var id's in the current/max slots. Thanks Shaz I'll try it out. Seems like that method will work so you can lock this thread. :)
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,211
Reaction score
15,549
First Language
English
Primarily Uses
RMMV
You would just do


draw_generic_bar(x, y, $game_variables[1], $game_variables[2])


However, I'm not sure where you want to PUT that script. The original one is in Window_Base. But if your battles are on the map, there IS no reference there to Window_Base. And I don't think Game_Map or Scene_Map have a "contents" to blt to. So there's still a bit of playing around for you to figure out where that script should go, and how to modify it, if necessary, based on where it is.
 

Zane

Food for thought
Veteran
Joined
Jun 9, 2013
Messages
913
Reaction score
110
First Language
US English
Primarily Uses
I could build a child class from window_base

and

alias scene_base's start and update and create the window if the scene is on the map

that's how I design all my huds unless that's not a appropriate way?
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,211
Reaction score
15,549
First Language
English
Primarily Uses
RMMV
It would be Scene_Map's, not Scene_Base's, because you only want these showing on the map, don't you? No need to have them defined in any other scene, then.
 

Zane

Food for thought
Veteran
Joined
Jun 9, 2013
Messages
913
Reaction score
110
First Language
US English
Primarily Uses
Your right but I use scene base for quick access to other scenes just in case

I don't think either method hurts really being they are both aliased.
 

Latest Threads

Latest Profile Posts

7DcJlIG.png


Made a lot of progress on the tileset for the more sumptuous interior areas for the priory
I keep thinking up of new changes or improvements... Edit: Forgot to add the image Gimpwork.JPG
Hello, my nickname is Rigomor, but I am also known as Mopsikus. I work on RPG Maker games, and are currently working on a game called Peony of War.

Forum statistics

Threads
117,301
Messages
1,106,314
Members
153,488
Latest member
AlexFliv0
Top