Color bar for a specific amount of energy

dantedevil

Well-known member
Hello!
I need when the enemies have a 25 rest of energy the bar shows color red.
I know how make this if the enemy have 100 of energy.  With the lifebar.txt (color25 = 0-20%),  this not work when enemies have more than 100 points of energy,  because shows 20% in red, not 25 points of energy.
 
The default color bar system cannot do this. You will have to sue a scripted life bar. Check out Golden Axe Remake by utunnels for an example.

DC
 
Damon Caskey said:
The default color bar system cannot do this. You will have to sue a scripted life bar. Check out Golden Axe Remake by utunnels for an example.

DC

Then... this is the example i think (update.c);

Code:
void main()
{
    int i; int z; int t;int health;int off;
    void pl;
	char cstring;
    if(openborvariant("in_level")==0)
    {
        z = openborconstant("FRONTPANEL_Z");
        drawbox(0, 240, 480, 32, z+1000, 1);
        for(i=0; i<3; i++)
        {
            pl = getplayerproperty(i, "ent");
            if(pl==NULL())
            {
                drawbox(i*160+32, 240, 126, 32, z+20000, 1);
            }
            else
            {
                drawbox(i*160+32, 240, 126, 32, z+1110, 45);
                t = getentityproperty(pl, "mp")/10;
                drawbox(i*160+55, 240, 11*t, 16, z+1111, 92); // magic pot
				drawbox(i*160+55, 256, 11*t, 16, z+1111, 93);
                health = getentityproperty(pl, "health");
                off = (health-1)/20;
                drawbox(i*160+54, 242, health, 2, z+18000, 68 + off);//health
                drawbox(i*160+54, 244, health, 2, z+18000, 66 + off);
                drawbox(i*160+54, 246, health, 2, z+18000, 64 + off);
				drawstring(i*160+34, 263, 1, "x"+getplayerproperty(i, "lives"));
				cstring = getglobalvar("cstring");
				if(cstring!=NULL())
				{
					drawstring(i*160+55, 256, 2, cstring);
				}
            }
        }
    }
    //drawstring(4, 100, 0, getglobalvar("debug"));
}

I try, but i can't undestrand how change this script to make the the result i need.

Some one can show me the way to do it?

Thanks!
 
I still working in this without good result.
Very Soon i post the first demo of my mod.
I need fix a few details including this problem and finally i hope can share my work with all.

Thanks.
 
drawbox(i*160+32, 240, 126, 32, z+20000, 1);

This code is using 6 values, and the "drawbox" accepts 7. The last one is the alpha:

Code:
drawbox(x, y, width, height, z, color, alpha)

The number "1", in bold, its the index in the global palette (8 bits mode). If you are using other mode, you should use the rgbcolor function to do it.

Try this:
drawbox(i*160+32, 240, 126, 32, z+20000, rgbcolor(255,255,0));
This will make the bar yellow (r 255 g 255 b 0)
 
Thanks for all!

I see this link:
http://www.caskeys.com/arc/games/openbor/wiki/index.php?title=Drawbox#drawbox.28.7Bx.7D.2C_.7By.7D.2C_.7Bwidth.7D.2C_.7Bheight.7D.2C_.7Bz.7D.2C_.7Bcolor.7D.2C_.7Balpha.7D.29

And all the info and the example you show me, but only find how make specific visual effects in grafics.
I try to create this:
When the enemy has 15 points of energy (not 15 %) the energy bar shows RED, if he has more 15, EX:16 then the bar shows YELLOW, etc.

The idea is create a way to shows specific color bar for a specific amount of energy, not %. For the % its lifebar.txt
 
Its doable, just will need some work.

health = getentityproperty(pl, "health");
This line get the player health. So, you will need to add a trigger to check if the life is <= 15 ("=" sets an attribute, "==" means EQUAL", "<=" EQUAL or LESS)

That code, for what I see, draws 3 bars, to simulate a gradient bar. So you will need to give 3 values for each color

if (health<=15)// checks if the health is 15 or less and draws a red box
{

drawbox(i*160+54, 242, health, 2, z+18000, rgbcolor(255,0,0));//health red 1
                drawbox(i*160+54, 244, health, 2, z+18000, rgbcolor(250,0,0));//health red 2
                drawbox(i*160+54, 246, health, 2, z+18000, rgbcolor(245,0,0));//health red 3

      } else { // if not, draws a yellow box

drawbox(i*160+54, 242, health, 2, z+18000, rgbcolor(255,255,0));//health yellow 1
                drawbox(i*160+54, 244, health, 2, z+18000, rgbcolor(250,250,0));//health yellow 2
                drawbox(i*160+54, 246, health, 2, z+18000, rgbcolor(245,245,0));//health yellow 3

}


So, if I am not wrong, the whole code should be:

Code:
				void main()
{
    int i; int z; int t;int health;int off;
    void pl;
	char cstring;
    if(openborvariant("in_level")==0)
    {
        z = openborconstant("FRONTPANEL_Z");
        drawbox(0, 240, 480, 32, z+1000, 1);
        for(i=0; i<3; i++)
        {
            pl = getplayerproperty(i, "ent");
            if(pl==NULL())
            {
                drawbox(i*160+32, 240, 126, 32, z+20000, 1);
            }
            else
            {
                drawbox(i*160+32, 240, 126, 32, z+1110, 45);
                t = getentityproperty(pl, "mp")/10;
                drawbox(i*160+55, 240, 11*t, 16, z+1111, 92); // magic pot
				drawbox(i*160+55, 256, 11*t, 16, z+1111, 93);
                health = getentityproperty(pl, "health");
                off = (health-1)/20;
    if (health<=15)// checks if the health is 15 or less and draws a red box
		{
				
		drawbox(i*160+54, 242, health, 2, z+18000, rgbcolor(255,0,0));//health red 1
        drawbox(i*160+54, 244, health, 2, z+18000, rgbcolor(250,0,0));//health red 2
        drawbox(i*160+54, 246, health, 2, z+18000, rgbcolor(245,0,0));//health red 3
		
		} else { // if not, draws a yellow box
		
		drawbox(i*160+54, 242, health, 2, z+18000, rgbcolor(255,255,0));//health yellow 1
        drawbox(i*160+54, 244, health, 2, z+18000, rgbcolor(250,250,0));//health yellow 2
        drawbox(i*160+54, 246, health, 2, z+18000, rgbcolor(245,245,0));//health yellow 3
				
		}
				drawstring(i*160+34, 263, 1, "x"+getplayerproperty(i, "lives"));
				cstring = getglobalvar("cstring");
				if(cstring!=NULL())
				{
					drawstring(i*160+55, 256, 2, cstring);
				}
            }
        }
    }
    //drawstring(4, 100, 0, getglobalvar("debug"));
}

Pay attention that I haven't tested it yet and I am writing this at my job without OpenBOR here, so I don't know if this will work or will make your PC explodes lol.

Test and see if its works
 
Well... First i must say thanks again for all your help.
Now create a update.c and put your script there,
Nothing change.

Need call the script or change the values in lifebar.txt to match with script?
 
I got it! I removed everything we don't need and isolated the code

Save this as update.c

Code:
void main()
{
    int i; int z; int t;int health;int off;
    void pl;
	char cstring;
    if(openborvariant("in_level")==1)
    {
        z = openborconstant("FRONTPANEL_Z");
        for(i=0; i<3; i++)
        {
            pl = getplayerproperty(i, "ent");
            if(pl!=NULL())
            {
                health = getentityproperty(pl, "health");
				
			if (health<=15)// checks if the health is 15 or less and draws a red box
			{
				//drawbox(x, y, width, height, z, color, alpha)		
				drawbox(i*160+54, 142, health, 6, z+18000, rgbcolor(255,0,0));//health red
			} else { // if not, draws a yellow box
				drawbox(i*160+54, 142, health, 6, z+18000, rgbcolor(255,180,0));//health yellow 1
				
		}
            }
        }
    }
}

Just change the positions to put the bar where you want to.

you own me a beer :) j/k

see ya
 
This is the result:



Mi idea is:

When the enemies has 15 points of energy they shows a lifebar in red.
That is the signal to know he's ready to make him a fatality.
If the enemy has 16 points o energy or more, the bars shows yellow, or green, etc
 
I can't understand how works exactly this script to reach my goal.
I have tried some changes but it did not work.
Maybe my first explanation not the best, but in my last post details the real idea to my objetive.
 
Code:
void main()
{
    int i; int z; int t;int health;int off;
    void pl;
	char cstring;
    if(openborvariant("in_level")==1)
    {
        z = openborconstant("FRONTPANEL_Z");
        for(i=0; i<3; i++)
        {
            pl = getplayerproperty(i, "ent");
            if(pl!=NULL())
            {
                void self = getlocalvar("self");
				void target = findtarget(self); 
				health = getentityproperty(target, "health");
				
			
			if (health<=15)// checks if the health is 15 or less and draws a red box
			{
				//drawbox(x, y, width, height, z, color, alpha)		
				drawbox(i*160+54, 142, health, 6, z+18000, rgbcolor(255,0,0));//health red
			} else { // if not, draws a yellow box
				drawbox(i*160+54, 142, health, 6, z+18000, rgbcolor(255,180,0));//health yellow 1
				
		}
            }
        }
    }
}
 
Back
Top Bottom