Requesting help modifying msmalik681's HPbar Script.

zexika

Member
I looked at the forums and while there are a few modifications posted, I am trying to get the HP bar to display ABOVE the enemy spawned that uses this script, rather than under their feet. I understand that by modifying the DRAWBOX code by leaving X alone and modifying V gives me partial success, the bar will display above the the enemy spawn, but it's erratic. The bar will move up and down, and when the enemy falls, it floats in the air instead of following the enemy to the ground. Perhaps that's why this script is written to display the hp bar under the enemy to begin with.

I'm not a C+ programmer, nor will I pretend to be. Anyone able to to help me out with this one?

Code:
void main()
{//floating hp bars by msmalik681

void self = getlocalvar("self");		//get calling entity
int time = openborvariant("elapsed_time");	//current time in game
float x = getentityproperty(self, "x") - openborvariant("xpos")-16;	//get caller x value minus 25
float z = getentityproperty(self, "z");		//get caller z value
float y = getentityproperty(self, "y");		//get caller y value
int mp = getentityproperty(self, "mp"); 	//get current mp

float v = z - y - openborvariant("ypos") - getentityproperty(self, "maxmp");	// get caller y position and move it up by entity max mp value
int maxhp = getentityproperty(self,"maxhealth");	// get caller max hp
int hp = getentityproperty(self,"health");		// get caller current hp
int health = hp / 0.01 / maxhp / 3;			// work out current hp percentage and half it
if(!getlocalvar("dam"+self)){setlocalvar("dam"+self,health);}	//set damage to same as hp
if(getlocalvar("dam"+self))
{
drawbox(x,v,health,4,z+10,rgbcolor(223,214,73),0);		//draw hp box using x and y cords also z value is +2 so its on top of other 2 boxes
drawbox(x,v,getlocalvar("dam"+self),4,z+9,rgbcolor(181,26,0),0);			//second box to show damage with a z+1 value so its under hp bar and dam controls its size
drawbox(x,v,33,4,z+8,rgbcolor(0,0,100),0);					//black box in background to show how much original life bar was
drawbox(x-1,v-1,35,6,z+7,rgbcolor(8,80,232),0);			//life bar border
drawbox(x-3,v+1,35,6,z+6,rgbcolor(0,24,112),0);			//life bar border
//drawstring(x,v+10,4,hp);
}

	if(health<getlocalvar("dam"+self) && time%50==0)		// if hp box smaller then damage box reduce damage every 50 tics
   		{
		setlocalvar("dam"+self,getlocalvar("dam"+self)-1);		//reduce damage by 1
		}
}
 
Zexika

Hello. I can't help too much with the script you are using, but I can show the script I'm using in some games.
You need to call the script below in your ondraw.c event.

Code:
void main()
{//Draw life bar in the screen, entity binded like RPG games
	void self = getlocalvar("self");
	
	if(openborvariant("in_level")){ //IN ANY LEVEL??
		int maxLife	= getentityproperty(self, "maxhealth");
		int life 	= getentityproperty(self, "health");
		int x 		= getentityproperty(self, "x");
		int y 		= getentityproperty(self, "y");
		int z 		= getentityproperty(self, "z");
		float xPos 	= openborvariant("xpos");
		float yPos 	= openborvariant("ypos");
		float xSize	= 20; //BAR WIDTH INCREASE FACTOR, MORE VALUE IS MORE SIZE
		float ySize	= 2; //BAR HEIGHT INCREASE FACTOR, MORE VALUE IS MORE SIZE
		float xDif	= 0; //BAR POSITION IN X AXIS, USE THIS TO MOVE ALL BARS TOGETHER
		float yDif	= 0; //BAR POSITION IN Y AXIS, USE THIS TO MOVE ALL BARS TOGETHER
		
		if(life > 0){ //ENTITY IS ALIVE??
			life 		= (life*xSize)/(maxLife); //CALCULATE REMAINING LIFE BAR SIZE
			maxLife		= (maxLife*xSize)/(maxLife); //CALCULATE MAX LIFE BAR SIZE
			x 		= x-xPos-(maxLife/2)+xDif; //CALCULATE X POSITION TO BIND BAR IN THE ENTITY, OFFSET IS ALWAYS THE CENTER
			y 		= z-yPos-y+yDif; //CALCULATE Y POSITION TO BIND BAR IN THE ENTITY
			drawbox(x, y, life, ySize, z+3, rgbcolor(0xFF,0xFF,0x00), 0); //YELLOW BAR, LIFE REMAINING
			drawbox(x, y, maxLife, ySize, z+1, rgbcolor(0xFF,0x00,0x00), 0); //RED BAR, LIFE LOST
			drawbox(x, y-1, maxLife, ySize*2, z, rgbcolor(0xFF,0xFF,0xFF), 0); //WHITE BORDER (UP/DOWN)
			drawbox(x-1, y, maxLife+2, ySize, z, rgbcolor(0xFF,0xFF,0xFF), 0); //WHITE BORDER (LEFT/RIGHT)
		}
	}
}

You can change the bar's height by changing the "yDif" value, or you can replace by the character's height property.
 
You sir, f***** rock! That's EXACTLY what I wanted. This script is easier to modify too. I set yDif to negative 108 to achieve what I wanted.
Code:
		float yDif	= -108; //BAR POSITION IN Y AXIS, USE THIS TO MOVE ALL BARS TOGETHER

Thank you again friend, I have a lot of enemies to add this script to, but that's more than fine.  Is there a cheat sheet to modify the color codes for the rgbcolor section in the drawbox section? YELLOW BAR, RED BAR, and WHITE BORDER are clearly spelled out and defined, but I'd love the option to modify these. I suppose I could play around with the color offsets and see what it does, but was hoping to save some time with the other tasks I'm working on at the moment. Any chance you'd know the offset codes for Dark Green, Lime Green, Orange, Grey, and Black? I'd like to modify this to do the following:

Code:
	        drawbox(x, y, life, ySize, z+5, rgbcolor(0xFF,0xFF,0x00), 0); //DARK GREEN BAR, 100% LIFE REMAINING
		        drawbox(x, y, life, ySize, z+4, rgbcolor(0xFF,0xFF,0x00), 0); //LIME GREEN BAR, 85% LIFE REMAINING
                        drawbox(x, y, life, ySize, z+3, rgbcolor(0xFF,0xFF,0x00), 0); //ORANGE BAR, 70% LIFE REMAINING
                        drawbox(x, y, life, ySize, z+2, rgbcolor(0xFF,0xFF,0x00), 0); //YELLOW BAR, 50% LIFE REMAINING
			drawbox(x, y, maxLife, ySize, z+1, rgbcolor(0xFF,0x00,0x00), 0); //BRIGHT RED BAR, 25% LIFE REMAINING
			drawbox(x, y, maxLife, ySize, z+0, rgbcolor(0xFF,0x00,0x00), 0); //DARK RED BAR, LIFE LOST
			drawbox(x, y-1, maxLife, ySize*2, z, rgbcolor(0xFF,0xFF,0xFF), 0); //GREY BORDER (UP/DOWN)
			drawbox(x-1, y, maxLife+2, ySize, z, rgbcolor(0xFF,0xFF,0xFF), 0); //BLACK BORDER (LEFT/RIGHT))

Update:
Community Tip: RBG Hex Codes can be found here: here:https://support.pstnet.com/hc/en-us/articles/360021200914-INFO-CColor-Color-Object-RteColor-provides-expanded-colors-and-HTML-color-listing-17814-

Okay, so I've started on this script. I did change the color RGB Hex values, but now my issue is the script will only call TWO color variants. I'm assuming that's because the life and maxLife formula needs additional code to allocate more color bars.
life = (life*xSize)/(maxLife); //CALCULATE REMAINING LIFE BAR SIZE
maxLife = (maxLife*xSize)/(maxLife); //CALCULATE MAX LIFE BAR SIZE

Code:
void main()
{//Draw life bar in the screen, entity binded like RPG games
	void self = getlocalvar("self");
	
	if(openborvariant("in_level")){ //IN ANY LEVEL??
		int maxLife	= getentityproperty(self, "maxhealth");
		int life 	= getentityproperty(self, "health");
		int x 		= getentityproperty(self, "x");
		int y 		= getentityproperty(self, "y");
		int z 		= getentityproperty(self, "z");
		float xPos 	= openborvariant("xpos");
		float yPos 	= openborvariant("ypos");
		float xSize	= 28; //BAR WIDTH INCREASE FACTOR, MORE VALUE IS MORE SIZE
		float ySize	= 2; //BAR HEIGHT INCREASE FACTOR, MORE VALUE IS MORE SIZE
		float xDif	= 0; //BAR POSITION IN X AXIS, USE THIS TO MOVE ALL BARS TOGETHER
		float yDif	= -108; //BAR POSITION IN Y AXIS, USE THIS TO MOVE ALL BARS TOGETHER
		
		if(life > 0){ //ENTITY IS ALIVE??
			life 		= (life*xSize)/(maxLife); //CALCULATE REMAINING LIFE BAR SIZE
			maxLife		= (maxLife*xSize)/(maxLife); //CALCULATE MAX LIFE BAR SIZE
			x 		= x-xPos-(maxLife/2)+xDif; //CALCULATE X POSITION TO BIND BAR IN THE ENTITY, OFFSET IS ALWAYS THE CENTER
			y 		= z-yPos-y+yDif; //CALCULATE Y POSITION TO BIND BAR IN THE ENTITY
			drawbox(x, y, life, ySize, z+5, rgbcolor(0xFF,0xFF,0x00), 0); //Dark Green Health Bar, 100% LIFE REMAINING
			drawbox(x, y, maxLife, ySize, z+4, rgbcolor(0x90,0xEE,0x90), 0); //Green Health Bar, 80% LIFE REMAINING
			drawbox(x, y, maxLife, ySize, z+3, rgbcolor(0xFF,0xA5,0x00), 0); //Orange Health Bar, 60% LIFE REMAINING
			drawbox(x, y, maxLife, ySize, z+2, rgbcolor(0x00,0xFF,0x00), 0); //Yellow Health Bar, 40% LIFE REMAINING
			drawbox(x, y, maxLife, ySize, z+1, rgbcolor(0xFF,0x00,0x00), 0); //Light Red Health Bar, 20% LIFE REMAINING
			drawbox(x, y, maxLife, ySize, z+0, rgbcolor(0x8B,0x00,0x00), 0); //Dark Red Health Bar, 0% LIFE REMAINING
			drawbox(x, y-1, maxLife, ySize*2, z, rgbcolor(0x80,0x80,0x80), 0); //Grey Border (UP/DOWN)
			drawbox(x-1, y, maxLife+2, ySize, z, rgbcolor(0x00,0x00,0x00), 0); //Black Border (LEFT/RIGHT)
		}
	}
}

I'm close, but I'm definitely missing something. Would you be kind enough to help me complete this wonderful script? :)
 
Zexika

Great, I'm glad it worked for your game. About the colors, if I understand correctly you want to change the health color (YELLOW) according to the life remaining, right?

EDIT: Please, test this new code in your game. Now it will get the current life and will define the current color according to it.

Code:
void main()
{//Draw life bar in the screen, entity binded like RPG games
	void self = getlocalvar("self");
	
	if(openborvariant("in_level")){ //IN ANY LEVEL??
		int maxLife	= getentityproperty(self, "maxhealth");
		int life 	= getentityproperty(self, "health");
		int x 		= getentityproperty(self, "x");
		int y 		= getentityproperty(self, "y");
		int z 		= getentityproperty(self, "z");
		int percent	= maxLife/5; //SPLIT THE ENTIRE LIFE IN 5 PARTS, 20% EACH
		int color;
		float xPos 	= openborvariant("xpos");
		float yPos 	= openborvariant("ypos");
		float xSize	= 20; //BAR WIDTH INCREASE FACTOR, MORE VALUE IS MORE SIZE
		float ySize	= 2; //BAR HEIGHT INCREASE FACTOR, MORE VALUE IS MORE SIZE
		float xDif	= 0; //BAR POSITION IN X AXIS, USE THIS TO MOVE ALL BARS TOGETHER
		float yDif	= 0; //BAR POSITION IN Y AXIS, USE THIS TO MOVE ALL BARS TOGETHER

		if(life >= maxLife)				{color = rgbcolor(0x00,0xFF,0x00);}else	//DARK GREEN HEALTH BAR, 100% LIFE REMAINING
		if(life < maxLife && life >= percent*4)		{color = rgbcolor(0x90,0xEE,0x90);}else	//GREEN HEALTH BAR, BELOW 100% AND ABOVE 80% LIFE REMAINING
		if(life < percent*4 && life >= percent*3)	{color = rgbcolor(0xFF,0xFF,0x00);}else	//YELLOW HEALTH BAR, BELOW 80% AND ABOVE 60% LIFE REMAINING
		if(life < percent*3 && life >= percent*2)	{color = rgbcolor(0xFF,0xA5,0x00);}else	//ORANGE HEALTH BAR, BELOW 60% AND ABOVE 40% LIFE REMAINING
		if(life < percent*2 && life >= percent)		{color = rgbcolor(0xFF,0x00,0x00);}else	//LIGHT RED HEALTH BAR, BELOW 40% AND ABOVE 20% LIFE REMAINING
		if(life < percent)				{color = rgbcolor(0x8B,0x00,0x00);}	//DARK RED HEALTH BAR, BELOW 20% LIFE REMAINING
		
		if(life > 0){ //ENTITY IS ALIVE??
			life		= (life*xSize)/(maxLife); //CALCULATE REMAINING LIFE BAR SIZE
			maxLife		= (maxLife*xSize)/(maxLife); //CALCULATE MAX LIFE BAR SIZE
			x		= x-xPos-(maxLife/2)+xDif; //CALCULATE X POSITION TO BIND BAR IN THE ENTITY, OFFSET IS ALWAYS THE CENTER
			y		= z-yPos-y+yDif; //CALCULATE Y POSITION TO BIND BAR IN THE ENTITY
			drawbox(x, y, life, ySize, z+1, color, 0); //MISC COLOR BAR, LIFE REMAINING
			drawbox(x, y-1, maxLife, ySize*2, z, rgbcolor(0x80,0x80,0x80), 0); //GREY BORDER (UP/DOWN)
			drawbox(x-1, y, maxLife+2, ySize, z, rgbcolor(0x00,0x00,0x00), 0); //BLACK BORDER (LEFT/RIGHT)
		}
	}
}
 
Kratus said:
Zexika

Great, I'm glad it worked for your game. About the colors, if I understand correctly you want to change the health color (YELLOW) according to the life remaining, right?

EDIT: Please, test this new code in your game. Now it will get the current life and will define the current color according to it.

Code:
void main()
{//Draw life bar in the screen, entity binded like RPG games
	void self = getlocalvar("self");
	
	if(openborvariant("in_level")){ //IN ANY LEVEL??
		int maxLife	= getentityproperty(self, "maxhealth");
		int life 	= getentityproperty(self, "health");
		int x 		= getentityproperty(self, "x");
		int y 		= getentityproperty(self, "y");
		int z 		= getentityproperty(self, "z");
		int percent	= maxLife/5; //SPLIT THE ENTIRE LIFE IN 5 PARTS, 20% EACH
		int color;
		float xPos 	= openborvariant("xpos");
		float yPos 	= openborvariant("ypos");
		float xSize	= 20; //BAR WIDTH INCREASE FACTOR, MORE VALUE IS MORE SIZE
		float ySize	= 2; //BAR HEIGHT INCREASE FACTOR, MORE VALUE IS MORE SIZE
		float xDif	= 0; //BAR POSITION IN X AXIS, USE THIS TO MOVE ALL BARS TOGETHER
		float yDif	= 0; //BAR POSITION IN Y AXIS, USE THIS TO MOVE ALL BARS TOGETHER

		if(life >= maxLife)				{color = rgbcolor(0x00,0xFF,0x00);}else	//DARK GREEN HEALTH BAR, 100% LIFE REMAINING
		if(life < maxLife && life >= percent*4)		{color = rgbcolor(0x90,0xEE,0x90);}else	//GREEN HEALTH BAR, BELOW 100% AND ABOVE 80% LIFE REMAINING
		if(life < percent*4 && life >= percent*3)	{color = rgbcolor(0xFF,0xFF,0x00);}else	//YELLOW HEALTH BAR, BELOW 80% AND ABOVE 60% LIFE REMAINING
		if(life < percent*3 && life >= percent*2)	{color = rgbcolor(0xFF,0xA5,0x00);}else	//ORANGE HEALTH BAR, BELOW 60% AND ABOVE 40% LIFE REMAINING
		if(life < percent*2 && life >= percent)		{color = rgbcolor(0xFF,0x00,0x00);}else	//LIGHT RED HEALTH BAR, BELOW 40% AND ABOVE 20% LIFE REMAINING
		if(life < percent)				{color = rgbcolor(0x8B,0x00,0x00);}	//DARK RED HEALTH BAR, BELOW 20% LIFE REMAINING
		
		if(life > 0){ //ENTITY IS ALIVE??
			life		= (life*xSize)/(maxLife); //CALCULATE REMAINING LIFE BAR SIZE
			maxLife		= (maxLife*xSize)/(maxLife); //CALCULATE MAX LIFE BAR SIZE
			x		= x-xPos-(maxLife/2)+xDif; //CALCULATE X POSITION TO BIND BAR IN THE ENTITY, OFFSET IS ALWAYS THE CENTER
			y		= z-yPos-y+yDif; //CALCULATE Y POSITION TO BIND BAR IN THE ENTITY
			drawbox(x, y, life, ySize, z+1, color, 0); //MISC COLOR BAR, LIFE REMAINING
			drawbox(x, y-1, maxLife, ySize*2, z, rgbcolor(0x80,0x80,0x80), 0); //GREY BORDER (UP/DOWN)
			drawbox(x-1, y, maxLife+2, ySize, z, rgbcolor(0x00,0x00,0x00), 0); //BLACK BORDER (LEFT/RIGHT)
		}
	}
}

At to the first question on Yellow referencing health, 100% correct with the added exception of it being green. Which by the way, not only did you already realize this, but you even filled in the RBG hex values for me... damn dude, you really went out of you way for me. Thank you.

Secondly thank you so much for your willingness to do that for me! Not only will I ensure your name is posted in the script header, but I want you to know I will be adding you to the Credits screen of my project as a special thank you!

I am at work but will test your new script out first thing when I get home in a few hours! Thank you so much for your willingness to be so helpful. :)
 
Not sure if this was the most up to date version of my hp bar script it would be in my tekken demo on gamejolt if you unpack it.

For my script each enemies mp will be used to determin the height of the bar as depending on the size of the enemy you would want to adjust the height for each enemy.
 
Kratus!!! You are amazing, it worked flawlessly straight away. I love you in the purest and most culturally acceptable way possible without it being awkward! LOL  ;D ;D ;D ;D

msmalik681 said:
Not sure if this was the most up to date version of my hp bar script it would be in my tekken demo on gamejolt if you unpack it.

For my script each enemies mp will be used to determin the height of the bar as depending on the size of the enemy you would want to adjust the height for each enemy.

You're spot on. I stumbled on your tekken demo and also tried another variant I found on the forums. Lol :D
 
Zexika said:
Kratus!!! You are amazing, it worked flawlessly straight away. I love you in the purest and most culturally acceptable way possible without it being awkward! LOL  ;D ;D ;D ;D

msmalik681 said:
Not sure if this was the most up to date version of my hp bar script it would be in my tekken demo on gamejolt if you unpack it.

For my script each enemies mp will be used to determin the height of the bar as depending on the size of the enemy you would want to adjust the height for each enemy.

You're spot on. I stumbled on your tekken demo and also tried another variant I found on the forums. Lol :D

Great!! It's good to know that the code worked well for your game :D
 
Back
Top Bottom