_addon.name = 'Update' _addon.author = 'Arcon' _addon.version = '1.1.0.0' _addon.command = 'update' require('luau') defaults = {} defaults.AutoUpdate = false defaults.CheckInterval = 300 settings = config.load(defaults) debug.setmetatable(nil, {__index = {}, __call = functions.empty}) units = {[''] = 1} units.s = units[''] units.min = 60*units.s units.h = 60*units.min units.d = 24*units.h units.ms = units.s/1000 units.us = units.ms/1000 units.ns = units.us/1000 math.randomseed(os.time() + os.clock()) handle = (0x7FFFFFFF):random():hex():zfill(8) tick = function(msg) last = os.clock() if not msg then windower.send_ipc_message('update ' .. handle) end end update = tick .. windower.execute:prepare(windower.windower_path .. 'Windower.exe', {'--update'}) windower.register_event('ipc message', tick:cond(function(str) local args = str:split(' ') return args[1] == 'update' and args[2] ~= handle end)) windower.register_event('time change', update:cond(function() return settings.AutoUpdate and os.clock() - last > settings.CheckInterval and not windower.ffxi.get_player().in_combat end)) windower.register_event('addon command', function(command, param, ...) command = command and command:lower() or nil param = param and param:lower() or nil if not command then update() elseif command == 'auto' then if not param then settings.AutoUpdate = not settings.AutoUpdate elseif param == 'on' then settings.AutoUpdate = true elseif param == 'off' then settings.AutoUpdate = false else error('Invalid syntax: //update auto [on|off]') return end config.save(settings) log('Automatic updates turned ' .. (settings.AutoUpdate and 'on' or 'off') .. '.') elseif command == 'interval' then if not param then error('Invalid syntax: //update interval