View Full Version : [Uscript]SimpleHealthBar
squirrel5153
24th July 2005, 09:59
this is code for a simple health bar (your health) that you can simple add to any existing menu or put in in a function if you like
enjoy:
Canvas.SetPos(700,700);
if(Me.Health < 35 )
{
Canvas.SetDrawColor(255,0,0);
}
else if (Me.Health < 60)
{
Canvas.SetDrawColor(255,255,0);
}
else if (Me.Health > 60)
{
Canvas.SetDrawColor(0,255,0);
}
Canvas.DrawRect(Texture'Engine.WhiteSquareTexture' , Me.Health , 8);
Canvas.SetDrawColor(255,0,0);
Canvas.SetPos(800,700);
Canvas.DrawRect(Texture'Engine.WhiteSquareTexture' , ((100 - Me.Health) * -1) , 8);
Canvas.SetDrawColor(0,0,255);
Canvas.SetPos(698,700);
Canvas.DrawText("|");
Canvas.SetPos(802,700);
Canvas.DrawText("|");
No1uKnow
24th July 2005, 17:48
atleast someone realises using textures already in the game and not including your own is more effecient.
Added to the Uscript sticky list, thanks.
sharkyboy
28th July 2005, 10:27
Im thinking that im the worst coder on the whole word :(
----- AGP (Release)
----- basics (Release)
Analyzing...
Parsing MyConsole
Parsing MyInteraction
Error in MyInteraction.uc (141): Unexpected 'Canvas'
Compile aborted due to errors.
Success - 0 error(s), 1 warning(s)
what can i do about it?
If i past to the basic bot any file it always gives errors :(
HyPeR-X
28th July 2005, 10:33
Small adition:
Function DrawHealthBar (Canvas Canvas, Float PosX, Float PosY, Pawn Target)
{
Local Float HealthPct;
HealthPct = 1.0 * Target.Health / 100;
If (HealthPct > 0)
{
Canvas.Style = 1;
Canvas.DrawColor = MyBlackColor;
Canvas.Setpos(PosX - 20, PosY - 16);
Canvas.DrawRect(Texture'MenuWhite', 40, 8);
Canvas.DrawColor = MyWhiteColor;
Canvas.Setpos(PosX - 19, PosY - 15);
Canvas.DrawRect(Texture'MenuWhite', 38, 6);
Canvas.DrawColor = GetBarColor(HealthPct);
Canvas.Setpos(PosX - 19, PosY - 15);
Canvas.DrawRect(Texture'MenuWhite', 38 * HealthPct, 6);
}
}
Final Function Color GetBarColor (Float HealthPct)
{
Local Color Temp;
Temp.A = 0;
If (HealthPct > 0.66)
{
Temp.R = 0;
Temp.G = 255 * HealthPct;
Temp.B = 0;
}
Else
{
If (HealthPct > 0.33)
{
Temp.R = 225 - (255 * HealthPct);
Temp.G = 1 + (255 * HealthPct);
Temp.B = 0;
}
Else
{
Temp.R = 255 - (255 * HealthPct);
Temp.G = 0;
Temp.B = 0;
}
}
Return Temp;
}
This is the code wich im using in my UN-Released radar atm ... when i finish it and fix all the bug's in the radar i will release it with source included ... everybody is allowed to use my code as long as you DO give credits to me ;)
- HyPz
RandomDude55
28th July 2005, 10:56
if ( Target.Health > 70 )
{
Canvas.SetDrawColor(0,255,0);
}
else if ( Target.Health > 40 )
{
Canvas.SetDrawColor(255,255,0);
}
else if ( Target.Health > 0 )
{
Canvas.SetDrawColor(255,0,0);
}
is the correct coloring. The health in aa for some reason doesn't go by 1/3 but like what i just posted. It was in the health bars i release quite a time ago on here. Anyways nice job guys.
kolbybrooks
28th July 2005, 11:02
Im thinking that im the worst coder on the whole word
----- AGP (Release)
----- basics (Release)
Analyzing...
Parsing MyConsole
Parsing MyInteraction
Error in MyInteraction.uc (141): Unexpected 'Canvas'
Compile aborted due to errors.
Success - 0 error(s), 1 warning(s)
what can i do about it?
If i past to the basic bot any file it always gives errors
Use this for copy to Basicbot.
Canvas.SetPos(700,700);
if(Me.Health < 35 )
{
MyCanvas.SetDrawColor(255,0,0);
}
else if (Me.Health < 60)
{
MyCanvas.SetDrawColor(255,255,0);
}
else if (Me.Health > 60)
{
MyCanvas.SetDrawColor(0,255,0);
}
MyCanvas.DrawRect(Texture'Engine.WhiteSquareTextur e' , Me.Health , 8);
MyCanvas.SetDrawColor(255,0,0);
MyCanvas.SetPos(800,700);
MyCanvas.DrawRect(Texture'Engine.WhiteSquareTextur e' , ((100 - Me.Health) * -1) , 8);
MyCanvas.SetDrawColor(0,0,255);
MyCanvas.SetPos(698,700);
MyCanvas.DrawText("|");
MyCanvas.SetPos(802,700);
MyCanvas.DrawText("|");
RandomDude55
28th July 2005, 11:32
Canvas.SetPos(700,700); top line --> MyCanvas.SetPos(700,700);
Missed that kolbybrooks if you wanna edit you post so people don't have problems copying that :P But gj helping people out.
HyPeR-X
28th July 2005, 14:37
if ( Target.Health > 70 )
{
Canvas.SetDrawColor(0,255,0);
}
else if ( Target.Health > 40 )
{
Canvas.SetDrawColor(255,255,0);
}
else if ( Target.Health > 0 )
{
Canvas.SetDrawColor(255,0,0);
}
is the correct coloring. The health in aa for some reason doesn't go by 1/3 but like what i just posted. It was in the health bars i release quite a time ago on here. Anyways nice job guys.
Mine isn't using the 1/3 for the health ... it calculate's the percentage of health left on the target and calculates the color acoding to that (So it wont be red, yellow/orange, green) mine change's everytime someone lose's a bit of health ;)
- HyPz
RandomDude55
29th July 2005, 01:55
O i missed that :P thats pretty cool Hyper, i was refering to squirrel's though :P
Just dumb me trying to be helpful i guess :P
Killer-x
31st July 2005, 21:26
Thanks I May Add This To My Bot i wont forget credits :p
YoYoReturns
31st July 2005, 22:11
atleast someone realises using textures already in the game and not including your own is more effecient.
prefer using no textures ;p.
btw hyp, i dont think random ment u, but more the topic starter, who is using random health percentages.
BANANABOMB
1st August 2005, 00:17
Small adition:
Function DrawHealthBar (Canvas Canvas, Float PosX, Float PosY, Pawn Target)
{
Local Float HealthPct;
HealthPct = 1.0 * Target.Health / 100;
If (HealthPct > 0)
{
Canvas.Style = 1;
Canvas.DrawColor = MyBlackColor;
Canvas.Setpos(PosX - 20, PosY - 16);
Canvas.DrawRect(Texture'MenuWhite', 40, 8);
Canvas.DrawColor = MyWhiteColor;
Canvas.Setpos(PosX - 19, PosY - 15);
Canvas.DrawRect(Texture'MenuWhite', 38, 6);
Canvas.DrawColor = GetBarColor(HealthPct);
Canvas.Setpos(PosX - 19, PosY - 15);
Canvas.DrawRect(Texture'MenuWhite', 38 * HealthPct, 6);
}
}
Final Function Color GetBarColor (Float HealthPct)
{
Local Color Temp;
Temp.A = 0;
If (HealthPct > 0.66)
{
Temp.R = 0;
Temp.G = 255 * HealthPct;
Temp.B = 0;
}
Else
{
If (HealthPct > 0.33)
{
Temp.R = 225 - (255 * HealthPct);
Temp.G = 1 + (255 * HealthPct);
Temp.B = 0;
}
Else
{
Temp.R = 255 - (255 * HealthPct);
Temp.G = 0;
Temp.B = 0;
}
}
Return Temp;
}
This is the code wich im using in my UN-Released radar atm ... when i finish it and fix all the bug's in the radar i will release it with source included ... everybody is allowed to use my code as long as you DO give credits to me ;)
- HyPz
Pretty neat, allthough this isn't the best one.
jefn000
2nd October 2005, 15:55
I'm having a problem: i use this code for my Health Bars and esp:
final function DrawEnemyESP (Canvas MyCanvas, PlayerReplicationInfo PRI)
{
Local float PosX;
Local Float PosY;
Local float StrX;
local String StrName;
Local String StrDist;
local Pickup Weapon;
Local Float HealthPct;
if (PRI.Team.TeamIndex != Me.PlayerReplicationInfo.Team.TeamIndex)
{
if (LocationToScreen(MyCanvas, PRI, PosX, PosY, StrDist))
{
StrName = PRI.PlayerName;
StrDist = StrDist;
DrawMyIcon(MyCanvas, PosX, PosY, MyRedColor, 2);
MyCanvas.DrawColor = MyRedColor;
MyCanvas.Style = 3;
MyCanvas.Font = MyCanvas.TinyFont;
MyCanvas.Setpos(PosX - StrX / 2, PosY - 20);
MyCanvas.DrawTextClipped(StrName);
MyCanvas.Setpos(PosX - StrX / 2, PosY + 10);
MyCanvas.DrawTextClipped("Distance: "$StrDist);
MyCanvas.Setpos(PosX - StrX / 2, PosY + 20);
MyCanvas.DrawText(Right(string(Weapon.Name),Len(st ring(Weapon.Name)) - 8));
HealthPct = 1.0 * Target.Health / 100;
if(Me.Health < 35 )
{
MyCanvas.SetDrawColor(255,0,0);
}
else if (Me.Health < 60)
{
MyCanvas.SetDrawColor(255,255,0);
}
else if (Me.Health > 60)
{
MyCanvas.SetDrawColor(0,255,0);
}
MyCanvas.Style = 1;
MyCanvas.DrawColor = MyWhiteColor;
MyCanvas.SetPos(PosX + 10, PosY - 8);
MyCanvas.DrawRect(Texture'Engine.WhiteSquareTextur e', 40, 6);
MyCanvas.DrawColor = MyRedColor;
MyCanvas.Setpos(PosX + 11, PosY - 7);
MyCanvas.DrawRect(Texture'Engine.WhiteSquareTextur e', 38, 4);
MyCanvas.DrawColor = MyGreenColor;
MyCanvas.Setpos(PosX + 11, PosY - 7);
MyCanvas.DrawRect(Texture'Engine.WhiteSquareTextur e', 38 * HealthPct, 4);
MyCanvas.Style = 3;
MyCanvas.DrawColor = GetTeamColor(Target.PlayerReplicationInfo);
}
}
}
So, the healthbars show up like they should, but they are allready red before some1 got shot... :mad: Can any1 help we??
No1uKnow
2nd October 2005, 18:10
erm, why are you doing me.health, shouldnt it be target ( or target pawn name ).health ?
jefn000
3rd October 2005, 10:31
Nv, allready got another way to make it work ;)
-Theblackkill
11th October 2005, 21:56
Let this code see |YOUR health of that from the enemy?
Powered by vBulletin™ Version 4.0.2 Copyright © 2010 vBulletin Solutions, Inc. All rights reserved.