How To Check If A Spell Is Set In Lua?

Eorzea Time
 
 
 
言語: JP EN FR DE
日本語版のFFXIVPRO利用したい場合は、上記の"JP"を設定して、又はjp.ffxivpro.comを直接に利用してもいいです
users online
フォーラム » FFXI » Jobs » Blue Mage » How to check if a spell is set in lua?
How to check if a spell is set in lua?
 Bahamut.Kelg
Offline
サーバ: Bahamut
Game: FFXI
user: Kelg
Posts: 58
By Bahamut.Kelg 2021-04-14 06:17:07  
I'm wondering how do you check if a blue spell is currently set in gearswap.

Essentially I want to do something like this:

if Magic Fruit is set:
send_command('bind ^numpad4 input /ma "Magic Fruit" <st>')

elseif Restoral is set:
send_command('bind ^numpad4 input /ma "Restoral" <me>')

elseif White wind is set:
send_command('bind ^numpad4 input /ma "White Wind" <me>')

else
send_command('bind ^numpad4 input /ma "Cure IV" <st>')

etc..

How can you check if certain spells are available?
Offline
Posts: 141
By LightningHelix 2021-04-14 07:24:55  
AzureSets has some code that does this, so we could likely tweak and reuse:
Quote:
function get_current_spellset()
--if not a BLU main, quit
if windower.ffxi.get_player().main_job_id ~= 16 then return nil end

--get set spells
return T(windower.ffxi.get_mjob_data().spells)

-- Returns all values but 512
:filter(function(id) return id ~= 512 end)

-- Transforms spells from IDs to lowercase English names
:map(function(id) return spells[id].english:lower() end)

-- Transform the keys from numeric x or xx to string 'slot0x' or 'slotxx'
:key_map(function(slot) return 'slot%02u':format(slot) end)
end

Looks like you want to use windower.ffxi.get_mjob_data().spells:
Quote:
windower.ffxi.get_mjob_data()

Returns a table containing main job info. May be empty if no job data is provided. Currently provides:

PUP (attachments and Automaton stats)
BLU (which spells are set)
MON (species and instincts)

That'll return a full table that you'll have to loop over to check for either the hardcoded IDs or reuse the call to spells[id].english:lower() to return things like "magic fruit" and "white wind".

I didn't write the actual code here, so uh, let me know if that's not clear.
 Bahamut.Kelg
Offline
サーバ: Bahamut
Game: FFXI
user: Kelg
Posts: 58
By Bahamut.Kelg 2021-04-14 07:47:29  
I only have a very basic understanding of how to put these together.
Would it be something close to this?

windower.ffxi.get_mjob_data().spells:
if spells[id].english:lower("Magic Fruit") then
send_command('bind ^numpad6 input /ma "Magic Fruit" <st>')
end

this one gives me an error when testing it
Offline
Posts: 92
By Masunasu 2021-04-14 10:05:47  
Have this near the beginning of your file...it doesn't need to fire multiple times unless you're changing sets frequently (could just run //gs reload after you do swap spells to update).
Code
local spells = require('resources').spells
blu_spells = S{}
for i,v in ipairs(windower.ffxi.get_mjob_data().spells) do
     blu_spells = blu_spells + spells[v].english:lower()
end


Now you can check if a spell is set using (make sure to check using lower case):
Code
if blu_spells:contains('magic fruit') then
...
end


I can't check right now but think all the code syntax is right.
 Bahamut.Kelg
Offline
サーバ: Bahamut
Game: FFXI
user: Kelg
Posts: 58
By Bahamut.Kelg 2021-04-14 11:40:07  
It seems gives an error saying it can't find "res.lua"

Tried changing the code to 'resources' and it stopped the error, but doesn't apply the key bind.
necroskull Necro Bump Detected! [58 days between previous and next post]
Offline
Posts: 464
By drakefs 2021-06-11 17:09:31  
Would need to see the lua to see why you are having an error.