FFXIAH.com

Language: JP EN DE FR
New Items
2023-11-19
users online
Gearswap_Academia_2
Class #2

Master thread

After the first class you should be having something that looks like this:
Lesson 4 - Making a swap

Now that we have our sets defined. It's time to set rules to tell gearswap when and how to swap them. If you remember in Lesson 1, we learnt that when you take an action in the game (spell, JA, pet, etc.) the lua runs these 3 functions:

precast
midcast
aftercast


So in our lua we have all these function already there, but they are empty at the moment and aren't doing anything. So for now, we'll skip them and look at the idle function. The reason behind this is we need to prepare the lua to return to our idle set after we tell it to change our sets on an action.

To do that we'll add equip(sets.idle.normal) inside the idle function. Like this:
Code
function idle()
	equip(sets.idle.normal) 
end


"equip" is a function gearswap already know, so we don't need to define it. It also takes a set as a parameter inside the ( ). So in the above case, we tell gearswap to equip the set that we put inside the parenthesis, which is our idle set we defined way above in the last class.

From now on, whenever we'll write "idle()" somewhere in the code, when the lua gets to that point it will run the idle function, which will now equip our idle set.

Lesson 5 - Calling functions

Now, we know that whenever we take an action it runs the 3 functions we listed previously. So after the spell or action is done, the last function to run is aftercast. So after we cast, we want to return to idle gear. So let's just add the idle function we just made inside the aftercast function. This way everytime we finish an action, we'll return to our idle set:
Code
function aftercast(spell)
	idle()
end


Calling a function is as simple as writing the function name followed by parenthesis, inside the parenthesis should go the kind of data that particular function expect or left empty if the data doesn't need to be defined. For example, idle() doesn't need anything in the parenthesis, but equip(your set here) needs a set inside the parenthesis. Be mindful of that!

Recap:
This defines a function and what it does:
Code
function idle()
	equip(sets.idle.normal) 
end


This calls a function to execute:
Code
idle()



Now you might ask, why didn't we just put "equip(sets.idle.normal)" inside the aftercast? Why make it inside another function (idle) and call that extra step in the aftercast... Well, that's because we eventually we'll have to decide if we return to an idle set, or a TP set, or a DT set, etc.. in more circumstances that just after casting, for example, when you engage a monster you wanna swap to your TP set but you have not cast any spells. So aftercast hasn't run yet. We then need another way to check what kind of idle set you should be having on. Also, it's easier to make those rules all in 1 place (the idle function) so whenever we need to update the idle set we can do so by calling idle(). More on that later!

Ok! Now that our idle() is done, and it's also being called in the aftercast. Give your lua a quick reload to make sure you haven't made any mistakes. Type "//gs r" in the game chat. This will reload the currently loaded lua. Alternatively, you can also retype "//gs load Test_JOB.lua". Obviously, without the quotations.

Then, we'll do something about the precast. The precast function runs after you hit the macro or confirm the target of a spell after selecting it from the game menu. Normally you'd start casting right there. But just before you start casting, the precast function runs. That's great for us cause we want to swap out of our idle set, and go to our fast cast set just before casting. I'll spare you the reasons we do that, this ain't that kind of class :P

So if you learned anything from the above you should be able to put the equip( your set here ) function call inside the precast with the proper set inside the parenthesis, as well as the equip( your correct super awesome cure set here ) function call inside the midcast as well. So go ahead and do that, once you do check the spoiler to make sure you got it correct:

Ok congrats, now reload your lua. (//gs r). Now type in the game chat: //gs showswaps This will tell gearswap to spam your chat log listing all the swaps it's doing. You can turn it off once you know it's working correctly by typing that same command again in the chat.

Assuming you did it right, get out of your mog, and go cast cure on yourself. You should see the precast set changing to your fastcast gear, then swapping to the midcast cure set, and after cast swap back to your idle set. If that worked correctly, congratulations, you've made your first functional gearswap file from scratch. It's a pretty terrible one for now though because it will just swap to a cure set whenever you cast *anything*. But it's a start and it works. Keep that in mind!

See ya next time in Class #3 where we'll learn how to differentiate between schools of magic and magic skills etc.. And also to create more solid logic so you don't cast -nas in a cure set or something.

Toodles.

Author: Elizabet
Date Created: 2020-01-21 13:24:57
Date Last Modified: 2020-01-21 16:01:01
Updates: 3
Bytes: 5538