FFXIAH.com

Language: JP EN DE FR
New Items
2023-11-19
users online
Gearswap_Academia_1


Master thread

So you wanna write your own Gearswap? You're curious about how those lua innards work? Cool. But first, you're going to need a few things.

1) A not Terrible text editor. Those 2 are free and quite decent. NotePad++ or Sublime or Visual Studio Code, thanks to Austar for that one!
2) A working Web browser, ideally with internet. I'm guessing you got that.
3) An FFXI account
4) Working Windower and the gearswap add-on.

So a job gearswap is based in lua. If you wanna know more about lua you can read about it but this isn't a lua course and there is plenty of resources for that. So what we'll do here is get you to write your very own gearswap from scratch. Not just how to fill up someone else's lua file with your gearsets, but actually making your own template.

So first things first. Let's bookmark some pages. We'll be going to those a bit.

* https://docs.windower.net/addons/gearswap/
* https://docs.windower.net/addons/gearswap/reference/

Lesson 1 - What gearswap does, in a nutshell

Gearswap is all based on doing things like swapping your gear based on in game actions. Those are actions, such as casting a spell or an ability are picked up by Gearswap and so when you cast a spell or JA in game it will run these 3 functions in order:

precast
midcast
aftercast


When you engage or disengage, Gearswap will run this function: status_change

When functions are run, you can instruct gearswap to evaluate something and then act on it. For example, when a midcast function is run, you can ask gearswap to evaluate what school of magic is being cast and if it's a cure spell, to swap in +cure potency gear.

So now that we know this. We'll create a fully new gearswap!

Lesson 2 - Creating you very first gearswap

https://pastebin.com/LBJ4dqTk

The above paste bin will be the basis of this exercise.

Now open up notepad++ or whatever editor you picked. Create a new file, and paste the above pastebin into that new file. You can save it as "Test_JOB.lua" inside the Data folder that is inside the Gearswap folder (which should be in your addon folder in the windower folder).

In game, once you are logged in, you can type in the chat //gs load Test_JOB.lua and gearswap will load your lua file.

Note: when you swap jobs, gearswap will load automatically a file that is named after the job you swapped to. For example, if you swap to warrior and a file exist named "WAR.lua" it will get loaded automatically. Also works with Name_JOB.lua pattern, so for me, I can name a file Elizabet_RDM.lua and that will get auto loaded when I swap to RDM.

For now, let's just keep "Test_JOB.lua" and load it manually by typing //gs load Test_JOB.lua in the chat window in game.

Now that we have a file to edit and load in the game. Congrats, we have our very own gearswap file. We're all set to start diving into actually making it do things.

Lesson 3 - Creating gear sets!

So in the lua file you'll see I have already preset the following:
Code
function get_sets()
 
    sets.idle = {}                  -- Leave this empty.
    sets.precast = {}               -- leave this empty    
    sets.midcast = {}               -- leave this empty    
    sets.aftercast = {}             -- leave this empty
 
end


The reason I have commented to leave those empty is because of grouping. Basically, sets are variable and we will be grouping some of them together. When we make a variable equal to {}, that means its an empty group, we'll call that group a table from now on. A table can contain another table, so a group within a group. So gearswap already defines "sets" as the table containing all sets. So we don't need to define it, but we can (and I did) define sub-tables.

So in the following:
Code
sets.idle = {}

It means there is an empty table known as idle inside the sets table. Now that this exist, we can also write:
Code
sets.idle.normal = {}

That now means that inside the idle table, there is an empty table called normal. It's kinda like a folder structure if you will. This is the primary way we'll keep things organized and also to add functionality. We'll dig into that more later but for now, you can view it as a sort of folder structure.

We'll first start with magic spells to get a good grasp on the gearswap functionality loop. So, for now we will create a normal idle set for when we're not doing anything, a fastcast set and a cure midcast set. So in that get_sets() function, we'll add those in. The updated function should look like this in your lua file now:
Code
function get_sets()
 
    sets.idle = {}                  -- Leave this empty.
    sets.precast = {}               -- leave this empty    
    sets.midcast = {}               -- leave this empty    
    sets.aftercast = {}             -- leave this empty

	sets.idle.normal = {}
	sets.precast.fastcast = {}
	sets.midcast.cure = {}

end


Now that we have our sets made we can start to add our gear in them. Now you cannot blindly copy paste this one, you'll have to use your own gear in the "", but note the naming of each slot and how it's written in. This is the basis of all sets we're going to create.

A gear set looks like this:
Code
    sets.idle.normal = {
        ammo		=	"Homiliary",
        head		=	"Viti. Chapeau +3",
        body		=	"Amalric Doublet +1",
        hands		=	"Aya. Manopolas +2",
        legs		=	"Carmine Cuisses +1",
        feet		=	"Aya. Gambieras +2",
        neck		=	"Twilight Torque",
        waist		=	"Flume Belt",
        left_ear	=	"Etiolation Earring",
        right_ear	=	"Ethereal Earring",
        left_ring	=	"Stikini Ring +1",
        right_ring	=	"Defending Ring",
        back		=	"Sucellos's Cape",
    }


For an easy way to make a set, you can just equip all the gear for it in the game then type in the game's chat: //gs export That will create a file into the export folder that is in the data folder where we placed our lua file. If you open that file that was created in the export folder is will have create the set for you and you can copy paste the contents of it into the sets we're building now.

So after I add my idle set (above) to the lua my get_sets() function will now looke like this:
Code
function get_sets()
 
    sets.idle = {}                  -- Leave this empty.
    sets.precast = {}               -- leave this empty    
    sets.midcast = {}               -- leave this empty    
    sets.aftercast = {}             -- leave this empty

    sets.idle.normal = {
        ammo		=	"Homiliary",
        head		=	"Viti. Chapeau +3",
        body		=	"Amalric Doublet +1",
        hands		=	"Aya. Manopolas +2",
        legs		=	"Carmine Cuisses +1",
        feet		=	"Aya. Gambieras +2",
        neck		=	"Twilight Torque",
        waist		=	"Flume Belt",
        left_ear	=	"Etiolation Earring",
        right_ear	=	"Ethereal Earring",
        left_ring	=	"Stikini Ring +1",
        right_ring	=	"Defending Ring",
        back		=	"Sucellos's Cape",
    }
	sets.precast.fastcast = {}
	sets.midcast.cure = {}

end


Now repeat that process to fill in the set of gear you'll use for fastcast in the sets.precast.fastcast, and as well the set to maximise cure power in the sets.midcast.cure.

Note: you don't have to fill in perfect sets, but make them all at least different so we can test that it's all changing properly and according to what we want.

See you next time in class #2!
Author: Elizabet
Date Created: 2020-01-16 13:14:38
Date Last Modified: 2020-01-21 16:42:15
Updates: 14
Bytes: 7899