Code:
class SwordHUD extends UTHUD;
//var SidePawn Jump;
//var int jumptest;
function DrawHealthBar(float percentFull)
{
local int currentBarWidth;
local int maxBarWidth;
local int barHeight;
local int barPositionX;
local int barPositionY;
local int healthPct;
maxBarWidth = 300;
barHeight = 20;
barPositionX = 20;
barPositionY = 20;
healthPct = percentFull * 100;
currentBarWidth = maxBarWidth * percentFull;
// Draw the "filled" part of the bar
Canvas.SetPos(barPositionX, barPositionY); // X, Y position
Canvas.SetDrawColor(0, 200, 0, 200); // R, G, B, A for bar rectangle
Canvas.DrawRect(currentBarWidth, barHeight);
// Draw the empty part of the bar
Canvas.SetPos(barPositionX + currentBarWidth, barPositionY);
Canvas.SetDrawColor(200, 255, 200, 110);
Canvas.DrawRect(maxBarWidth - currentBarWidth, barHeight);
// Draw some text next to the bar
Canvas.SetPos(barPositionX + maxBarWidth + 10, barPositionY);
Canvas.SetDrawColor(0, 200, 0, 200);
Canvas.Font = class'Engine'.static.GetMediumFont();
Canvas.DrawText("Health: "$healthPct$"%");
}
function DrawManaBar(float percentFull)
{
local int currentBarWidth;
local int maxBarWidth;
local int barHeight;
local int barPositionX;
local int barPositionY;
local int manaPct;
maxBarWidth = 300;
barHeight = 20;
barPositionX = 20;
barPositionY = 60;
manaPct = percentFull * 100;
currentBarWidth = maxBarWidth * percentFull;
// Draw the "filled" part of the bar
Canvas.SetPos(barPositionX, barPositionY); // X, Y position
Canvas.SetDrawColor(0, 0, 200, 200); // R, G, B, A for bar rectangle
Canvas.DrawRect(currentBarWidth, barHeight);
// Draw the empty part of the bar
Canvas.SetPos(barPositionX + currentBarWidth, barPositionY);
Canvas.SetDrawColor(200, 200, 255, 110);
Canvas.DrawRect(maxBarWidth - currentBarWidth, barHeight);
// Draw some text next to the bar
Canvas.SetPos(barPositionX + maxBarWidth + 10, barPositionY);
Canvas.SetDrawColor(0, 0, 200, 200);
Canvas.Font = class'Engine'.static.GetMediumFont();
Canvas.DrawText("Mana: "$manaPct$"%");
}
function DrawAmmoBar(float percentFull)
{
local int currentBarWidth;
local int maxBarWidth;
local int barHeight;
local int barPositionX;
local int barPositionY;
local int AmmoPct;
maxBarWidth = 300;
barHeight = 20;
barPositionX = 20;
barPositionY = 40;
if (PawnOwner.Weapon!=None)
{
if(UTWeapon(PawnOwner.Weapon).MaxAmmoCount==1)
{
AmmoPct = percentFull;
}
else
{
AmmoPct = percentFull * 100;
}
}
currentBarWidth = maxBarWidth * percentFull;
// Draw the "filled" part of the bar
Canvas.SetPos(barPositionX, barPositionY); // X, Y position
Canvas.SetDrawColor(200, 0, 200, 200); // R, G, B, A for bar rectangle
Canvas.DrawRect(currentBarWidth, barHeight);
// Draw the empty part of the bar
Canvas.SetPos(barPositionX + currentBarWidth, barPositionY);
Canvas.SetDrawColor(255, 200, 255, 110);
Canvas.DrawRect(maxBarWidth - currentBarWidth, barHeight);
// Draw some text next to the bar
Canvas.SetPos(barPositionX + maxBarWidth + 10, barPositionY);
Canvas.SetDrawColor(200, 0, 200, 200);
Canvas.Font = class'Engine'.static.GetMediumFont();
Canvas.DrawText("Ammo: "$AmmoPct);
}
function DrawBar(String Title, float Value, float MaxValue,int X, int Y, int R, int G, int B) // Create our function used to draw bars
{
local int PosX; //Declare our variable representing our postition on the X-axis
local int BarSizeX; //Declare our variable representing the size of our bar
PosX = X; //Where we should draw the rectangle
BarSizeX = 300 * FMin(Value / MaxValue, 1); // size of active rectangle (change 300 to however big you want your bar to be)
//Displays active rectangle
Canvas.SetPos(PosX,Y);
Canvas.SetDrawColor(R, G, B, 200);
Canvas.DrawRect(BarSizeX, 12);
//Displays empty rectangle
Canvas.SetPos(BarSizeX+X,Y);
Canvas.SetDrawColor(255, 255, 255, 80);
Canvas.DrawRect(300 - BarSizeX, 12); //Change 300 to however big you want your bar to be
//Draw our title
Canvas.SetPos(PosX+300+5, Y); //Change 300 to however big your bar is
Canvas.SetDrawColor(R, G, B, 200);
Canvas.Font = class'Engine'.static.GetSmallFont();
Canvas.DrawText(Title);
}
//function DrawLevelBar(float percentFull)
//{
// local int currentBarWidth;
// local int maxBarWidth;
// local int barHeight;
// local int barPositionX;
// local int barPositionY;
// local SwordTestPlayerController PC;
//
// maxBarWidth = 300;
// barHeight = 20;
// barPositionX = 20;
// barPositionY = 80;
//
// PC = SwordTestPlayerController(PlayerOwner);
//
// currentBarWidth = maxBarWidth * percentFull;
//
// // Draw the "filled" part of the bar
// Canvas.SetPos(barPositionX, barPositionY); // X, Y position
// Canvas.SetDrawColor(200, 0, 0, 200); // R, G, B, A for bar rectangle
// Canvas.DrawRect(currentBarWidth, barHeight);
//
// // Draw the empty part of the bar
// Canvas.SetPos(barPositionX + currentBarWidth, barPositionY);
// Canvas.SetDrawColor(255, 200, 200, 110);
// Canvas.DrawRect(maxBarWidth - currentBarWidth, barHeight);
//
// // Draw some text next to the bar
// Canvas.SetPos(barPositionX + maxBarWidth + 10, barPositionY);
// Canvas.SetDrawColor(200, 0, 0, 200);
// Canvas.Font = class'Engine'.static.GetMediumFont();
// Canvas.DrawText("Level: "@PC.Level);
//}
//function DrawXPBar(float percentFull)
//{
// local int currentBarWidth;
// local int maxBarWidth;
// local int barHeight;
// local int barPositionX;
// local int barPositionY;
// local SwordTestPlayerController PC;
//
// maxBarWidth = 300;
// barHeight = 20;
// barPositionX = 20;
// barPositionY = 100;
//
// PC = SwordTestPlayerController(PlayerOwner);
//
// currentBarWidth = maxBarWidth * percentFull;
//
// // Draw the "filled" part of the bar
// Canvas.SetPos(barPositionX, barPositionY); // X, Y position
// Canvas.SetDrawColor(200, 200, 0, 200); // R, G, B, A for bar rectangle
// Canvas.DrawRect(currentBarWidth, barHeight);
//
// // Draw the empty part of the bar
// Canvas.SetPos(barPositionX + currentBarWidth, barPositionY);
// Canvas.SetDrawColor(255, 255, 200, 110);
// Canvas.DrawRect(maxBarWidth - currentBarWidth, barHeight);
//
// // Draw some text next to the bar
// Canvas.SetPos(barPositionX + maxBarWidth + 10, barPositionY);
// Canvas.SetDrawColor(200, 200, 0, 200);
// Canvas.Font = class'Engine'.static.GetMediumFont();
// Canvas.DrawText("XP:"@PC.XP$"/"$PC.XPRequiredForNextLevel);
//}
//function DrawArmorBar(float percentFull)
//{
// local int currentBarWidth;
// local int maxBarWidth;
// local int barHeight;
// local int barPositionX;
// local int barPositionY;
// local int ArmorPct;
//
// maxBarWidth = 300;
// barHeight = 20;
// barPositionX = 20;
// barPositionY = 60;
// ArmorPct = percentFull;
//
// currentBarWidth = percentFull * 3;
//
// // Draw the "filled" part of the bar
// Canvas.SetPos(barPositionX, barPositionY); // X, Y position
// Canvas.SetDrawColor(200, 200, 0, 200); // R, G, B, A for bar rectangle
// Canvas.DrawRect(currentBarWidth, barHeight);
//
// // Draw the empty part of the bar
// Canvas.SetPos(barPositionX + currentBarWidth, barPositionY);
// Canvas.SetDrawColor(200, 255, 0, 110);
// Canvas.DrawRect(maxBarWidth - currentBarWidth, barHeight);
//
// // Draw some text next to the bar
// Canvas.SetPos(barPositionX + maxBarWidth + 10, barPositionY);
// Canvas.SetDrawColor(200, 200, 0, 200);
// Canvas.Font = class'Engine'.static.GetMediumFont();
// Canvas.DrawText("Armor: "$ArmorPct$"%");
//}
function DrawString(string text, int X, int Y, int R, int G, int B, int A)
{
Canvas.SetPos(X, Y);
Canvas.SetDrawColor(R, G, B, A);
Canvas.Font = class'Engine'.static.GetMediumFont();
Canvas.DrawText(text);
}
function DrawGameHud()
{
local SwordTestPlayerController PC;
local string CurEqWeap;
// Type cast the PlayerOwner property of the HUD to SidePlayerController
PC = SwordTestPlayerController(PlayerOwner);
if (!PlayerOwner.IsDead())
{
// Display health bar only when the player hasn't died
if(PlayerOwner.Pawn.HealthMax > 0)
{
DrawHealthBar(float(PlayerOwner.Pawn.Health) / float(PlayerOwner.Pawn.HealthMax));
}
DrawManaBar(float(SwordPawn(PawnOwner).CurrentMana) / float(SwordPawn(PawnOwner).MaxMana));
if (PawnOwner.Weapon!=None)
{
DrawAmmoBar(float(UTWeapon(PawnOwner.Weapon).AmmoCount) / float(UTWeapon(PawnOwner.Weapon).MaxAmmoCount));
}
else
{
DrawAmmoBar(0);
}
DrawBar("Level:"@PC.Level, PC.Level, PC.MAX_LEVEL ,20,80,200,200,200); //...and our level-bar
if ( PC.Level != PC.MAX_LEVEL ) //If our player hasn't reached the highest level...
{
DrawBar("XP:"@PC.XPGatheredForNextLevel$"/"$PC.XPRequiredForNextLevel, PC.XPGatheredForNextLevel, PC.XPRequiredForNextLevel, 20, 100, 80, 255, 80); //...draw our XP-bar
}
//DrawLevelBar(float(PC.Level) / float(PC.MAX_LEVEL)); //...and our level-bar
//if ( PC.Level != PC.MAX_LEVEL ) //If our player hasn't reached the highest level...
//{
// DrawXPBar(float(PC.XP) / float(PC.XPRequiredForNextLevel)); //...draw our XP-bar
// `log("HUD XPGATHEREDFORNEXTLEVEL:"$PC.XP);
// `log("HUD XPREQUIREDFORNEXTLEVEL:"$PC.XPRequiredForNextLevel);
//}
// DrawArmorBar(float(UTPawnOwner.GetShieldStrength()));
// Always display other information
CurEqWeap=String(PawnOwner.Weapon);
//`log("WEAPON:"$CurEqWeap);
If (CurEqWeap=="Poisonball_0")
{
DrawString("Weapon: POISONBALL",20,120,140,80,0,200);
}
If (CurEqWeap=="Fireball_0")
{
DrawString("Weapon: FIREBALL",20,120,140,80,0,200);
}
If (CurEqWeap=="Frostball_0")
{
DrawString("Weapon: FROSTBALL",20,120,140,80,0,200);
}
If (CurEqWeap=="Lightning_0")
{
DrawString("Weapon: LIGHTNING",20,120,140,80,0,200);
}
If (CurEqWeap=="BroadSwordNew_0")
{
DrawString("Weapon: SWORD",20,120,140,80,0,200);
}
If (CurEqWeap=="UTWeap_Bow_0")
{
DrawString("Weapon: BOW",20,120,140,80,0,200);
}
If (CurEqWeap=="crossbow_0")
{
DrawString("Weapon: CROSSBOW",20,120,140,80,0,200);
}
If (CurEqWeap=="ForcePush_0")
{
DrawString("Weapon: FORCE PUSH",20,120,140,80,0,200);
}
If (CurEqWeap=="SwordNew_0")
{
DrawString("Weapon: SWORD",20,120,140,80,0,200);
}
If (CurEqWeap=="HammerNew_0")
{
DrawString("Weapon: HAMMER",20,120,140,80,0,200);
}
If (CurEqWeap=="AxeNew_0")
{
DrawString("Weapon: AXE",20,120,140,80,0,200);
}
If (CurEqWeap=="None")
{
DrawString("Weapon: NONE",20,120,140,80,0,200);
}
// DrawString("Score: "$PC.SidePoints,20,100,0,80,160,200);
// DrawString("Lives: "$PC.Lives,140,80,80,80,80,200);
}
// if ((PlayerOwner != none) && PlayerOwner.Pawn != none)
// {
// Jump = SidePawn(PlayerOwner.Pawn);
// jumptest = Jump.MaxMultiJump;
// if (jumptest == 0)
// {
// DrawString("Double Jump Not Available",140,100,255,255,255,255);
// }
// if (jumptest == 1)
// {
// DrawString("Double Jump Available",140,100,255,255,255,255);
// }
// }
}
defaultproperties
{
// bCrosshairShow=false
}
I know this is probably ugly code but it works for the most part. Anyone have any ideas why it doesn't work for my melee weapon?
Bookmarks