Tools of the Trade

For a couple of years now, I have been considering writing a section about the tools that I use for writing Lua plugins. I have put it off because my development tools for Lua plugins are fairly simple, a text editor and a picture editor. No IDE, or Integrated Development Environment, is needed - in fact an IDE can actually complicate the process for many simple plugins to the point that it deters potential developers. That said, I would like to discuss some of the options available for editing both the text files and images for anyone who is not familiar with some of the quirks.

First, let's talk about text editors. Many of you will already be aware that text can come in several flavors, particularly when handling special characters and accents. The Lua interpreter that the Lotro client uses can read text files in two formats, ASCII and UTF-8 without BOM. What does that mean in plain English?

ASCII is the American Standard Code for Information Interchange and represents all of the regular characters used in the English language without accents. In order to specify accented or other special characters you have to use an 'escape sequence' - that is, you use a sequence of a special character followed by numeric codes to represent the special character. For instance, to represent the accented 'é' (a very common letter in French), you would use the escape sequence /195/169 where the '/' character is the escape and the codes 195 and 169 specify the character code. This is OK if you are writing files that predominantly contain English with a few accented or special characters filled in, but what about string table files for French, German or Russian (where the entire alphabet is different)? Well, for those we need a file format that can handle the special characters as typed characters - enter UTF-8 without BOM.

UTF-8 is the Unicode Transformation Format 8-bit specification. BOM refers to Byte Order Mark which normally would indicate
the 'endianness' of a code and is simply a marker in the first couple of byes of the file but in UTF-8 it isn't really
relevant so the code parser is expecting no BOM character, thus UTF-8 without BOM. Using this format, you can simply type the
accent characters if your keyboard supports them, or copy/paste them or (as I usually do) use the Alt+character codes to type
them. For instance, to type a 'é' character, you can hold the Alt key and press the numbers 0233 on your numeric keypad and
you will get a 'é' character (neat, huh?). Many editors also support virtual keyboards where you can get a pop-up window
showing the accent/special characters and select them with your mouse. Just remember to set the encoding to UTF-8 without
BOM before saving your file (the method to do this differs by editor but it is usually an option from the editor menu). Note, the UTF mode supported by standard Windows Notepad is UTF-8 with BOM and will cause an error when read by the client.

So, what editor to use. Well, if you are mostly dealing with English and don't mind using escape sequences for the occasional accent/special character, just use Notepad or any other editor that can save as ASCII. That is by far the simplest answer. To edit using UTF-8 without BOM, I have personally used Notepad++ which is available for free for non-commercial use. Most recently, I have been experimenting with VSCode which is a fairly simple but powerful editor. Lunarwater has written an extension to VSCode that provides context sensitive help for the Turbine API. This is worth noting because the documentation for the API is kind of thin and any help that can indicate when you are using the correct methods and properties of the API classes helps. He has also included support for a number of the undocumented features like SetStretchMode and Rotate (two of my all-time favourite Turbine Window methods). To use the VSCode editor, you can download it from https://code.visualstudio.com/download
To use the Lua and Turbine extensions, open VSCode, click the Gear icon at the bottom left, select 'Extensions' from the menu (or type Ctrl+Shift+X). In the search box at the top, type Lua. Select the 'Lua Language Server coded by Lua' and click Install. Then type 'lotro' in the search box. Select the 'Lord of the Rings Online API' and click Install. You now have context sensitive help for the Lua language as well as the Turbine API for LotRO.

There are many other editors, many of them part of IDEs and if you are already familiar with one like Eclipse, it may be worth using it for familiarity's sake, but I prefer to avoid the overhead inherent in full blown IDEs when editing Lua projects. Then again, if you are already familiar with an IDE, this particular chapter probably isn't really for you

On to image editing. The client only allows us to load two types of images, JPG (Joint Photographic experts Group) and TGA (Targa). JPG files are great for handling compression and making small files, but JPG is a 'lossy' compression, meaning that the image will be slightly different once saved as a JPG in order to enhance the compression and make the resulting file smaller. Normally this is not a big issue and .jpg files are great for large images like maps where exact pixel correctness is less important than getting as many maps into as small a footprint as possible. The biggest difference with tga files is that tga is lossless (thus larger files) but supports the alpha channel - what is an alpha channel, you ask? Well, ever see an overhead projector where slides can be shown on top of other slides, and they show through each other? Well, the alpha channel allows for transparency or even partial transparency of the image so that when over laid it will show parts of the underlying image. This is really handy for UI elements that want to superimpose an irregularly shaped image over a background image. It is also handy if you want to blend an image with a background color to create a variably colored UI element (like the wear state components in the item wear mannequin which change from green to yellow to red to black as an item wears). As an example, .tga files are typically used in MoorMap for Overlays since the Overlay will usually want to show the background map and only overwrite the portions that indicate a special location or instructions or a path, etc.

So, how do you get a jpg or tga file? By far, the simplest method to create/edit a jpg file is the Windows Paint program built into Windows (or whatever editor is built into your chosen OS). This will allow you to create and save images, edit screenshots captured from the client, etc. and save them as jpg files. Unfortunately, Paint does not support the tga format. So, I usually recommend a free application called Paint.Net. Paint.Net has been around for years, has lots of extensions and plugins available if you are into that (I use one for blur effects) and most importantly supports a couple of really useful features, notably jpg and tga formats, transparency and Layers. What's a Layer? Simply put, layers allow you to work on an image in multiple overlapping layers which when combined create a finished product. Why is that important? Because when replacing part of the UI or creating an Overlay for MoorMap, it is easiest to work over a copy of the original. I will take a screenshot, open it in Paint.Net, change the resolution (if necessary), and then add a layer and do my work on the new layer with the original as the background. That way I know that what I am working on will line up exactly where I want it to in the client. Then, I can either flatten the layers to create a new image with my work on top of the default image, or more likely, remove the background layer and have just my work. Once I have the desired image, I save it as a tga file and the transparent portions will display the default client UI or whatever else is behind them when they are displayed.

And that covers not only which applications I use for working on plugins, but some of the reasons why I have chosen those particular applications. As I noted, there are many programs that can be used to write plugins. For simplicity I have focused on those that are either part of the Windows operating system or are free to use for non-commercial purposes.