Convert gettime()
#1

Hello.

I have a little ask.
This is my Code:
PHP код:
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:
PHP код:
You have %d hours, %d minutes and %d seconds a ban
Thanks!
Reply
#2

pawn Код:
new hours, minutes, seconds;

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

It don't work really.
The time doesn't expire. And I think, I have to write it like this to get the hour.
PHP код:
hours = (Spieler[playerid][pClanSperre]-gettime()) / 3600
But the time doesn't expire.
Reply
#4

Than you are saying that gettime is broken?

The given code is fine, just try it again
PHP код:
new
    
seconds Spieler[playerid][pClanSperre] - gettime(),
    
minutes = (seconds 3600) / 60,
    
hours seconds 3600;
seconds %= 60
Reply
#5

PHP код:

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:

PHP код:

PlayerInfo
[playerid][TempBan] = (gettime() + (86400 3) ); //set
//Check if player is still banned
if(gettime() < PlayerInfo[playerid][TempBan]) 

    new 
dhms
    
TimeConvertEx ((PlayerInfo[playerid][TempBan] - gettime()) , dhms); 
    new 
str[64]; 
    
format(str64"You will get unbanned in %d days, %d hours, %d minutes %02d seconds."dhms); 
    
SendClientMessage(playerid, -1str); 
    
Kick(playerid); // Use settimer if not message wont show
    
return 1;

Reply
#6

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.
Reply
#7

Thanks for all replys.

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


Forum Jump:


Users browsing this thread: 1 Guest(s)