Advertisement
Threxx

Untitled

Sep 9th, 2022
2,902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @description game_timer(timer)
  2. /// @param timer
  3. function game_timer(timer) {
  4.     //Handles the in-game timer.
  5.  
  6.     //Local variables for calculating the time
  7.     var hour, minute, second, centisecond;
  8.  
  9.     //Local variables for displaying the time
  10.     var d_hour, d_minute, d_second, d_centisecond;
  11.  
  12.     //Timer limits
  13.     var local_limit = 599999;
  14.     var global_limit = 35999999;
  15.  
  16.     //Stage time
  17.     if (global.gameTimer == 1) {        
  18.         //Calculate current time
  19.         if (global.currentTime < local_limit - 4) {
  20.             if (++timer == 2) {
  21.                 timer = 0;
  22.                 global.currentTime += 5;
  23.             }
  24.         } else {
  25.             global.currentTime = local_limit;
  26.         }
  27.    
  28.         //Calculate each timer section
  29.         minute = floor(global.currentTime / 6000);  
  30.         second = floor((global.currentTime - (minute * 6000)) / 100);
  31.         centisecond = (global.currentTime - (minute * 6000) - (second * 100));
  32.  
  33.         //Display correct time
  34.         d_hour = "";
  35.         d_minute = minute < 10 ? "0" + string(minute) : string(minute);
  36.         d_second = second < 10 ? "0" + string(second) : string(second);
  37.         d_centisecond = centisecond < 10 ? "0" + string(centisecond) : string(centisecond);
  38.     }
  39.  
  40.     //Global time
  41.     else {        
  42.         //Calculate current time
  43.         if (global.globalTime < global_limit - 4) {
  44.             if (++timer == 2) {
  45.                 timer = 0;
  46.                 global.globalTime += 5;
  47.             }
  48.         } else {
  49.             global.globalTime = global_limit;
  50.         }
  51.    
  52.         //Calculate each timer section  
  53.         hour = floor(global.globalTime / 360000);
  54.         minute = floor((global.globalTime - (hour * 360000)) / 6000);
  55.         second = floor((global.globalTime - (hour * 360000) - (minute * 6000)) / 100);
  56.         centisecond = (global.globalTime - (hour * 360000) - (minute * 6000) - (second * 100));
  57.    
  58.         //Display correct time
  59.         d_hour = hour < 10 ? "0" + string(hour) : string(hour);
  60.         d_minute = minute < 10 ? "0" + string(minute) : string(minute);
  61.         d_second = second < 10 ? "0" + string(second) : string(second);
  62.         d_centisecond = centisecond < 10 ? "0" + string(centisecond) : string(centisecond);
  63.     }
  64.  
  65.     //Return timer and strings to display
  66.     return [timer, d_hour, d_minute, d_second, d_centisecond];
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement