I can tell you the logic I use to swap certain pieces when above a certain threshold of TP in my lua, but I'm not sure it's gonna help you and, likewise, I'm not sure it's the best way to do it.
It's just the way I do it, developed this logic ages ago and it always worked for me.
First, I define a variable called TPthreshold.
Its value changes according if I'm using Doji or not.
Technically I have two variables on SAM, for 2 different TP threshold (one swaps just moonshade, the other swaps earring and head), but I think it's the only situation. On all my other jobs lua where I bother with tpthreshold, I normally have a single variable and a single set (moonshade is the only thing I swap)
Then somewhere in my "get_sets" I define a custom set.
Like for instance the two I use on SAM
Code
sets.precast.WS.maxTP1 = {ear2="Lugra Earring +1"}
sets.precast.WS.maxTP2 = set_combine(sets.precast.WS.maxTP1, {head="Nyame helm"})
Then I do something in my precast.
My precast normally has a single chained if inside.
"If action is a spell equip this set
Elseif action is a ja, equip the proper set
Else if action is blahblahblah, equip the proper set
End"
Normally my precast function ends right after that.
When I want to handle tpthreshold I do a second, separate if.
This "if" is inside the precast function, but comes after the main "if" (the one I described above). It's not chain inside it, it's a second, separate "If".
This is mine for sam
Code
if spell.english == "Tachi: Fudo" or spell.english == "Tachi: Shoha" or spell.english == "Tachi: Gekko" or <insert list of all WS where you want to check for TP> then
if player.tp > TPthreshold1 then
equip(sets.precast.WS.maxTP1)
elseif player.tp > TPthreshold2 then
equip(sets.precast.WS.maxTP2)
end
end
Basically the first If, the long chained one, equips the proper set.
If it's a WS we're talking about, it will equip the relevant WS set, which by default includes Mpaca helm and Moonshade earring.
Then, separately, it checks for my current TP value.
If it's above a certain threshold, it equips a different set which is empty except for the 1-2 relevant pieces I want to swap.
Gearswap doesn't equip sets the second they get processed into an if, the packet to equip them gets sent to the game after the precast function is over.
This means that my two ifs will be combined into a single set, and a single "equip" packet will be sent to the game after the precast function is over.
Soo... I dunno if I explained myself to you and I'm sure there are way better and more efficient ways to do it, but this is the way I've been doing it for all these years.