From c6d1fd880b360835dc17f07a343e422daeb38c27 Mon Sep 17 00:00:00 2001 From: Matt Franklin Date: Mon, 10 Feb 2025 00:14:29 -0600 Subject: [PATCH 1/4] Fixed targeting p1 without <> and linting errors --- SmartSkillup.lua | 34 +++++++++++++++++++--------------- helpers.lua | 37 +++++++++++++++++++++++-------------- libs/sms_images.lua | 4 ++-- libs/sms_texts.lua | 6 +++--- 4 files changed, 47 insertions(+), 34 deletions(-) diff --git a/SmartSkillup.lua b/SmartSkillup.lua index e651cc1..ee4d08f 100644 --- a/SmartSkillup.lua +++ b/SmartSkillup.lua @@ -92,14 +92,14 @@ modules_default = T{ mp_limit = T{label = 'MP Limit', available = true , hidden = false}, -- first three are always available t_target = T{label = 'T.Target', available = true , hidden = false}, food = T{label = 'Food' , available = true , hidden = false}, - moogle = T{label = 'Moogle' , available = false, hidden = false, res = {res.spells:find(function(r) return r.en == 'Moogle' end)}[2]}, -- use dynamic lookups to protect against ID shifts - refresh = T{label = 'Refresh' , available = false, hidden = false, --[[res varies]]}, - haste = T{label = 'Haste' , available = false, hidden = false, --[[res varies]]}, - georef = T{label = 'Geo-Ref.', available = false, hidden = false, res = {res.spells:find(function(r) return r.en == 'Geo-Refresh' end)}[2]}, - sublim = T{label = 'Sublim.' , available = false, hidden = false, res = {res.job_abilities:find(function(r) return r.en == 'Sublimation' end)}[2]}, - convert = T{label = 'Convert' , available = false, hidden = false, res = {res.job_abilities:find(function(r) return r.en == 'Convert' end)}[2]}, - compo = T{label = 'Compos.' , available = false, hidden = true , res = {res.job_abilities:find(function(r) return r.en == 'Composure' end)}[2]}, - radial = T{label = 'Radial.A', available = false, hidden = true , res = {res.job_abilities:find(function(r) return r.en == 'Radial Arcana' end)}[2]}, + moogle = T{label = 'Moogle' , available = false, hidden = false, res = ({res.spells:find(function(r) return r.en == 'Moogle' end)})[2]}, -- use dynamic lookups to protect against ID shifts + refresh = T{label = 'Refresh' , available = false, hidden = false}, --[[res varies]] + haste = T{label = 'Haste' , available = false, hidden = false}, --[[res varies]] + georef = T{label = 'Geo-Ref.', available = false, hidden = false, res = ({res.spells:find(function(r) return r.en == 'Geo-Refresh' end)})[2]}, + sublim = T{label = 'Sublim.' , available = false, hidden = false, res = ({res.job_abilities:find(function(r) return r.en == 'Sublimation' end)})[2]}, + convert = T{label = 'Convert' , available = false, hidden = false, res = ({res.job_abilities:find(function(r) return r.en == 'Convert' end)})[2]}, + compo = T{label = 'Compos.' , available = false, hidden = true , res = ({res.job_abilities:find(function(r) return r.en == 'Composure' end)})[2]}, + radial = T{label = 'Radial.A', available = false, hidden = true , res = ({res.job_abilities:find(function(r) return r.en == 'Radial Arcana' end)})[2]} } @@ -117,19 +117,23 @@ function end_timeout(source) logger(chat_colors.purple, '[TIMEOUT END] Timeout ended' .. (source and ' by ' .. source or '') .. '.', false, true) end -function schedule_decision(delay, source, ...) - threads.make_decision = make_decision:schedule(delay, source) - if {...}[2] then logger(...) end +local function schedule_decision(delay, source, ...) + local args = {...} + threads.make_decision = coroutine.schedule(function() make_decision(source) end, delay) + if args[2] then + logger(unpack(args)) + end end function end_decision() coroutine.close(threads.make_decision) end -function end_timeout_and_decision(source, ...) +local function end_timeout_and_decision(source, ...) + local args = {...} end_timeout(source or 'end_timeout_and_decision') end_decision() - if {...}[2] then logger(...) end + if args[2] then logger(unpack(args)) end end @@ -397,10 +401,10 @@ function make_decision(source) --must be global to both A) be called from above -- SELF/PARTY SPELLS (Prefer trusts for ilvl target skillup chance multiplier) if spell.targets.Self and spell.targets.Party then for i = 1, 5, 1 do - local entity = windower.ffxi.get_mob_by_target('p' .. i) + local entity = windower.ffxi.get_mob_by_target('') -- party members local castable = not untargetable_trusts:contains((entity or {}).name) if (entity or {}).spawn_type == 14 and castable and entity.distance:sqrt() <= 20 then - return 'p' .. i + return '' end end return '' -- fallback target diff --git a/helpers.lua b/helpers.lua index 58fd6f6..6a5ea77 100644 --- a/helpers.lua +++ b/helpers.lua @@ -300,7 +300,7 @@ end -- Requests skill data from the server, with a timeout, with a cutscene failsafe -- NOTE: During events the server queues your packet replies, so a spam of requests would get a spam of replies ------------------------------------------------------------------------------------------------------------------- -function skill_data_request_timeout(attempts) +local function SkillDataRequestTimeout(attempts) attempts = attempts or 0 local freq = 10 --seconds local attempts_max = (60/freq)*1 --1 minute @@ -316,9 +316,9 @@ function skill_data_request_timeout(attempts) end attempts = attempts + 1 - windower.packets.inject_outgoing(0x061, 0:char():rep(8)) -- requests skill packet, packet processor runs initialize_ui() if skill_data_retrieved is false + windower.packets.inject_outgoing(0x061, string.char(0):rep(8)) -- requests skill packet coroutine.close(threads.skill_data_request_timeout) - threads.skill_data_request_timeout = skill_data_request_timeout:schedule(freq, attempts) + threads.skill_data_request_timeout = coroutine.schedule(function() SkillDataRequestTimeout(attempts) end, freq) logger(chat_colors.purple, '[SKILL REQUEST] Requesting skill data from server; attempt ' .. attempts .. '/' .. attempts_max, true) -- NOTIFY: OUT OF ATTEMPTS @@ -328,6 +328,8 @@ function skill_data_request_timeout(attempts) end end +_G.skill_data_request_timeout = SkillDataRequestTimeout -- Make it globally accessible if needed + ------------------------------------------------------------------------------------------------------------------- @@ -598,25 +600,32 @@ function determine_modules() modules.moogle.available = true -- res already populated end -- DYNAMIC SPELL MODULES (Refresh/Haste) - for id, spell in pairs(res.spells) do - local skill_en = res.skills[spell.skill].en + for _, spell in pairs(res.spells) do + local skill_en = res.skills[spell.skill].en; if is_valid(spell, skill_en, true) then -- REFRESH MODULE, weighted by priority if spell.en == 'Refresh III' then - modules.refresh:update({available = true, res = {res.spells:find(function(r) return r.en == 'Refresh III' end)}[2]}) + local update_data = {available = true, res = select(2, res.spells:find(function(r) return r.en == 'Refresh III' end))}; + modules.refresh:update(update_data); elseif spell.en == 'Refresh II' and modules.refresh.en ~= 'Refresh III' then - modules.refresh:update({available = true, res = {res.spells:find(function(r) return r.en == 'Refresh II' end)}[2]}) + local update_data = {available = true, res = select(2, res.spells:find(function(r) return r.en == 'Refresh II' end))}; + modules.refresh:update(update_data); elseif spell.en == 'Refresh' and not modules.refresh.available then - modules.refresh:update({available = true, res = {res.spells:find(function(r) return r.en == 'Refresh' end)}[2]}) + local update_data = {available = true, res = select(2, res.spells:find(function(r) return r.en == 'Refresh' end))}; + modules.refresh:update(update_data); elseif spell.en == 'Battery Charge' then - modules.refresh:update({available = true, res = {res.spells:find(function(r) return r.en == 'Battery Charge' end)}[2]}) + local update_data = {available = true, res = select(2, res.spells:find(function(r) return r.en == 'Battery Charge' end))}; + modules.refresh:update(update_data); -- HASTE MODULE, weighted by priority - elseif spell.en == 'Erratic Fluttter' then - modules.haste:update ({available = true, res = {res.spells:find(function(r) return r.en == 'Erratic Flutter' end)}[2]}) + elseif spell.en == 'Erratic Flutter' then + local update_data = {available = true, res = select(2, res.spells:find(function(r) return r.en == 'Erratic Flutter' end))}; + modules.haste:update(update_data); elseif spell.en == 'Haste II' then - modules.haste:update({available = true, res = {res.spells:find(function(r) return r.en == 'Haste II' end)}[2]}) + local update_data = {available = true, res = select(2, res.spells:find(function(r) return r.en == 'Haste II' end))}; + modules.haste:update(update_data); elseif spell.en == 'Haste' and not modules.haste.available then - modules.haste:update({available = true, res = {res.spells:find(function(r) return r.en == 'Haste' end)}[2]}) + local update_data = {available = true, res = select(2, res.spells:find(function(r) return r.en == 'Haste' end))}; + modules.haste:update(update_data); end end end @@ -688,7 +697,7 @@ function update_best_cures() known_spells = windower.ffxi.get_spells() me.best_cures = T{} for i = 6, 1, -1 do - local cure = {res.spells:find(function(r) return r.en == 'Cure' .. numerals[i] end)}[2] + local cure = select(2, res.spells:find(function(r) return r.en == 'Cure' .. numerals[i] end)) if is_valid(cure, res.skills[cure.skill].en, true) then -- BEST CURE if me.best_cures[1] == nil then diff --git a/libs/sms_images.lua b/libs/sms_images.lua index 4260590..c6d7079 100644 --- a/libs/sms_images.lua +++ b/libs/sms_images.lua @@ -178,7 +178,7 @@ function images.new(str, settings, root_settings) t = {} local m = {} meta[t] = m - m.name = (_addon and _addon.name or 'image') .. '_gensym_' .. tostring(t):sub(8) .. '_%.8x':format(16^8 * math.random()):sub(3) + m.name = (_addon and _addon.name or 'image') .. '_gensym_' .. tostring(t):sub(8) .. ('_%.8x'):format(16^8 * math.random()):sub(3) m.settings = settings or {} m.status = m.status or {visible = false, image = {}} m.root_settings = root_settings @@ -546,7 +546,7 @@ end) -- Can define functions to execute every time the settings are reloaded function images.register_event(t, key, fn) if not events[key] then - error('Event %s not available for text objects.':format(key)) + error(('Event %s not available for text objects.'):format(key)) return end diff --git a/libs/sms_texts.lua b/libs/sms_texts.lua index a1f5a2d..baad613 100644 --- a/libs/sms_texts.lua +++ b/libs/sms_texts.lua @@ -228,7 +228,7 @@ function texts.new(str, settings, root_settings) local t = {} local m = {} meta[t] = m - m.name = (_addon and _addon.name or 'text') .. '_gensym_' .. tostring(t):sub(8) .. '_%.8X':format(16^8 * math.random()):sub(3) + m.name = (_addon and _addon.name or 'text') .. '_gensym_' .. tostring(t):sub(8) .. ('_%.8X'):format(16^8 * math.random()):sub(3) t._name = m.name m.settings = settings or {} m.status = m.status or {visible = false, text = {}} @@ -317,7 +317,7 @@ function texts.append(t, str) local index = #m.textorder + 1 while i <= #str do local startpos, endpos = str:find('%${.-}', i) - local rndname = '%s_%u':format(m.name, index) + local rndname = ('%s_%u'):format(m.name, index) if startpos then -- Match before the tag local match = str:sub(i, startpos - 1) @@ -775,7 +775,7 @@ end) -- Can define functions to execute every time the settings are reloaded function texts.register_event(t, key, fn) if not events[key] then - error('Event %s not available for text objects.':format(key)) + error(('Event %s not available for text objects.'):format(key)) return end From e3a0064a1b5abe596ecf1ae7b411d93ccfb91e64 Mon Sep 17 00:00:00 2001 From: Matt Franklin Date: Mon, 10 Feb 2025 00:22:19 -0600 Subject: [PATCH 2/4] Update spell iteration to use ID for clarity in determine_modules function --- helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers.lua b/helpers.lua index 6a5ea77..2f7b192 100644 --- a/helpers.lua +++ b/helpers.lua @@ -600,7 +600,7 @@ function determine_modules() modules.moogle.available = true -- res already populated end -- DYNAMIC SPELL MODULES (Refresh/Haste) - for _, spell in pairs(res.spells) do + for id, spell in pairs(res.spells) do local skill_en = res.skills[spell.skill].en; if is_valid(spell, skill_en, true) then -- REFRESH MODULE, weighted by priority From c9800841f67672e37c84c2f17cb32bbc813ecef5 Mon Sep 17 00:00:00 2001 From: Matt Franklin <45428920+matt-frankl1n@users.noreply.github.com> Date: Tue, 11 Feb 2025 16:08:03 -0600 Subject: [PATCH 3/4] fixed errors in trust summoning and code error --- SmartSkillup.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SmartSkillup.lua b/SmartSkillup.lua index ee4d08f..cb7668a 100644 --- a/SmartSkillup.lua +++ b/SmartSkillup.lua @@ -117,8 +117,8 @@ function end_timeout(source) logger(chat_colors.purple, '[TIMEOUT END] Timeout ended' .. (source and ' by ' .. source or '') .. '.', false, true) end -local function schedule_decision(delay, source, ...) - local args = {...} +function schedule_decision(delay, source, ...) + args = {...} threads.make_decision = coroutine.schedule(function() make_decision(source) end, delay) if args[2] then logger(unpack(args)) @@ -129,8 +129,8 @@ function end_decision() coroutine.close(threads.make_decision) end -local function end_timeout_and_decision(source, ...) - local args = {...} +function end_timeout_and_decision(source, ...) + args = {...} end_timeout(source or 'end_timeout_and_decision') end_decision() if args[2] then logger(unpack(args)) end @@ -209,7 +209,7 @@ function use_module() if me.main_job_level < 99 then logger(chat_colors.yellow, '[NOTICE] You are not ilvl, so your mileage with this module may vary.') end - windower.send_command('input ' .. spell.prefix .. ' "' .. spell.en .. '"') + windower.send_command('input ' .. spell.prefix .. ' "' .. spell.en .. '"' .. '') return true end end From d63e25cd917c981c3086b2956b06d9eccd7379e7 Mon Sep 17 00:00:00 2001 From: Matt Franklin <45428920+matt-frankl1n@users.noreply.github.com> Date: Tue, 11 Feb 2025 16:13:20 -0600 Subject: [PATCH 4/4] Update helpers.lua --- helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers.lua b/helpers.lua index 2f7b192..7022482 100644 --- a/helpers.lua +++ b/helpers.lua @@ -300,7 +300,7 @@ end -- Requests skill data from the server, with a timeout, with a cutscene failsafe -- NOTE: During events the server queues your packet replies, so a spam of requests would get a spam of replies ------------------------------------------------------------------------------------------------------------------- -local function SkillDataRequestTimeout(attempts) +function SkillDataRequestTimeout(attempts) attempts = attempts or 0 local freq = 10 --seconds local attempts_max = (60/freq)*1 --1 minute