This is going to be a really long post. You mention wanting to understand your code, so I went ahead and tried to explain everything so that you can use what is here to apply to other things in the future.
There are a great number of ways you can handle toggles. Feary's solution will work, but there are two key problems: it's not flexible (you cannot easily add another set without having to write new rules), and it's not modular (you cannot combine the feature with other features without a lot of redundancies).
There is also something to consider practically: there is content in which you are magic bursting, but still need to consider magic accuracy. You can solve by adding four options, but it would be more logical and easy to rather have two toggles, one for regular/MB, and one for magic accuracy levels.
The most typical method you'll find for such toggles is based on Byrth's original GearSwap examples. First, make the tables that hold your variables. You can declare these in your get_sets() function:
Code
m_typeIndex = 1
m_typeArray = {'normal','MB'}
m_accIndex = 1
m_accArray = {'normal','midAcc','highAcc'}
The index keeps track of where you are in the array. We will use these to "index" our table. For example, m_typeArray[1] would return "normal" while m_typeArray[2] would return "MB". As it is now, m_typeArray[m_typeIndex] would return "normal".
Next, we want to control them. Basically, we need a way to change the number. Our self_command function would look like:
Code
function self_command(command)
if command == 'mtype' then
m_typeIndex=(m_typeIndex % #m_typeArray) + 1
add_to_chat(200,'M Set changed to '..m_typeArray[m_typeIndex])
elseif command == 'macc' then
m_accIndex=(m_accIndex% #m_accArray) + 1
add_to_chat(200,'M Acc changed to '..m_accArray[m_accIndex])
end
end
"//gs c macc" would change accuracy, and "//gs c mtype" would change your type. This isn't the most elegant way to do it, but it's simple and works.
Next is to use these. The nice thing is that all of our sets actually make up a really huge table--think of it like a tree with a lot of branches that branch off into their own branches. For example, when we say "sets.midcast.Impact" we are looking at the "Impact" branch of the "midcast" branch of the "sets" tree.
So our "rules" can be written as a set of instructions on how to navigate the tree to the correct branch. Since we're dealing with midcast, we know that's our first branch, so let's start there:
Then we look to see if the next branch exists; and if it does, we will move onto that branch. We actually want to start with the most specific, so that we can catch those first (otherwise "Impact" will get caught by "Elemental Magic"), so we'll start with the spell name:
Code
equipSet = sets.midcast
if equipSet[spell.english] then
equipSet = equipSet[spell.english]
end
So if your spell's name is "Impact" and you have a set called "sets.midcast.Impact," it will find that. We can add any number of branches, like spell.skill, which you are using now:
Code
equipSet = sets.midcast
if equipSet[spell.english] then
equipSet = equipSet[spell.english]
elseif equipSet[spell.skill] then
equipSet = equipSet[spell.skill]
end
Note that we can use an "elseif" here because there is never any reason to use both spell.english and spell.skill, since every spell only has one skill.
So if you cast Haste, but there is no sets.midcast.Haste, it will look for sets.midcast["Enhancing Magic"]. If it finds it, it will move to that branch.
Next, we want to use the variables we declared, so we'll add those branches now. We want to use their own "ifs" because we want them to work independently of one another.
Code
equipSet = sets.midcast
if equipSet[spell.english] then
equipSet = equipSet[spell.english]
elseif equipSet[spell.skill] then
equipSet = equipSet[spell.skill]
end
if m_typeArray and equipSet[m_typeArray[m_typeIndex]] then
equipSet = equipSet[m_typeArray[m_typeIndex]]
end
if m_accArray and equipSet[m_accArray[m_accIndex]] then
equipSet = equipSet[m_accArray[m_accIndex]]
end
Now you can use a multitude of sets just by creating them. For example:
sets.midcast["Elemental Magic"]
sets.midcast["Elemental Magic"].midAcc
sets.midcast["Elemental Magic"].highAcc
sets.midcast["Elemental Magic"].MB
sets.midcast["Elemental Magic"].MB.midAcc
sets.midcast["Elemental Magic"].MB.highAcc
sets.midcast.Death
sets.midcast.Death.midAcc
sets.midcast.Death.highAcc
Remember that if it doesn't find a certain branch, it won't move onto it, so you don't need a set called sets.midcast["Elemental Magic"].normal. It will just stay on the sets.midcast["Elemental Magic"] branch until further instruction.
Also note that you cannot create a branch off of a branch that doesn't exist (this will give you a run time error that says something like "Failed to index [blahblah]"). Basically, you can't make "sets.midcast.Death.MB" without a sets.midcast.Death set first. However, you're never going to use Death unless you're magic bursting anyway...so you don't need a sets.midcast.Death.MB set. Even if you set your type to MB, it will stay on the sets.midcast.Death branch.
After you're done navigating the tree, you can then add particular equip rules, like obi.
Code
function midcast(spell,action)
if spell.action_type == 'Magic' then
equipSet = sets.midcast
if equipSet[spell.english] then
equipSet = equipSet[spell.english]
elseif equipSet[spell.skill] then
equipSet = equipSet[spell.skill]
end
if m_typeArray and equipSet[m_typeArray[m_typeIndex]] then
equipSet = equipSet[m_typeArray[m_typeIndex]]
end
if m_accArray and equipSet[m_accArray[m_accIndex]] then
equipSet = equipSet[m_accArray[m_accIndex]]
end
if spell.element == world.weather_element or spell.element == world.day_element then
equipSet = set_combine(equipSet,sets.midcast.weather)
end
equip(equipSet)
end
end
In this example, you would use sets.midcast as your basic set (what gets used whenever it can't find anything).
I'm not very good at explaining things, especially at 4AM, so if you have questions, don't hesitate to ask.