PDA

View Full Version : How to get current player health status?


Drain
6th Dec 2003, 02:38 PM
How to get current player health status to draw it on HUD?

Canvas.DrawText("Health"$Pawn(Owner).Health); - It's not working, just logged "ScriptWarning: RTHud Level01.RTHud0 (Function Runtime.RTHud.DrawHealth:0092) Accessed None".

Wormbo
6th Dec 2003, 04:50 PM
A HUD's Owner will never be a Pawn.
Use something like this instead:
if ( PawnOwner != None )
Canvas.DrawText("Health"$PawnOwner.Health);
A HUD's PawnOwner property contains the pawn currently acting as the local PlayerController's ViewTarget, so if there's no Pawn it'll start logging Accessed Nones.

Drain
6th Dec 2003, 11:55 PM
Thanks, but it also does not work.
Help to me please i even can't present what to do, here is a content of uc file:


class RTHud extends HUD;

#exec TEXTURE IMPORT NAME=Crosshair FILE=Textures\crosshair.bmp GROUP="Icons" MIPS=OFF MASKED=1
#exec TEXTURE IMPORT NAME=Icon_health FILE=Textures\HUD\icon_health.bmp GROUP="Icons" MIPS=OFF MASKED=1


function DrawCrossHair( canvas Canvas, int Startx, int Starty )
{
Canvas.SetPos(StartX, StartY );
Canvas.Style = 2;
Canvas.DrawIcon(Texture'Crosshair', 0.6);
}

function DrawHealth( canvas Canvas, int Startx, int Starty )
{
Canvas.SetPos(StartX, StartY );
Canvas.DrawIcon(Texture'Icon_Health', 0.7);
Canvas.CurX -= 0;
Canvas.CurY -= 5;
//if ( Pawn(Owner) !=None )
//{
//Canvas.Font = Font'Engine.SmallFont';
Canvas.DrawText("Health "$Pawn(Owner).Health);
//}
}

function PostRender( canvas Canvas )
{

DrawCrossHair(Canvas, 0.5 * Canvas.ClipX - 8, 0.5 * Canvas.ClipY - 8);
DrawHealth( Canvas, Canvas.ClipX-770, Canvas.ClipY-60 );
}
defaultproperties
{
}

Drain
6th Dec 2003, 11:56 PM
Oops! There should be:

if ( PawnOwner !=None )
{
Canvas.Font = Font'Engine.SmallFont';
Canvas.DrawText("Health "$PawnOwner.Health);
}

Wormbo
7th Dec 2003, 05:24 AM
Try the "edit" link and [code] tags next time. ;)

How does it "not work"? What exactly does it do instead?

Drain
7th Dec 2003, 06:56 AM
It response "Error, bad or missing expression in 'if'" when comiling.

Drain
9th Dec 2003, 09:54 AM
The correct code should be such:

if ( Playerowner !=None )
{
Canvas.Font = Font'Engine.SmallFont';
Canvas.DrawText(PlayerOwner.Pawn.health,false);
}

Has found itself by thousand selection :mad: