How to program a countdown timer in UDK ( Unrealscript Timers WIP)

Timers is an awesome feature in the engine UDK, you can have latent functions and other stuff, but one of the most relevant aspects of it it's making a countdown for the game to end sometime, in this tutorial I will teach you how to make a countdown timer in Unrealscript as well as in Actionscript.

First step.

Try it by yourself make your own drawing.

that's what I got something like getting the divider which is the left time / the seconds an hour has made no sense I know it's a mess.

So let's apply it to Unrealscript. 

Let's begin a timer somewhere for instance in PostBeginPlay Function from GameInfo class. 
like this : 

simulated function postBeginPlay()
{
super.postBeginPlay();
SetTimer(120.0f , false, NameOf(EndGame));
 //Player does not exist at the beginning gets spawned later
}
function EndGame()
{

}


in HUD place another latent timer that processes every second 

var int CachedTimeLeft;


SetTimer(120, true, nameOf(CountDown) ); for instance on postbeginplay

function CountDown()
{
    if( MyGameSoloMatchGameInfo( Worldinfo.game ) != none )
    {
        CachedTimeLeft--;
        Minutes = CachedTimeLeft/60;
        Divider = CachedTimeLeft/60+1;
        seconds = (60 - ((60 * Divider) - CachedTimeLeft)  );
        self.GFxAS2MultiPurposeHUD.MinTimerTxt.SetText(String(Minutes));
        self.GFxAS2MultiPurposeHUD.SecondsTimerTxt.SetText(String(Seconds));

        if( ! GOTAMP2SoloMatchGameInfo( Worldinfo.game       ).AGMV.MatchToBeFougth.bRespawnsAndTimeLimit )
        {
            self.GFxAS2MultiPurposeHUD.SetElementVisibleOrUnvisibleByNum(24 , false );
        }

    }
}








Comments

Popular Posts