Repository navigation
Expand file tree
/
Copy pathmain.lua
More file actions
38 lines (34 loc) · 1.44 KB
/
Copy pathmain.lua
File metadata and controls
38 lines (34 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- Copy this folder to BSX/scripts/clock_log. Press the key in settings.ini and read BSX/bsx.log.
-- This reports the client clock and raw climate values, not a named weather or forecast.
local shortcut = config.string("ClockLog", "Hotkey", "ctrl+f7")
local minutes = config.int("ClockLog", "IntervalMinutes", 5)
if minutes < 1 or minutes > 1440 then
bsx.log("clock log: IntervalMinutes must be 1..1440; using 5")
minutes = 5
end
local function report()
local time, time_why = game.time()
if time == nil then
bsx.log("clock log: time unavailable (" .. tostring(time_why) .. ")")
else
bsx.log(string.format("clock log: day %d, time %02d:%02d:%02d.%03d",
time.day, time.hour, time.minute, time.second, time.millisecond))
end
local weather, weather_why = game.weather()
if weather == nil then
bsx.log("clock log: weather unavailable (" .. tostring(weather_why) .. ")")
else
bsx.log("clock log: raw rain base " .. tostring(weather.rain_base) ..
", raw snow base " .. tostring(weather.snow_base))
end
end
-- Hotkeys require BSX API 3 and the key service. pcall keeps the script on if unavailable.
local ok, why = pcall(bsx.hotkey, shortcut, report)
if not ok then
bsx.log("clock log: hotkey unavailable (" .. tostring(why) .. "); using timer")
local function poll()
report()
bsx.after(minutes * 60000, poll)
end
bsx.after(minutes * 60000, poll)
end