PDA

View Full Version : Convert gettime()


Mencent
27/09/2016, 04:55 PM
Hello.

I have a little ask.
This is my Code:
Spieler[playerid][pClanSperre] = gettime() + (60 * 60 * 3);
It's added 3 hours to gettime() and save it in pClanSperre.

Now I want to get the hours, minutes and seconds from now up to "pClanSperre".
Can you Show me how I have to "convert" it?

Example:
You have %d hours, %d minutes and %d seconds a ban.


Thanks!

Konstantinos
27/09/2016, 05:04 PM
new hours, minutes, seconds;

hours = Spieler[playerid][pClanSperre] / 3600;
minutes = (Spieler[playerid][pClanSperre] % 3600) / 60;
seconds = Spieler[playerid][pClanSperre] % 60;

Mencent
27/09/2016, 06:03 PM
It don't work really.
The time doesn't expire. And I think, I have to write it like this to get the hour.
hours = (Spieler[playerid][pClanSperre]-gettime()) / 3600;

But the time doesn't expire. ;)

Nero_3D
27/09/2016, 09:39 PM
Than you are saying that gettime is broken?

The given code is fine, just try it again

new
seconds = Spieler[playerid][pClanSperre] - gettime(),
minutes = (seconds % 3600) / 60,
hours = seconds / 3600;

seconds %= 60;

adri1
27/09/2016, 09:50 PM
stock TimeConvertEx(sec, &days, &hours, &minutes, &seconds)
{
days = floatround(sec / 86400);
hours = floatround((sec - (days * 86400)) / 3600);
minutes = floatround((sec - (days * 86400) - (hours * 3600)) / 60);
seconds = sec % 60;
return 1;
}



Example:

Ban 3 days:



PlayerInfo[playerid][TempBan] = (gettime() + (86400 * 3) ); //set


//Check if player is still banned

if(gettime() < PlayerInfo[playerid][TempBan])
{
new d, h, m, s;
TimeConvertEx ((PlayerInfo[playerid][TempBan] - gettime()) , d, h, m, s);

new str[64];
format(str, 64, "You will get unbanned in %d days, %d hours, %d minutes %02d seconds.", d, h, m, s);
SendClientMessage(playerid, -1, str);
Kick(playerid); // Use settimer if not message wont show
return 1;
}

PrO.GameR
28/09/2016, 01:31 AM
You indeed need to use Spieler[playerid][pClanSperre]-gettime() with Konstantinos's code (everywhere it uses the array)
Other than that it'll work fine.

Mencent
28/09/2016, 04:05 PM
Thanks for all replys.

The tip of PrO.GameR was helpful and now it works. Thanks! ;)