Advertisement
Madi_Perth

Untitled

Apr 30th, 2023 (edited)
1,519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Linden Scripting 2.34 KB | Source Code | 0 0
  1. integer time;
  2.  
  3.  /*
  4.   *  Submitted Opensource under GPL 3.0
  5.   *  2010 Fire Centaur
  6.   *  Description:
  7.   *  
  8.   *  Input number of seconds, function will return a string with Days, Hours, Minutes, Seconds
  9.   *  Corrections by Traven Sachs to Display Correct Output allowing for 0 seconds or more than 1 day
  10.   *     and improve readability with whitespace 19-Feb-2011
  11.   */
  12.  
  13. string getTime(integer secs)
  14. {
  15.     string timeStr;
  16.     integer days;
  17.     integer hours;
  18.     integer minutes;
  19.  
  20.     if (secs>=86400)
  21.     {
  22.         days=llFloor(secs/86400);
  23.         secs=secs%86400;
  24.         timeStr+=(string)days+" day";
  25.         if (days>1)
  26.         {
  27.             timeStr+="s";
  28.         }
  29.         if(secs>0)
  30.         {
  31.             timeStr+="\n";
  32.         }
  33.     }
  34.     if(secs>=3600)
  35.     {
  36.         hours=llFloor(secs/3600);
  37.         secs=secs%3600;
  38.         timeStr+=(string)hours+" hour";
  39.         if(hours!=1)
  40.         {
  41.             timeStr+="s";
  42.         }
  43.         if(secs>0)
  44.         {
  45.             timeStr+="\n";
  46.         }
  47.     }
  48.     if(secs>=60)
  49.     {
  50.         minutes=llFloor(secs/60);
  51.         secs=secs%60;
  52.         timeStr+=(string)minutes+" minute";
  53.         if(minutes!=1)
  54.         {
  55.             timeStr+="s";
  56.         }
  57.         if(secs>0)
  58.         {
  59.             timeStr+="\n";
  60.         }
  61.     }
  62.     if (secs>0)
  63.     {
  64.         timeStr+=(string)secs+" second";
  65.         if(secs!=1)
  66.         {
  67.             timeStr+="s";
  68.         }
  69.     }
  70.     return timeStr;
  71. }
  72. default
  73. {
  74.     state_entry()
  75.     {
  76.         llListen(888, "", "", "START");
  77.     }
  78.     touch_end(integer total_number)
  79.     {
  80.         state start;
  81.     }
  82.    
  83.     listen( integer channel, string name, key id, string message )
  84.     {
  85.         if(message == "START")
  86.             state start;
  87.     }
  88.    
  89. }
  90.  
  91. state start
  92. {
  93.     state_entry()
  94.     {
  95.         time = 0;
  96.         llListen(888, "", "", "STOP");
  97.         llSetTimerEvent(1);
  98.     }
  99.     touch_end(integer num)
  100.     {
  101.         state default;
  102.     }
  103.    
  104.     state_exit()
  105.     {
  106.         llSetText(getTime(time),    <0.180, 0.800, 0.251>, 1.0);
  107.     }
  108.    
  109.     listen( integer channel, string name, key id, string message )
  110.     {
  111.         if(message == "STOP")
  112.             state default;
  113.     }
  114.    
  115.     timer()
  116.     {
  117.         llSetText(getTime(time++),     <1.000, 0.255, 0.212>, 1.0);
  118.     }
  119.    
  120.    
  121.    
  122. }
  123.  
  124.  
  125.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement