World of Warcraft super assistant Lua scripting language

Source: Internet
Author: User
Tags set time types of functions

World of WarcraftSuper AssistantLua scriptLanguage is the content to be introduced in this article, mainly to understandWorld of WarcraftDevelopment languageLuaFor more information, see this article.

LuaProgramming structure:

1)LuaComment: The line comment identifier "", used to comment the content of the subsequent line. Multi-line comments start with "[[" indicating the comments and end.

2) Lua program: each statement block of Lua requires the end keyword to end. The control statements include:

 
 
  1. If condition then... elseif condition then... else... end
  2. While condition do... end
  3. For variable = initial value, end value, step do... end
  4. For variable 1, variable 2,... Variable n in table or enumeration function do... end

.

A function starts with a function and ends with an end. It also supports Object-Oriented Programming modes such as class, inheritance, and private.

Note:

1) The string. len (s) function of the string library calculates the length of a single byte. For example, if a double byte Chinese character is 2 characters in length, it is calculated in sequence and so on.

2) the starting point of the array type element in the table database is 1. The starting point 0 of the element in the regular language will be ignored. The number of elements in the specified array obtained by table. getn () starts from 1. For example, a [0] is always nil (that is, null does not exist ).

3) logical operators "and (and), or (or), not (not)", and Relational operators "~ = (Not equal to) "; the concatenation operator"... "is different from or similar to other languages. Do not confuse or abuse it. The connector can be used to directly connect values, strings, expressions, and so on.

Script control and multi-script collaboration:

Pause sleep: sleep (MS) Function

Set the timer: timer number = settimer (millisecond, 'function name') Function

Disable the Timer: killtimer (timer number)

Display debugging information: trace ('content') Function

RunScriptFunction: thread handle, thread ID = runlua ('filename ')

(Start multiple timesScript, File name: relative to the assistant Scripts directory) multiple Scripts support setting and obtaining public variables. BecauseLua scriptMultithreading is not supported, so we can use multiple scripts to implement the multi-threaded program operation mode.

Return Value: integer value of the thread handle, and integer value of the thread ID

Set the global variable of the string: setglobalstring ('variable name', 'variable value ')

Setglobalint ('variable name', variable value)

Set the floating point global variable: setglobalfloat ('variable name', variable value)

Get global variable: value = getglobalvar ('variable name ')

Obtain the number of global variables: Count = getglobalvarcount ()

Delete global variables: removeglobalvar ('variable name ')

Note: The above variable name can be up to 63 bytes, and the excess part will be truncated. Global variables are allLUA scriptAll can be accessed, so it is as complex as possible to name the variable name, so as not to conflict with the delivery thread message: whether the message is successful = postthreadmessage (thread ID, message, word parameter, long parameter)

Thread ID: ID of the thread returned by runlua.

Message: message ID

WParam: Word Parameter

LParam: long parameter

Return Value: 0/1

Set monitoring thread message: setmsgwatch ('message monitoring callback function name ')

Note: This function must be placed at the end of all code; otherwise, the subsequent code will not be executed.

Reference format:

 
 
  1. Function msgwatchfunc (message, wParam, lParam)
  2. [[Message, wParam, and lParam correspond to messages, parameter, and long parameter of the message function of the shipping thread respectively]
  3. ...
  4. End
  5. Setmsgwatch ('msgwatchfunc ')

File and system functions:

INI File Read operation: value = readini ('node name', 'value name', 'file name ')

INI file write operation: writeini ('node name', 'value name', 'value', 'file ')

Obtain the number of milliseconds since the system was started: milliseconds = gettickcount ()

Return Value: unsigned integer value

BELL: beep (frequency, duration [millisecond]) Function

MP3 playback: playmp3 ('mp3 or wav file path') Function

Copy text to clipboard: copytexttoclipboard ('text to be copied content') Function

Window control and process operations:

The assistant provides a variety of function interfaces for windows program windows and process operations to implement the vast majority of windows program control and process operations, which are not listed here, for more information, see the function menu of the assistant Script Editor. Here we need to emphasize two of the functions:

The customer Region coordinates are x, y = clienttoscreen (window handle, customer Region x coordinate, customer region y coordinate)

The screen area coordinates are x, y = screentoclient (window handle, screen x coordinate, screen y coordinate)

The screen area coordinates are often used when operations involving mouse positioning, while the operations of the Program (a program that is not operated by a script mouse or mouse simulation) relative to its own location are the coordinates of the customer area, therefore, the two functions are required to convert the interaction coordinate parameters.

Keyboard and mouse operation and control:

This function is widely used in the basic mouse and mouse simulation operations for games.

To perform mouse-and-mouse simulation and control, you must first set the mouse-and-mouse monitoring program to intercept or filter the mouse-and-mouse operations. The assistant directly provides function support for monitoring and control.

1) setkeywatch ('function name'): keyboard operation

The reference format is as follows:

 
 
  1. Setkeywatch ('keyhookfunc ')
  2. Function keyhookfunc (keycode, controlkey, downorup)
  3. Keycode: key code
  4. Controlkeycode: Alt Shift Ctrl status
  5. 1: Left Alt press 2: Right Alt Press
  6. 4: Left Shift press 8: Right Shift Press
  7. 16: Left Ctrl press 32: Right Ctrl Press

Multiple control keys support bitwise operation Detection

 
 
  1. Downorup: 0 press 1 to open

Returned value: 1-The assistant and Windows do not continue to process the key. 0-the assistant and Windows continue to process the key.

 
 
  1. return 1  
  2. end 

In the keyhookfunc function, we can intercept and filter all key information, and add analog operations to the program for processing. To implement the simulated keyboard operation we want to implement.

2) setmousewatch ('function name'): Mouse operation

The reference format is as follows:

 
 
  1. Setmousewatch ('mousehookfunc ')
  2. Function mousehookfunc (msg)
  3. Msg: Mouse message
  4. 1-Left click to press 2-Right click to press 3-click to press
  5. 4-extended key 1 Press 5-extended key 2 Press
  6. 11-left-click Release 12-Right-click release 13-click release
  7. 14-extended key 1 released 15-extended key 2 released
  8. 21-roller roll up 22-roller roll down

Returned value: 1-The assistant and Windows do not continue to process the message. 0-the assistant and Windows continue to process the message.

 
 
  1. return 1  
  2. end 

In the mousehookfunc function, we can intercept and filter all mouse messages, and add analog operations to process them. This allows us to simulate mouse operations.

3) setmousewatchex ('function name'): Specifies the mouse position function.

The reference format is as follows:

 
 
  1. Setmousewatchex ('mousehookfuncex ')
  2. Function mousehookfuncex (msg, x coordinate, y coordinate)
  3. Msg: Mouse message
  4. 0-move the mouse 1-Press the left button 2-Right click and press 3-middle click
  5. 4-extended key 1 Press 5-extended key 2 Press
  6. 11-left-click Release 12-Right-click release 13-click release
  7. 14-extended key 1 released 15-extended key 2 released
  8. 21-roller roll up 22-roller roll down

Returned value: 1-The assistant and Windows do not continue to process the message. 0-the assistant and Windows continue to process the message.

Note: Do not move the message with the mouse for time-consuming operations. Otherwise, the mouse will become slow.

If you do not need to monitor mouse movement, directly

 
 
  1. if msg==0 then return 0 end  
  2. return 1  
  3. end 

The setmousewatchex and setmousewatch functions are basically the same. The difference is that the setmousewatch function allows long-time delay operation simulation, while setmousewatchex is definitely not recommended for long-time delay operation simulation, otherwise, your mouse will remain idle and not controlled during this delay. During Normal script operations, delayed operations unrelated to mouse positioning are performed in setmousewatch. The simulated operations on mouse positioning are processed in setmousewatchex. The two will not cause any problems in collaborative processing.

When some simulated operations require keyboard, mouse, and mouse positioning, the script needs to set the above three monitoring functions and then break down the simulation operations and control of their respective duties, the synchronous simulation can adopt the simplest mode of variable state change for coordination. This mode is widely used in existing scripts provided by the assistant. If you are interested, read and view the script on your own.

4) mouse and mouse simulated operation functions:

Key: keypress)

Press the keyboard key: keydown (key code)

Release the keyboard key: keyup (key code)

Mouse Click: mouseclick (mouse key)

Mouse key: 0-Left click 1-Right click 2-middle click

Press the mouse key: mousedown (mouse key)

Mouse button release: mouseup (mouse key)

Editing mouse: lockmouse (x coordinate, y coordinate)

When the coordinate is the x coordinate of the customer region or the y coordinate is-1, unlock

Note: the customer and Region coordinates are the coordinates relative to the program interface. The customer and Region coordinates must be converted to the screen coordinates. The conversion function is in the window operation.

Lock the mouse: disablemouse ()

Unlock mouse: enablemouse ()

In the above functions, the differences between the keyboard buttons and the keyboard buttons are as follows, you only need to press the keyboard or mouse to simulate a normal mouse or mouse, when performing the key combination operation, you need to press the keyboard button and press the keyboard button loose, press the mouse button, and release the mouse button to complete the cooperation. First, you need to execute all the key combinations by pressing the simulated operation, then, execute all the Undo operations to simulate the key combination. Of course, during single-key simulation, you can also press to release the simulation operation. The simulated operation, especially the key combination simulation operation, requires a certain sleep delay after each simulation to avoid the simulation operation failure in some cases.

5) mouse and cursor operations:

Query mouse pointer coordinates: x, y = getcursorpos ()

Set mouse pointer coordinates: setcursorpos (x, y)

That is, positioning the mouse coordinates

5,World of WarcraftInformation Acquisition and support:

As a helper tool for World of Warcraft, obtaining and supporting World of Warcraft information for the script is the most worthy of our detailed understanding.

1) World of Warcraft information and status:

Query World of Warcraft version: version = getwar3version ()

The returned value is an unsigned integer.

Get World of Warcraft path: World of Warcraft Path = getwar3path ()

The returned value is a path string.

Determine whether World of Warcraft is at the frontend: whether it is at the frontend = iswar3front ()

The returned value is 0 or 1.

Judge whether World of Warcraft is running: whether it is running = iswar3running ()

The returned value is 0 or 1.

Judge whether World of Warcraft has started: whether it has started = isplaying ()

The returned value is 0 or 1.

Determine whether the user is in the chat status: whether the user is in the chat status = ischat ()

The returned value is 0 or 1.

Query the current map name (including the path): Map Name = getmapname ()

The returned value is a map name string.

Query currently selected unit ID: Selected unit = getselunit ()

Returns the ID list of the selected units (multiple)

Query currently selected unit ID and handle: Selected unit ID, selected unit handle = getselunitex ()

Returns the ID and handle list of the selected units (multiple)

Query the current operational unit ID and handle: unit ID, unit handle = getcurrentunit ()

Different from "getting the currently selected unit", this function obtains the one that can be operated in the selected unit (the Tab key in World of Warcraft can be switched)

Returns the ID and handle of the leader organization (single)

Query unit attributes: attribute value 1, attribute value 2, attribute value 3,... = getunitattribute (unit handle, attribute code 1, attribute code 2, attribute code 3 ,...)

Multiple Attribute values can be queried at a time. Property Code:

1: HP limit 2: HP 3: MP limit 4: MP

5: experience 6: Strength 7: agility 8: Intelligence

9: attack frequency 10: basic attack capability 11: attack times by 12: dice

13: attack type 15: armor 16: Armor type

19: Skill 1ID 20: Skill 2ID 21: Skill 3ID 22: Skill 4ID 23: Skill 5ID

24 ~ 28: Skill 1 ~ 5. Highest Level 29: available skill points

This function is a function with multiple parameters and multiple return values.

Query unit item bar information: item handle, item ID, remaining item usage = getunititem (unit handle, item No. [0-5])

Returns an integer, a string, or an integer. Returns 0, '', 0 if the specified position item fails to be obtained.

Speaker: talk ('content', target)

Content: Separate multiple rows with \ r \ n

Target Audience: 0-Ally 1-all

SetWorld of WarcraftField of view: setcamera (field of view [500 ~ Between 5000])

Display FPS: enablefps (whether to enable [0-No 1-Yes])

Query local players and teams: SlotID, team = getmyslotidteam ()

SlotID is the game location ID, which is determined by the player's location before the host starts the game

The team is the game camp

Query the player information of a specified SlotID: Team, person, or computer, race = getplayerinfoex (SlotID)

People or computers: 0-1-computer

Race: 1-HUM 2-ORC 3-UD 4-NE

Team:-1: Acquisition failed (may not be in the game yet, or SlotID is out of bounds) 0: None this player> = 1: team

Query the hero list of a specified SlotID: Number of heroes, hero handle list, Hero ID list, SlotID list of heroes = getherolist (SlotID)

Hero handle list, Hero ID list, And SlotID list of heroes separated by commas (,)

SlotID:-1: Take the hero list of all players-2: Take your own hero list 0-15: Take the hero list of the corresponding SlotID

The extracted sequence conforms to the F1 ~ F5 Sequence

Query player index: Player Index = getplayerindex (SlotID)

This function gets the actual location index of the player after the player enters the game (the camp may be exchanged.

After the Chenghai exchange camp, you can determine the gamer camp.

2) LAN information and status: the LAN information and status function depends on whether the "host" Page function is enabled

Obtain host information: Game ID, Host IP address, host name, host creator name = gethostinfo (No. [0-255])

Returns the integer ID, IP string, host name string, and creator string.

Obtain player information: Player ID, player IP address, player port, player name, player status = getplayerinfo (serial number [0-15])

Player status: 0-100: Map download progress: 256: map loaded

Returns the integer value of ID, IP string, port integer value, player name string, and status integer value.

When you create a host, your player name is the actual game name. When you enter another host, your player name is the "<yourself>" String

Get your game count: Game count = getgametimes ()

Get the loading status of your game: Game loading status = getgamestatus ()

0: not started 1: Start 5 seconds countdown 2: 5 seconds Countdown completed 3: game started

Status 3 is equivalent to isplaying () = 1

Number of remaining slots: number of remaining slots = gethostfreeslot ()

Returns the number of unsigned integers.

3) Assistant Information and functions:

Query assistant version: version = getwshscriptversion ()

The returned value is an unsigned integer.

Query assistant path: Assistant Path = getwshpath ()

The returned value is a path string.

Enablewshfunction)

Function No.: 0. Right-click the map area and choose "invalid". 1. Press the keyboard to change the key. 2. Mouse ing.

3-Allow keys to be changed in the combination key 4-press any key to reset the scroll wheel every time it is rolled

5-automatic switch to key change solution 6-shouting

7-Ctrl + right-click = right-click + Shift + H 8-Ctrl + left-click = A + left-click

9-Alt + [Q/W/A/S/Z/X] control package bar 10-Right-click = M + Shift + H

11-Alt + Num1 ~ Num0 replaces Alt + 1 ~ 0

12-show our blood records 13-show enemy blood records 14-shield Win key 15-shield Alt + Tab key

16-adjust the field of view [0: Restore 1: Near-1: far] 17-adjust the brightness [0: Restore 1: Dark-1: bright] 18-check and modify the key scheme 19-single choice to change the key Scheme

Enabled or not: 0-disabled 1-Enabled

Whether to enable the query assistant function: whether to enable = iswshfunctionenable)

Function No.: 0. Right-click the map area and choose "invalid". 1. Press the keyboard to change the key. 2. Mouse ing.

3-Allow keys to be changed in the combination key 4-press any key to reset the scroll wheel every time it is rolled

5-automatic switch to key change solution 6-shouting

7-Ctrl + right-click = right-click + Shift + H 8-Ctrl + left-click = A + left-click

9-Alt + [Q/W/A/S/Z/X] control package bar 10-Right-click = M + Shift + H

11-Alt + Num1 ~ Num0 replaces Alt + 1 ~ 0

12-show our blood records 13-show enemy blood records 14-shield Win key 15-shield Alt + Tab key

16-host Functions

Enabled or not: 0-disabled 1-Enabled

Get the current call scheme name: Name = getseltalkscheme ()

Returns a string.

Obtain the selected key change solution name: Name = getselkeyscheme ()

Returns a string.

Get the call solution list: Name = gettalkschemelist ()

Different solution names are separated by line breaks '\ N'

Get the key change solution list: Name = getkeyschemelist ()

Different solution names are separated by line breaks '\ N'

Get the content of the current call scheme: content = getseltalkwords ()

Returns the call string.

Obtain the content of the selected key change solution: content = getselkeymaps ()

Return key change solution content

Select the specified call plan: whether the call plan is successful = seltalkscheme ('scheme name ')

Returns 0 or 1.

Select the designated reconstruction scheme: whether the scheme is successfully = selkeyscheme ('scheme name', whether to select [1-select 0-not selected])

Returns 0 or 1.

Check whether the key change scheme is selected: Select = iskeyschemesel ('scheme name ')

Returns 0 or 1.

Execute the reconstruction sequence: Success = runkeys ('change key sequence ')

For example, runkeys ('use item I50I use item B60I DOTA near-wei base ')

The return value is 0 or 1. Successful or not only indicates whether the key sequence can be successfully modified, but not whether the simulated operation is successful or not.

Wait until the key change sequence is completed: waitrunkeysdone ()

Used with runkeys

In the AssistantLuaNote:

The Lua in the assistant provides some support and mechanisms, and some will be different from the original Lua. Therefore, pay special attention to the following issues during actual Script Creation or modification:

1) Simulated operations should not take long time-delay simulation operations as far as possible. Otherwise, the individual's game operation capability will plummet and may also cause great errors due to actual game conditions. For example, Zhuge wind E Sima Feng N script can only be used for playing and learning, and cannot be used in practice, because this long-delay simulation operation has a huge influence on the actual situation.

2) The timer or function script resident delay Program (Infinite Loop wile, repeat, etc.) cannot be in the same script as the mouse and mouse monitoring message monitoring function. The timer function or the script resident program and the mouse-and-mouse message monitoring function both start a separate thread, and the Lua script does not support multithreading. Therefore, these two types of functions may have the same resource problems, the script may crash. However, it is not recommended that the timer function and the script resident delay Program (Infinite Loop wile, repeat, etc.) be in a script, because if the first execution is the script resident delay program, timers outside the program will never be executed; a script can have multiple timers.

3) The Script resident delay program contains the loop delay operation. It can execute the program at the same time as the timer, but it is very different from the Timer: first, the script resident latency program can customize the first latency or the first program problem, while the timer itself is a fixed first latency program; second, the actual delay time of the script resident delayed program includes the actual time of program execution in addition to the specified delay time, and the timer will execute the program at a fixed time according to the set time, the execution frequency of the program segment is fixed. The two will be of different use because of these similarities and differences. The specific use depends on the actual needs of the program.

Summary:World of WarcraftSuper AssistantLua scriptAfter the introduction of the language content, 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.