FFXIAH.com

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

Master thread

Lesson 10 - Idle and Engaged

Alrighty! It's time to take a look at the idle and engaged sets! First, gotta make a few new sets! I am pretty sure you know how to do this by now. Last time we also added this category: sets.melee. We're going to make use of it now. Adding the following set:

sets.melee.normal

Note: It doesn't have to be sets.melee it could be sets.engaged or whatever suits your fancy, as long as you are consistant. I like to use melee so I can differentiate, at a glance, between melee and ranged sets for TPing.


Then, we need to look in our test lua at the bottom. There is a function called status_change. Gearswap runs this function when you engage, disengage or rest for mp or hp. So it's a good place to start telling our lua to change somethings based on those action. For example, we could say when we engage, swap to a melee set. In order to do that, we have to know what's the satus when changing to. Like this:
Code
function status_change(new,old)
	if new == 'Engaged' then
 		equip(sets.melee.normal)
	else
		equip(sets.idle.normal)
	end
end


This while it would work..ish... Would not be ideal, because everytime we can a spell, or use a JA or WS as we set in the previous lessons, we run the idle() function in the aftercast. And the idle() function puts us back into idle gear. So after each WS or something, we'd be swapped out of our TP set. That's not good! So, instead of doing it there in status_change, we'll need to put that logic in the idle function. So that when we cast something, then it know which set to revert us back to. But since we'll have that logic in the idle() function, there is no point writing it twice. So in the status_change function, we'll just tell it to run the idle() function when that status_change function runs. The idea here is that when the status change (say we engage) then we check the idle function for what set to use, just the same as if we had cast something.
Code
function status_change(new,old)
	idle()
end


But now we need to actually put a rule in our idle() function to handle this. Fortunately, https://docs.windower.net/addons/gearswap/reference/#player is our friend again. Gearswap has variables we can check that tells us a bunch of things on the player. Such as the status! See player.status in the link above. Using that variable we can make a simple if-then-else type rule inside the idle function:

We had:
Code
function idle()
    equip(sets.idle.normal) 
end


Now we can change it to:
Code
function idle()
	if player.status=='Engaged' then
	    equip(sets.melee.normal) 
	else
	    equip(sets.idle.normal) 
	end
end


This way whenever idle() is run (now on status change, and on aftercast) it'll first check if we are engaged or not, before putting us in either an idle or a TP set.


Lesson 11 - Sets Variation, using set_include

So now our little test lua that could is able to swap you into precast/midcast sets for magic, WS and JA sets as well as return you into an idle set or a TP set depending if you're engaged or not. And you also now have everything you need in the previous lessons to add sets and rules for any spell or ability you'd want. So now we'll get into how to support a DT swap.

So the first thing to do when creating a set variation (we'll start with sets.melee.dt) is that we can base it off another set and only add in the gear that is different. To do that when we make a set instead of this:
Code
sets.melee.dt = {
	
}


We'll do this:
Code
sets.melee.dt = set_include( sets.melee.normal, {
	
})


This way, even if we leave it empty as is, the sets.melee.dt will be the same as sets.melee.normal. But if we add gear in it now, it will be the same as the set we put in the set_include parenthesis, except it will differ in the gear we define. For example, the set below would be exactly as my normal TP set, but also swap in my D ring.
Code
sets.melee.dt = set_include( sets.melee.normal, {
	right_ring  =   "Defending Ring",	
})


This is important, because if I had simply made the above set without the set_include part, then whenever I would swap to sets.melee.dt after using a spell, I'd remain in the casting gear except for that D ring. So you have the option of either using set_include, or remember to put ALL the gear in each slot for your set. In short, set_include lets you say: "it's like this set, but with these following gear instead."

Now that you made sets.melee.dt, go ahead and make sets.idle.dt. You can choose to use set_include or not, I would suggest getting used to it, it's quite handy.

OK, now that we have the dt sets made, we need to decide when to use them. First we'll go back up all the way at the top of the file. If the very first line is "function get_sets()" then drop it a few lines so we can put the following above it.
Code
useDTsets = false


That means we now have a variable called useDTsets that is initialized as false. So we'll be able to use it in our idle() function to decide which sets variation to use. We can do that by making yet again a simple if-then-else rule checking that variable we just made. So our new idle would look like this:
Code
function idle()
	if player.status=='Engaged' then
		if useDTsets == true then
			equip(sets.melee.dt)
		else
			equip(sets.melee.normal)
		end 
	else
		if useDTsets == true then
			equip(sets.idle.dt)
		else
			equip(sets.idle.normal)
		end 
	end
end


Note: When using "if useDTsets == true then" with a variable that is either true or false, you can simply write "if useDTsets then" to test for true, and "if not useDTsets then" to test for false

Now that we have the bare bones of that working we need a way to change the "useDTsets" variable to true when we want it to. Otherwise as is now, the variable will stay false forever and we'll be in the normal sets all the time.

Lesson 12 - self command

Now we're getting into pretty advanced stuff, but if you've stuck with me so far you should be able to get this too. In gearswap, you can send a command to it via the game chat box. And t can be and do almost anything. The basis of it is that once you type "//gs c something" the "//gs c " part tells gearswap you want to send it a command and that command is "something" that by itself wont do anything because we haven't put any code for that in yet. So anything that comes after the space after the "c" in "//gs c " is part of the command. It can have many words in it like: "//gs c play Ariana Grande on spotify". Basically, "//gs c" is like "Ok Google" or "Yo Alexa" or something.

In order for our lua to understand those commands, we need to add a new function. You can add this one all the way at the bottom of the lua.
Code
function self_command(command)

end


This function is called when we type in "//gs c stuff". Note that "command" is put in the parenthesis in the function declaration. That means that in the case of "//gs c stuff" typed in game, when we're inside that function command now equals "stuff". Got it? So if I type "//gs c yo mamma" then inside the function, command would equal.... yep, "yo mamma".

So I'll go ahead and put some more code in the above function and explain what that does in comments.
Code
function self_command(command)
	local commandArgs = command				-- First we copy the content of command inside a new variable for our use. 
	if #commandArgs:split(' ') >= 2 then			-- We check if there is 2 or more words in the commandArgs.
        	commandArgs = T(commandArgs:split(' '))		-- If there is indeed 2 or more words, we split each words into a different entry, so commandArgs[1] and commandArgs[2] if there was 2 words.
	end
end


So from there, if you typed in "//gs c yo mamma" then the above code would split "yo mamma" into commandArgs[1] = "yo" and commandArgs[2] = "mamma". Got it? So we're going to be using this to toggle our DT sets on or off. For example we'll use the command "//gs c toggle useDTsets". So after we split the "toggle useDTsets" command in 2, first thing our function needs to do is to check for that specific command. So we can check if we match the first word, "toggle". To help debugging and also for general usability we can use this in the code: windower.add_to_chat(123,'Stuff and Things')

That will put 'Stuff and Things' or whatever else you wrote in there in the game's chat (only for you to see). Remember how if-then-else stuff we keep doing works? Then you should be able to make sense of the code below.
Code
function self_command(command)
	local commandArgs = command					-- First we copy the content of command inside a new variable for our use. 
	if #commandArgs:split(' ') >= 2 then				-- We check if there is 2 or more words in the commandArgs.
        	commandArgs = T(commandArgs:split(' '))			-- If there is indeed 2 or more words, we split each words into a different entry, so commandArgs[1] and commandArgs[2] if there was 2 words.
		
		if commandArgs[1]:lower() == "toggle" then		-- the :lower() part makes sure that capital letters are now lowercase, so "Toggle" and "toggle" are both fine. 
			if commandArgs[2]:lower() == "usedtsets" then	-- We passed the first word test, now we check for the 2nd word.
				if useDTsets then			-- if useDTsets is true
					useDTsets = false		-- then we set it to fasle
				else					-- else, means it was false
					useDTsets = true		-- so we set it to true.
				end
			else
				windower.add_to_chat(123,'Error. 2nd word unkown, don't know what to toggle.')
			end
		else
			windower.add_to_chat(123,'Error. The first word is not toggle.')
		end
	else
		windower.add_to_chat(123,'Error. Only 1 word command. Need 2 words')
	end
end


So now, the "//gs c toggle useDTsets" command you can type in game will flip the useDTsets variable from true to false or vice versa. And because of the new idle() function we made to check that variable. The correct wanted variations of melee or idle sets will get equipped.

Technically, from here onward you should now be able to make a workable lua for any job. It wont be the best ever, but it'll work. So I encourage you to make your own, as questions, try stuff out, use these threads to ask anything you are unclear on.

The next classes are going to dive a bit deeper in things we can do better handling for sets that are used in many spells, or that have variations between them. For example, enhancing duration vs potency. So that we don't have to make a ton of sets for each individual spells.

Toodle-oo
Author: Elizabet
Date Created: 2020-01-26 12:31:32
Date Last Modified: 2020-01-26 14:16:34
Updates: 9
Bytes: 10701