Client: add new Util_ functons Util_GetTime, Util_GetTimeLeft and Util_GetAddress for the current server.

This commit is contained in:
Marco Cawthorne 2023-06-15 11:40:46 -07:00
parent 3b99cf7419
commit 373e844305
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
2 changed files with 48 additions and 1 deletions

View File

@ -38,4 +38,8 @@ bool Client_InIntermission(void);
string Util_GetKeyString(string strBind);
/** Returns if the currently active client-seat is in a vehicle. */
bool Client_InVehicle(void);
bool Client_InVehicle(void);
string Util_GetTime(void);
float Util_GetTimeLeft(void);
string Util_GetAddress(void);

View File

@ -90,3 +90,46 @@ Util_GetMaxPlayers(void)
{
return g_numplayerslots;
}
string
Util_GetTime( void )
{
static int iS, iM, iT, iMS;
float timeLimit = stof( serverkey( "timelimit" ) ) * 60;
/* display a count-down timer if we've got a time limit */
if (timeLimit <= 0)
iMS = (int)time;
else
iMS = timeLimit - time;
if ( iMS < 0 ) {
iMS = 0;
}
iS = iMS;
iM = iS / 60;
iS -= iM * 60;
iT = iS / 10;
iS -= iT * 10;
return sprintf( "%i:%i%i", iM, iT, iS );
}
float
Util_GetTimeLeft(void)
{
float timeLimit = stof( serverkey( "timelimit" ) ) * 60;
return timeLimit - time;
}
string
Util_GetAddress(void)
{
string host = serverkey("ip");
if (host == "QLoopBack:0")
return "localhost";
else
return host;
}