LUA Study Notes: World of Warcraft custom interface plug-in

Source: Internet
Author: User
Tags switch case blizzard

LUALearning notesWorld of WarcraftCustomInterfacePlug-ins are the content to be introduced in this article, mainly to understand that the library files of the operating system are not included inWorld of WarcraftIn the PATH of the UI, this article isWorld of WarcraftCustomInterfaceThe introduction of plug-ins mainly describes how to define Custom UI plug-ins (Custom UI:

UserInterface(UI-User Interface) wizard

Recently, many players have flocked to the WOW group, many of which, like me, have some programming experience and want to try to create UI plug-ins. With many programming languages and interfaces, many people may take some detours. I hope the following content can reduce the above situations (at least reduce the headache for finding information about those functions ):

(In fact, it is not difficult. The content only involves the knowledge of some scripting languages and XML documents. Even if you have not written a program, you can be competent .)

1. Start preparation

1) available tools

The first step must understand what we will do, but in order to get started correctly, we must select some scripting tools. First of all, I think the Editor (in professional terms, IDE-integrated development evironment) may have many options. Since we write a script in LUA (for more information, see www.lua.org), we need an editor for this language. The following is a list of 10 options:

Blua.sourceforge.net)

B: Lua is one of its first script editing tools. It provides powerful IDE functions and is enough to edit WOW UI. Moreover, it is written in Java and runs in whatever operating system.

Www.ideais.com.br/luaeclipse .)

Lua Eclipse? This is another Java environment IDE. I have never used this IDE. It is based on the Eclipse platform (for more information, see www.eclipse.org ), it is a plug-in with multiple features, and I'm sure this is a good tool.

Editplus.com/(: editPlus is a text editor similar to UltraEdit)

EditPlus? This is an effective tool to replace the Notepad program, and also a tool for editing LUA. It has a variety of features you need, and it has a LUA language Schema (can be understood as a template, it specifies how the file is defined and so on ). But it has a 30-day evaluation period and you have to register it.

These are just three suggestions. I think once you have mastered B: Lua, you will be able to use other tools better.

2) Target: WOW File

After you have the editor, everything is just getting started. We need some tools to edit WOW. The preferred tool is WinMPQ: shadowflare.gameproc.com/dwnload.html#WinMPQ

You need to run the Library (VB4 Runtime Library) to run it. With it, you can open the MPQ file or MoPaO file in the game directory. MPQ is the file format used by blizzard to store game materials. For more information, see www.campaigncreations.org/starcraft/inside_mopaq/index.htm.

With WinMPQ, You can unbind the file content and package it into the game installation directory.

With WinMPQ, You can unbind the file content and package it into the game installation directory, which contains all the content you need. The Interface. mpq file contains basic Interface data and a large number of KE files as examples. The Patch. mpq file contains all the Patch content, which will overwrite all the basic files during game operation.

Open WinMpq and use all the basic interface files as an example. We will also demonstrate how to ensure that the data is consistent with the latest patch. Use the "Open" option to Open the interface. mpq file (this file is under the game installation directory), find a folder named FrameXML (there is also a folder named glueXML, regardless of it ), select all files in the directory and decompress them to a directory other than game installation.

Open Patch. mpq, not onlyInterfaceFile, there are many update files. Open the Interface \ FrameXML directory, decompress the content to the extract directory of the interface. mpq file, and overwrite the existing file. In this way, we have a copy of the latest FrameXML directory data on the game interface as a reference. (You can also use WinMPQ to decompress other files, such as music files ).

2. When a target is set

Everything is ready. Let's get started with the first plug-in!

First, you know the specific file arrangement and what file is made. Let's take a look at the following World of Warcraft installation. There are many directories, and the directory we want to operate on is the Interface directory (create if it does not exist ). There are three main directories in this directory:

FrameXML: There are all interfaces provided by blizzard, where you will deal with all the files.

GlueXML: contains non-gameInterfaceSuch as the logon interface, server selection, and role creation. You don't need to worry about these files.

AddOns: Model of all game roles.

Under the AddOns directory, each role has all its directories and a content table.

3. Start

1) initialization

We are starting to create "Hello world! (: "Hello world" usually refers to the first program). Create a directory named hello_world under AddOns, that is, Warcraft/Interface/AddOns/hello_world. Create a file named hello_world.toc in the directory. This is the content table, which defines how WOW loads the plug-in content. For example, the following is the file content:

 
 
  1. Interface: 4114   
  2. Title: Hello World   
  3. Notes: The obligatory hello world script ? WoW-style!   
  4. OptionalDeps:   
  5. Dependencies:   
  6. hello_world.xml  

The first line indicates the beginning of the new code segment. In fact, the current version number is updated every time blizzard updates the patch. If your script does not have the latest version, this script will not be loaded into the game. This is why plug-ins cannot be used due to version updates.

You can open the Interface \ FrameXML. toc file to know the current version number. The Title and Nodes of the next two rows do not need to be explained. (optional ). In the next line, you can list the names of all your plug-ins in OptionalDeps (you can list other plug-ins, separated by spaces ). Dependencies is the same, but it is not optional. I'm not sure if your plug-in will be loaded without this line. It is best to write everything, whether it is optional or not, so that everyone can better read your code.

After the Declaration starts, you will write the names of some XML files (the order is not fixed) and write a file name in one row. You can also write an XML file in a subdirectory, such as "core/hello_world.xml", to make the folder look more concise.

Oh. Is it complicated? You don't have to worry about anything else.

2) add content

The following will be the most interesting part. Let's start with a simple one. Create a hello_world.xml file in the directory (the file name should be written in FrameXML. toc). The content is as follows (for the XML file format, refer to the relevant documentation ):

 
 
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  2. xsi:schemaLocation="http://www.blizzard.com/wow/ui/">   
  3. <script file="hello_world.lua"/>   
  4. <!-- Frame to handle all core events -->   
  5. <Frame name="hello_world_core">   
  6. <scripts>   
  7. <onLoad>   
  8. this:RegisterEvent("VARIABLES_LOADED");   
  9. </onLoad>   
  10. <OnEvent>   
  11. if (event == "VARIABLES_LOADED") then   
  12. hello_world_initialize();   
  13. end   
  14. </OnEvent>   
  15. </scripts>   
  16. </Frame>   
  17. </Ui>  

(See wow.nevir.net/tutorial/hello_world/hello_world.xml)

Oh. Is it complicated? If you do not need to read the <script file = "hello_world.lua"/> line first, it tells the game hello_world.lua that it is a script file, that is, the script running by the plug-in. Each interface is expanded with a <Frame> Tag. Here we use a Frame tag to package all event scripts. You can alsoInterfaceButtons and windows are defined in the Frame tag. In the <Frame> label, you can define an attribute named name (for example, <Frame name = "hello_world_core">)

Note that the values must be unique in the entire file. We recommend that you use your plug-in Module name as the prefix, followed by an underscore, and then the name of the true meaning of the Frame. In the above example, we call it core, which forms the above name.

There is a <script> tag in the <Frame> tag, which is a realScript. Here, there are many events (the action that the World of Warcraft game program will perform at a certain stage), of which <onLoad> and <OnEvent> are the two most commonly used events.

Here, <onLoad> is the event that will be responded before the role Laoding screen starts when you select the role to enter the game (in other words, your plug-in will not be loaded when you log on to the screen ). In our code, we registered this and gave an event named "VARIABLES_LOADED ".ScriptLanguage introduction books). this indicates the current Frame, that is, the Frame named hello_world_core. this is the object/variable pointing to the Frame object (pointing to the instance of the Frame object ), the ":" Here is equivalent to the expression of the reference method (like in some other scripting languages ". the RegisterEvent function tells the game program to notify you of the defined Frame when the VARIABLES_LOADED event occurs (VARIABLES_LOADED is an event defined in the game. Here we have to talk about the <OnEvent> label, where there is a default variable event, its value is the name of the event generated in the current game (just like the VARIABLES_LOADED above ).

You really need to understand programming. The event processing mode is similar to the code mode of Win32 event processing. You can use if (event = event name) {operation code} else if (event = event name 2) {operation code }..... Or switch case .)

Blizzard now provides a way to store variables. You can use RegisterForSave ("variable_name") to define a variable during the game.

In our example, when VARIABLES_LOADED occurs, the hello_world_initialize () function is called for processing. Right, this hello_world_initialize () function is not defined yet. The following describes how to define a function.

3) after completing (note: the part of the Code, the person who writes the script must be familiar with it, but does not need to learn what to do: <)

Now is the time to write code. Create a file named hello_world.lua. The content is as follows:

 
 
  1. function hello_world_initialize()   
  2.  -- add our very first chat command!   
  3.  SlashCmdList["HELLOW"] = hello_world_command;   
  4.  SLASH_HELLOW1 = "/hellow";   
  5.  SLASH_HELLOW2 = "/hw";   
  6. end  
  7. function hello_world_command(msg)   
  8.    -- this function handles our chat command   
  9. message(msg);   
  10. end  

I don't want to explain the syntax here. If you don't understand the syntax, please read the LUA documentation, which will introduce it in detail. See www.lua.org/manual/5.0/

Note that the system I/O library file is not included in the operating system library fileWorld of WarcraftIn the PATH of the UI. For blizzard-defined functions (built-in) and events, you can find them on the Cosmos website. For more information, see www.cosmosui.org/texts/BlizzardCommands.xml.

Return to the Code. In our function, we define a chat command. It seems that our code looks strange. Yes, we directly modified the SlashCmdList table, when we input the macro "/hellow message" or "/hw message", the hello_world_command () function is called, (this article does not discuss how to map the relationship within the game.) then, the player can see the chat window that displays the "message" (in fact, msg () function creation window ). We can see that the "message" is passed to the hello_world_command () function as a parameter.

All of the above is a simple plug-in, which includes two commands (macros ). If you want to test it, enter the game, enter/console reloadui (reload UI), and enter "/hellow Why hello there!" in the chat box after logging on to the game !", You will see a message box popped up in the game. The message is "Why hello there !".

4. Complete

This is our basic example. In the future, I may take some time to give some other examples.

If you have completed the above example, I would like to applaud you! (It takes you a lot of time to read .)

If you are interested, you may find a lot of information as follows:LUA(Www.lua.org/manual/5.0/), a function defined by Blizzard (www.cosmosui.org/texts/BlizzardCommands.xml ). In addition, try to see the Interface/FrameXML/BasicControls. xml file, which contains many control statements, and the Font. xml file, which allows you to define your own fonts and colors.

Summary:LUAStudy Notes:World of WarcraftCustomInterfaceThe plug-in content has been introduced. I hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.