User Tools

Site Tools



lua_tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
lua_tutorial [2023/04/25 16:03] kalilua_tutorial [2023/04/29 07:52] (current) kali
Line 11: Line 11:
   * [[https://www.jetbrains.com/idea/|IntelliJ IDEA]]   * [[https://www.jetbrains.com/idea/|IntelliJ IDEA]]
   * [[https://studio.zerobrane.com|ZeroBrane Studio]]   * [[https://studio.zerobrane.com|ZeroBrane Studio]]
-There are other options out there, most people tend to go with VSCode or Notepad++. I personally prefer IntelliJ but the most important thing is that you know how to use it comfortably because you don't want to have to end up learning how to write Lua on top of how to install and use the software.+There are other options out there, most people tend to go with VSCode or Notepad++. I personally prefer IntelliJ but the most important thing is that you know how to use it comfortably because you don't want to have to end up learning how to write Lua on top of how to install and use the software. This guide will assume you use VSCode and any references I make will refer to that software.
  
 Next are online resources, use these to look up standard Lua functions. Minion uses a modified version of Lua 5.1 with some standard functions removed/modified for security purposes. Keep that in mind when using these and other resources. Next are online resources, use these to look up standard Lua functions. Minion uses a modified version of Lua 5.1 with some standard functions removed/modified for security purposes. Keep that in mind when using these and other resources.
Line 24: Line 24:
 The console is one of your most important tools when developing, debugging, or even reporting an issue to other developers. At first glance it might seem like a bunch of nonsense, but everything in the console has been determined by that developer that it is important information and to output it into the console. The reason for this is if that information is not correct or not intended that we have a record of what Minion's Lua Interpreter executed and in what order if we have enough information. The console is one of your most important tools when developing, debugging, or even reporting an issue to other developers. At first glance it might seem like a bunch of nonsense, but everything in the console has been determined by that developer that it is important information and to output it into the console. The reason for this is if that information is not correct or not intended that we have a record of what Minion's Lua Interpreter executed and in what order if we have enough information.
  
-Now with Minion's Lua instead of using the function **print** to "print to the console" like you normally would use, we simply use the function **d**, and to stick with tradition we can output to the console with our Hello World message:+Now with Minion's Lua instead of using the function ''print'' to "print to the console" like you normally would use, we simply use the function ''d'', and to stick with tradition we can output to the console with our Hello World message: 
 + 
 +{{:tutorial_hello_world.png?nolink |}}
   d("Hello, World!")   d("Hello, World!")
-{{ ::tutorial_hello_world.png?nolink |}} 
 ===== Dev Tools and Lua Source Files ===== ===== Dev Tools and Lua Source Files =====
 {{ ::tutorial_dev_tools.png?nolink|}}Next we're going to introduce Dev Tools and our Lua source files that come by default with MMOMinion. To access Dev Tools open the MMOMinion menu and hover your mouse over FFXIVMinion to expand the menu right and click Dev Tools. Dev Tools, aka Dev-Monitor, is our single greatest resource in Minion as it contains most of our API in one single script. {{ ::tutorial_dev_tools.png?nolink|}}Next we're going to introduce Dev Tools and our Lua source files that come by default with MMOMinion. To access Dev Tools open the MMOMinion menu and hover your mouse over FFXIVMinion to expand the menu right and click Dev Tools. Dev Tools, aka Dev-Monitor, is our single greatest resource in Minion as it contains most of our API in one single script.
Line 32: Line 33:
 To show this off target something like a minion or any NPC, then in Dev-Tools expand the Target tree and expand Core Data and Position Data. Lets go over what this information means. To show this off target something like a minion or any NPC, then in Dev-Tools expand the Target tree and expand Core Data and Position Data. Lets go over what this information means.
  
-{{:tutorial_dev_tools_2.png?nolink |}}+{{:tutorial_dev_tools_2.png?direct&300 |}}
   * Ignore **Ptr**, this information is only used by developers reversing the game to update minion for new patches.   * Ignore **Ptr**, this information is only used by developers reversing the game to update minion for new patches.
   * **ID**, not to be confused with ContentID, is an identifier generated by the servers so the client knows what entity is what. Imagine if you had 5 Ifrit's on the same battlefield, all with the same name, same ContentID, how does the game tell them apart otherwise? ID's are not static/reliable information, a new ID is given every time you zone or load an instance.   * **ID**, not to be confused with ContentID, is an identifier generated by the servers so the client knows what entity is what. Imagine if you had 5 Ifrit's on the same battlefield, all with the same name, same ContentID, how does the game tell them apart otherwise? ID's are not static/reliable information, a new ID is given every time you zone or load an instance.
Line 55: Line 56:
   * **IsReachable** is determined by the Navigation Manager if the entity can be reached by the Player or not.   * **IsReachable** is determined by the Navigation Manager if the entity can be reached by the Player or not.
   * **MeshPosition** is the position on the mesh, not the same as game position.   * **MeshPosition** is the position on the mesh, not the same as game position.
-//*Deep Breath*//, now that was a lot of information wasn't it? And to imagine that's not even 1% of all the information Minion provides about the game. That might sound intimidating, and it can be, but it's always important to remember that you don't need to know what everything is. You can find your way around by context and some documentation about what something is here and there. +//*Deep Breath*//, now that was a lot of information wasn't it? And to imagine that's not even 1% of all the information Minion provides about the game. That might sound intimidating, and it can be, but it's always important to remember that you don't need to know what everything is. You can find your way around by context and some documentation about what something is here and there. I encourage you to look through everything Dev Tools has to offer as you learn and experiment with Lua. There is so much you can do, you just need to know what is available and how to apply that knowledge. 
 + 
 +{{ ::luatutorial_dev_tools_3.png?direct&450|}}In order to apply this information, we're going to need to access the source file for Dev Tools, which is located in Minion's Lua Mods folder.  The MINIONAPP folder is located where you installed Minion, by default the C:\ drive. 
 +  ..\MINIONAPP\Bots\FFXIVMinion64\LuaMods\Dev 
 +The LuaMods folder contains every Lua script that runs with Minion including addons from the store. When you begin making your own modules, which is very soon, you'll maintain all your projects within LuaMods. Now open the Dev folder and open **dev.lua** in the text editor you chose to use. From this point forward I'm going to assume you are using VSCode, so I'll be referencing how to do things from there this point forward. 
 + 
 +{{:luatutorial_dev_tools_4.png?direct&550 |}} 
 +Now there is a lot of information that we aren't ready to talk about in this file, so press **CTRL+F** to search for **Core Data**, there will only be one entry in the file so it will take you right to it. 
 + 
 +This is the same thing you interacted with before in Dev Tools, just the source of it. We're just going to borrow some information from this to help demonstrate how you can use this information in the future, but also it helps you get use to using these files to learn from them. In this image on line 2459 for **Name**, at the very end of the line you see ''c.name''. What is c you may ask? Well, to not overcomplicate it too much the script is using a template and passing a table into the function so it doesn't have to write everything multiple times and will adapt by displaying information only needed for that target type. But to explain what c is, we're going to need to manually grab the table used in our example before, which was our player's target. To do that search for **"Target"** with quotes, and you should see this: 
 + 
 +{{ ::luatutorial_dev_tools_5.png?direct&550 |}} 
 + 
 +  local c = Player:GetTarget() 
 +Lets break this line down, **local c** is making **c** a local variable, which we'll talk about later, **c = Player:GetTarget()** is setting c, **Player** is a global table for your character, **:** is calling a function from the Player table, **GetTarget** is the function within the Player table, and **()** is executing that function. 
 + 
 +We'll talk about all that and more later, but we just need to use **Player:GetTarget()** for our example, so go back to the game and open your console and lets combine the two pieces of information we pulled and apply them together. 
 + 
 +{{::luatutorial_multiple_similar_entities.png?direct&400 |}} 
 +In this example we have 5 Striking Dummies, you can target any entity for this but for this example I'll be targeting these. Target something and in your console, execute this: 
 + 
 +{{ :luatutorial_multiple_similar_entities_2.png?direct&400|}} 
 +  d(Player:GetTarget().name) 
 +Now as you rotate between different targets execute it again to have it print the target's name. You can also mix things up and print your target's ''.id'', or ''.type'', or ''.chartype'', ''.distance'', etc. 
 + 
 +{{ ::luatutorial_multiple_similar_entities_3.png?direct&800 |}} 
 + 
 +  local target = Player:GetTarget() d("["..target.id.."] "..target.name.." is "..string.format("%.2f",target.distance).." yalms away"
 + 
 +Now what did I do there? I simply utilized the information we learned with 3 variables and [[https://www.merriam-webster.com/dictionary/concatenate|concatenated]] them together in the same string. In one simple line it demonstrates that 5 entities all have the same name, but all have different id's and distances from the Player. ''local target = Player:GetTarget()'' is defining **target** as the Player's current target, ''"["..target.id.."] "'' is concatenating brackets on each end of the target id, ''..target.name.." is "..string.format("%.2f",target.distance).." yalms away")'' is formatting the number from distance and [[https://www.merriam-webster.com/dictionary/truncate|truncating]] it to two decimals. It's a bit more advanced, but it should be easy enough to understand I think, but I think it's time we take a few steps back and introduce basic Lua terms so you can be on the same page. 
 +===== Introducing Basic Lua Terms ===== 
 + 
 +  - explain what a variable is 
 +  - comments 
 +  - identifiers, and how they are case sensitive 
 +  - the 21 reserved keywords 
 +  - whitespace and readability 
 +  - variable definition, lists, and declaration 
 +  - the 8 "types" 
 +    - nil, boolean, number, string, function, userdata, thread, and table 
 +  - the type function 
 +  - arithmetic operators 
 +  - relational operators 
 +  - logical operators 
 +  - miscellaneous operators 
 +  - operator precedence 
 +  - loops, break, and infinite loops 
 +  - if statements 
 +  - functions 
 +    - defining 
 +    - arguments 
 +    - calling 
 +    - assigning and passing 
 +    - variable arguments 
 +  - strings and string manipulation 
 +  - replacing a substring, find and match 
 +  - string formatting 
 +  - character and byte representation 
 +  - arrays and multi-dimensional arrays 
 +  - iterators 
 +  - tables and table manipulation 
 + 
 +===== Making our First Module ===== 
 + 
 +===== Common Functions and Standard Libraries ===== 
 + 
 +===== Error Handling and Debugging ===== 
 + 
 +===== Garbage Collection and Performance Impact ===== 
 + 
 +===== Object Oriented and Inheritance =====
lua_tutorial.1682438627.txt.gz · Last modified: 2023/04/25 16:03 by kali