LucasRed

[SNIPPET] TimeCalc

Jul 17th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. myTime <- {};
  2. iTime <- 600; // Valor em segundos...
  3.  
  4. function onPlayerJoin( player )
  5. {
  6.     myTime.rawset( player.ID, time() );
  7. }
  8.  
  9. function onPlayerSpawn( player )
  10. {
  11.     MessagePlayer( "Calculando iTime = " + TimeCalc( iTime, 0 ), player );
  12.     MessagePlayer( "Voce entrou no server ha " + TimeCalc( myTime[ player.ID ], 1 ), player );
  13. }
  14.  
  15. function TimeCalc( value, type )
  16. {
  17.     if ( value )
  18.     {
  19.         local a;
  20.         if ( type == 0 ) a = value; // Tempo total. Usado quando o valor já é especificado em segundos...
  21.         else a = time() - value; // Descontando do tempo do servidor. Tempo parcial
  22.  
  23.         local hours = a / 3600,
  24.         a = a % 3600,
  25.         mins = a / 60,
  26.         a = a % 60,
  27.         secs = a / 1;
  28.  
  29.         if ( hours >= 1 ) return format( "%02d:%02d:%02d", hours, mins, secs );
  30.         else if ( ( mins >= 1 ) && ( hours < 1 ) ) return format( "%02d:%02d", mins, secs );
  31.         else if ( ( secs >= 1 ) && ( mins < 1 ) ) return "00:" + format( "%02d", secs );
  32.     }
  33.     else return "00:00:00";
  34. }
Advertisement
Add Comment
Please, Sign In to add comment