Advertisement
Arc13

time.lua

May 7th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.51 KB | None | 0 0
  1. function getWorldTime()
  2.     return os.time()
  3. end
  4.  
  5. function getWorldTick()
  6.     worldTick = (os.time() * 1000 + 18000) % 24000
  7.     return worldTick
  8. end
  9.  
  10. function getWorldDay()
  11.     return os.day()
  12. end
  13.  
  14. function canPlayerGotoBed()
  15.     time = getWorldTick()
  16.  
  17.     if time > 12541 and time < 23458 then
  18.         return true
  19.     else
  20.         return false
  21.     end
  22. end
  23.  
  24. function canPlayerSleep()
  25.     time = getWorldTick()
  26.  
  27.     if time > 12541 and time < 23458 then
  28.         return true
  29.     else
  30.         return false
  31.     end
  32. end
  33.  
  34. function isWorldDay()
  35.     time = getWorldTick()
  36.  
  37.     if time > 0 and time < 12000 then
  38.         return true
  39.     else
  40.         return false
  41.     end
  42. end
  43.  
  44. function isWorldNight()
  45.     time = getWorldTick()
  46.  
  47.     if time > 13501 and time < 23000 then
  48.         return true
  49.     else
  50.         return false
  51.     end
  52. end
  53.  
  54. function isWorldDusk()
  55.     time = getWorldTick()
  56.  
  57.     if time > 12001 and time < 13500 then
  58.         return true
  59.     else
  60.         return false
  61.     end
  62. end
  63.  
  64. function isWorldDawn()
  65.     time = getWorldTick()
  66.  
  67.     if time > 23001 and time < 23999 then
  68.         return true
  69.     else
  70.         return false
  71.     end
  72. end
  73.  
  74. function canMobsSpawn()
  75.     time = getWorldTick()
  76.  
  77.     if time > 13187 and time < 22812 then
  78.         return true
  79.     else
  80.         return false
  81.     end
  82. end
  83.  
  84. function canMobsBurn()
  85.     time = getWorldTick()
  86.  
  87.     if time > 23459 or time < 12650 then
  88.         return true
  89.     else
  90.         return false
  91.     end
  92. end
  93.  
  94. function getWorldElapsedSeconds()
  95.     time = getWorldTick() / 1000
  96.  
  97.     elapsed = time * 50
  98.     return elapsed
  99. end
  100.  
  101. function getWorldHours()
  102.     time = getWorldTick()
  103.  
  104.     hours = time / 1000 + 6
  105.  
  106.     if hours > 23 then
  107.         hoursStr = tonumber(math.floor(hours - 24))
  108.         hoursStr = "0"..hoursStr
  109.     elseif hours < 10 then
  110.         hoursStr = tonumber(math.floor(hours))
  111.         hoursStr = "0"..hoursStr
  112.     else
  113.         hoursStr = tonumber(math.floor(hours))
  114.     end
  115.  
  116.     if hoursStr == "0-1" then
  117.         hoursStr = "23"
  118.     end
  119.  
  120.     return hoursStr
  121. end
  122.  
  123. function getWorldMinutes()
  124.     time = getWorldTick()
  125.  
  126.     minutes = (time % 1000) * 60 / 1000
  127.     minutesStr = tonumber(math.floor(minutes))
  128.  
  129.     if minutes < 10 then
  130.         minutesStr = "0"..minutesStr
  131.     end
  132.  
  133.     return minutesStr
  134. end
  135.  
  136. function getWorldMoonPhase()
  137.     local nDateMod = os.day() % 8
  138.     local tPhasesEn = {"Full Moon", "Waning Gibbous", "Last Quarter", "Waning Crescent", "New Moon", "Waxing Crescent", "First Quarter", "Waxing Gibbous"}
  139.     local tPhasesFr = {"Pleine Lune", "Lune Gibbeuse", "Dernier Quartier", "Dernier Croissant", "Nouvelle Lune", "Premier Croissant", "Premier Quartier", "Lune Gibbeuse"}
  140.  
  141.     if nDateMod == 0 then
  142.         nDateMod = 8
  143.     end
  144.  
  145.     if nDateMod and tPhasesEn[nDateMod] and tPhasesFr[nDateMod] then
  146.         return nDateMod, tPhasesEn[nDateMod], tPhasesFr[nDateMod]
  147.     end
  148. end
  149.  
  150. function getRealMinutes()
  151.     local response = http.get("http://www.timeapi.org/utc/now?format=%25M")
  152.  
  153.     if response then
  154.         text = response.readAll()
  155.         response.close()
  156.         return text
  157.     else
  158.         return false
  159.     end
  160. end
  161.  
  162. function getRealHours()
  163.     local response = http.get("http://www.timeapi.org/utc/now?format=%25H")
  164.  
  165.     if response then
  166.         text = response.readAll()
  167.         response.close()
  168.         text = tonumber(text)
  169.         text = text + 1
  170.         text = text % 24
  171.  
  172.         if text <= 9 and text >= 0 then
  173.             text = "0"..text
  174.         end
  175.  
  176.         text = tostring(text)
  177.  
  178.         return text
  179.     else
  180.         return false
  181.     end
  182. end
  183.  
  184. function getRealSeconds()
  185.     local response = http.get("http://www.timeapi.org/utc/now?format=%25S")
  186.     if response then
  187.         text = response.readAll()
  188.         response.close()
  189.         return text
  190.     else
  191.         return false
  192.     end
  193. end
  194.  
  195. function getRealWeekDay()
  196.     local response = http.get("http://www.timeapi.org/utc/now?format=%25u")
  197.     if response then
  198.         text = response.readAll()
  199.         response.close()
  200.         return text
  201.     else
  202.         return false
  203.     end
  204. end
  205.  
  206. function getRealMonthDay()
  207.     local response = http.get("http://www.timeapi.org/utc/now?format=%25d")
  208.     if response then
  209.         text = response.readAll()
  210.         response.close()
  211.         return text
  212.     else
  213.         return false
  214.     end
  215. end
  216.  
  217. function getRealYear()
  218.     local response = http.get("http://www.timeapi.org/utc/now?format=%25Y")
  219.     if response then
  220.         text = response.readAll()
  221.         response.close()
  222.         return text
  223.     else
  224.         return false
  225.     end
  226. end
  227.  
  228. function getRealYearDay()
  229.     local response = http.get("http://www.timeapi.org/utc/now?format=%25j")
  230.     if response then
  231.         text = response.readAll()
  232.         response.close()
  233.         return text
  234.     else
  235.         return false
  236.     end
  237. end
  238.  
  239. function getRealMonth()
  240.     local response = http.get("http://www.timeapi.org/utc/now?format=%25m")
  241.     if response then
  242.         text = response.readAll()
  243.         response.close()
  244.         return text
  245.     else
  246.         return false
  247.     end
  248. end
  249.  
  250. function getRealMilliseconds()
  251.     local response = http.get("http://www.timeapi.org/utc/now?format=%25L")
  252.     if response then
  253.         text = response.readAll()
  254.         response.close()
  255.         return text
  256.     else
  257.         return false
  258.     end
  259. end
  260.  
  261. function getWorldComplete(sep)
  262.     if sep then
  263.         return getWorldHours()..sep..getWorldMinutes()
  264.     else
  265.         return getWorldHours()..":"..getWorldMinutes()
  266.     end
  267. end
  268.  
  269. function getRealComplete(sep, secs, sepSec)
  270.     if not sep then
  271.         sep = ":"
  272.     end
  273.  
  274.     if not sepSec then
  275.         sepSec = "."
  276.     end
  277.  
  278.     if secs then
  279.         return getRealHours()..sep..getRealMinutes()..sepSec..getRealSeconds()
  280.     else
  281.         return getRealHours()..sep..getRealMinutes()
  282.     end
  283. end
  284.  
  285. function getWorldYear()
  286.     local year = os.day() / 360
  287.  
  288.     return math.floor(year)
  289. end
  290.  
  291. function getWorldWeekDay()
  292.     local tablewday = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
  293.     local wday = os.day() % 7
  294.  
  295.     return tablewday[wday + 1]
  296. end
  297.  
  298. function getWorldMonth()
  299.     local tablemonth = {"January", "February", "March", "April", "May", "June", "July", "August", "Spetember", "October", "November", "December"}
  300.     local month = os.day() / 30
  301.     local month = month % 12
  302.  
  303.     return tablemonth[math.floor(month + 1)], math.floor(month + 1)
  304. end
  305.  
  306. function getWorldDate()
  307.     local date = os.day() % 30
  308.  
  309.     return date + 1
  310. end
  311.  
  312. function getDaylightOutput()
  313.     local time = (os.time() * 1000 + 18000)%24000
  314.  
  315.     if time >= 4300 and time <= 7720 then
  316.         return 15
  317.     elseif time >= 3180 and time <= 8840 then
  318.         return 14
  319.     elseif time >= 2460 and time <= 9560 then
  320.         return 13
  321.     elseif time >= 1880 and time <= 10140 then
  322.         return 12
  323.     elseif time >= 1380 and time <= 10640 then
  324.         return 11
  325.     elseif time >= 940 and time <= 11080 then
  326.         return 10
  327.     elseif time >= 540 and time <= 11480 then
  328.         return 9
  329.     elseif time >= 180 and time <= 11840 then
  330.         return 8
  331.     elseif time >= 23960 or time <= 12040 then
  332.         return 7
  333.     elseif time >= 23780 or time <= 12240 then
  334.         return 6
  335.     elseif time >= 23540 or time <= 12480 then
  336.         return 5
  337.     elseif time >= 23300 or time <= 12720 then
  338.         return 4
  339.     elseif time >= 23080 or time <= 12940 then
  340.         return 3
  341.     elseif time >= 22800 or time <= 13220 then
  342.         return 2
  343.     elseif time >= 22340 or time <= 13680 then
  344.         return 1
  345.     else
  346.         return 0
  347.     end
  348. end
  349.  
  350. function getDaylightOutputRain()
  351.     local time = (os.time() * 1000 + 18000)%24000
  352.  
  353.     if time >= 4120 and time <= 7900 then
  354.         return 12
  355.     elseif time >= 2880 and time <= 9140 then
  356.         return 11
  357.     elseif time >= 2080 and time <= 9940 then
  358.         return 10
  359.     elseif time >= 1440 and time <= 10580 then
  360.         return 9
  361.     elseif time >= 900 and time <= 11120 then
  362.         return 8
  363.     elseif time >= 400 and time <= 11620 then
  364.         return 7
  365.     elseif time >= 0 and time <= 12020 then
  366.         return 6
  367.     elseif time >= 23760 or time <= 12260 then
  368.         return 5
  369.     elseif time >= 23520 or time <= 12500 then
  370.         return 4
  371.     elseif time >= 23240 or time <= 12780 then
  372.         return 3
  373.     elseif time >= 22800 or time <= 13220 then
  374.         return 2
  375.     elseif time >= 22340 or time <= 13680 then
  376.         return 1
  377.     else
  378.         return 0
  379.     end
  380. end
  381.  
  382. function getDaylightOutputThunder()
  383.     local time = (os.time() * 1000 + 18000)%24000
  384.  
  385.     if time >= 3960 and time <= 8060 then
  386.         return 10
  387.     elseif time >= 2620 and time <= 9400 then
  388.         return 9
  389.     elseif time >= 1740 and time <= 10280 then
  390.         return 8
  391.     elseif time >= 1040 and time <= 10980 then
  392.         return 7
  393.     elseif time >= 460 and time <= 11560 then
  394.         return 6
  395.     elseif time >= 60 and time <= 11940 then
  396.         return 5
  397.     elseif time >= 23700 or time <= 12300 then
  398.         return 4
  399.     elseif time >= 23360 or time <= 12660 then
  400.         return 3
  401.     elseif time >= 22960 or time <= 13060 then
  402.         return 2
  403.     elseif time >= 22340 or time <= 13680 then
  404.         return 1
  405.     else
  406.         return 0
  407.     end
  408. end
  409.  
  410. function getDaylightOutputInversed()
  411.     local time = (os.time() * 1000 + 18000)%24000
  412.  
  413.     if time >= 4300 and time <= 7720 then
  414.         return 0
  415.     elseif time >= 3180 and time <= 8840 then
  416.         return 1
  417.     elseif time >= 2460 and time <= 9560 then
  418.         return 2
  419.     elseif time >= 1880 and time <= 10140 then
  420.         return 3
  421.     elseif time >= 1380 and time <= 10640 then
  422.         return 4
  423.     elseif time >= 940 and time <= 11080 then
  424.         return 5
  425.     elseif time >= 540 and time <= 11480 then
  426.         return 6
  427.     elseif time >= 180 and time <= 11840 then
  428.         return 7
  429.     elseif time >= 23960 or time <= 12040 then
  430.         return 8
  431.     elseif time >= 23780 or time <= 12240 then
  432.         return 9
  433.     elseif time >= 23540 or time <= 12480 then
  434.         return 10
  435.     elseif time >= 23300 or time <= 12720 then
  436.         return 11
  437.     elseif time >= 23080 or time <= 12940 then
  438.         return 12
  439.     elseif time >= 22800 or time <= 13220 then
  440.         return 13
  441.     elseif time >= 22340 or time <= 13680 then
  442.         return 14
  443.     else
  444.         return 15
  445.     end
  446. end
  447.  
  448. function getDaylightOutputInversedRain()
  449.     local time = (os.time() * 1000 + 18000)%24000
  450.  
  451.     if time >= 4120 and time <= 7900 then
  452.         return 3
  453.     elseif time >= 2880 and time <= 9140 then
  454.         return 4
  455.     elseif time >= 2080 and time <= 9940 then
  456.         return 5
  457.     elseif time >= 1440 and time <= 10580 then
  458.         return 6
  459.     elseif time >= 900 and time <= 11120 then
  460.         return 7
  461.     elseif time >= 400 and time <= 11620 then
  462.         return 8
  463.     elseif time >= 0 and time <= 12020 then
  464.         return 9
  465.     elseif time >= 23760 or time <= 12260 then
  466.         return 10
  467.     elseif time >= 23520 or time <= 12500 then
  468.         return 11
  469.     elseif time >= 23240 or time <= 12780 then
  470.         return 12
  471.     elseif time >= 22800 or time <= 13220 then
  472.         return 13
  473.     elseif time >= 22340 or time <= 13680 then
  474.         return 14
  475.     else
  476.         return 15
  477.     end
  478. end
  479.  
  480. function getDaylightOutputInversedThunder()
  481.     local time = (os.time() * 1000 + 18000)%24000
  482.  
  483.     if time >= 3960 and time <= 8060 then
  484.         return 5
  485.     elseif time >= 2620 and time <= 9400 then
  486.         return 6
  487.     elseif time >= 1740 and time <= 10280 then
  488.         return 7
  489.     elseif time >= 1040 and time <= 10980 then
  490.         return 8
  491.     elseif time >= 460 and time <= 11560 then
  492.         return 9
  493.     elseif time >= 60 and time <= 11940 then
  494.         return 10
  495.     elseif time >= 23700 or time <= 12300 then
  496.         return 11
  497.     elseif time >= 23360 or time <= 12660 then
  498.         return 12
  499.     elseif time >= 22960 or time <= 13060 then
  500.         return 13
  501.     elseif time >= 22340 or time <= 13680 then
  502.         return 14
  503.     else
  504.         return 15
  505.     end
  506. end
  507.  
  508. function timestampToDate(nTimestamp)
  509.     if not nTimestamp or type(nTimestamp) ~= "number" then
  510.         return false, "timestampToDate(number timestamp)"
  511.     end
  512.  
  513.     sTs = http.get("http://www.convert-unix-time.com/api?format=german&timezone=paris&timestamp="..nTimestamp)
  514.     jTsJson = sTs.readAll()
  515.     sTs.close()
  516.  
  517.     return string.sub(jTsJson, 15, 33)
  518. end
  519.  
  520. function getRealCompleteDate(sSeparator)
  521.     local sSeparator = sSeparator or "/"
  522.  
  523.     local MonthDay = getRealMonthDay()
  524.     local Month = getRealMonth()
  525.     local Year = getRealYear()
  526.  
  527.     while not MonthDay or not Month or not Year do
  528.         local MonthDay = getRealMonthDay()
  529.         local Month = getRealMonth()
  530.         local Year = getRealYear()
  531.     end
  532.  
  533.     return MonthDay..sSeparator..Month..sSeparator..Year
  534. end
  535.  
  536. function getWorldCompleteDate(sSeparator)
  537.     local sSeparator = sSeparator or "/"
  538.  
  539.     return getWorldDate()..sSeparator..table.pack(getWorldMonth())[2]..sSeparator..getWorldYear()
  540. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement