# Execute LUA

{% hint style="info" %}
Use this event if you want to execute one or more LUA commands.
{% endhint %}

{% hint style="success" %}
You can combine [official LUA commands](#official-commands) with [custom LUA commands](#custom-commands) (line by line).
{% endhint %}

## Index

1. [Official Commands](#official-commands)
2. [Custom Commands](#custom-commands)

***

## Official Commands

{% hint style="info" %}
The official WoW LUA API comes with a bunch of commands and functions that anyone can access and use.

[Here you can find a clear list.](https://wowpedia.fandom.com/wiki/World_of_Warcraft_API)
{% endhint %}

{% hint style="info" %}
These commands have different execution levels. Most can be executed individually or in combination directly. Others require a hardware event and can only be executed with a mouse click or key press.
{% endhint %}

* Copy the following command into the LUA event text field.

```
print("My name is "..UnitName("player")..".")
```

<div align="left"><figure><img src="https://content.gitbook.com/content/Ru6xdzQbPbHLSP4OmeYT/blobs/DlQO6WRB56xzHl68V0hs/execute-lua-04.png" alt=""><figcaption></figcaption></figure></div>

* Click on the "Test" button to test the command.
* The output in your in-game chat should look like this:

<div align="left"><figure><img src="https://content.gitbook.com/content/Ru6xdzQbPbHLSP4OmeYT/blobs/O3qeqBHtt6kVb34sX3L6/execute-lua-05.png" alt=""><figcaption></figcaption></figure></div>

Since this command doesn't really give us anything, we'll build ourselves a little conditional query to check if we have a Hearthstone in our bags:

```
if GetItemCount(6948) == 1 then
    print("Yay, i have a Hearthstone in my bag.")
else
    print("I have no Hearthstone in my bag ;(")
end
```

<div align="left"><figure><img src="https://content.gitbook.com/content/Ru6xdzQbPbHLSP4OmeYT/blobs/5mgqLIXnsNKDbwchwiwi/execute-lua-06.png" alt=""><figcaption></figcaption></figure></div>

Also possible as a function:

```
function CheckMyHearthstone()
    if GetItemCount(6948) >= 1 then
        print("Yay, i have a Hearthstone in my bag.")
    else
        print("I have no Hearthstone in my bag ;(")
    end
end

CheckMyHearthstone()
```

{% hint style="info" %}
If a function is passed, it remains until the next reload of the game.
{% endhint %}

Alternatively, we can trigger commands or a conditional query as a Key Press event by placing a <mark style="color:yellow;">**/run**</mark> in front of it.

```
/run print("My name is "..UnitName("player")..".")
```

Enter commands line by line if you want to execute several in a row:

```
/run print("My name is "..UnitName("player")..".")
/dance
```

***

## Custom Commands

* Click on "Show custom commands" to display a list and descriptions of all custom commands.

{% hint style="info" %}
To explain the structure, we click on the "WaitForNPC" command on the left.
{% endhint %}

<figure><img src="https://content.gitbook.com/content/Ru6xdzQbPbHLSP4OmeYT/blobs/vnvPIIr5WGAf8tnrxM5b/execute-lua-02.png" alt=""><figcaption></figcaption></figure>

1. Name of the command.
2. Duty Argument.
3. Optional arguments.

<pre><code><strong>WaitForNPC("NameOrID" [, "MaximumWaitTime", "DistanceInYards", "DeadOrAlive"])
</strong></code></pre>

{% hint style="info" %}
All arguments in square brackets are optional.
{% endhint %}

<figure><img src="https://content.gitbook.com/content/Ru6xdzQbPbHLSP4OmeYT/blobs/lmXbWNqWKa6xCMWNZfgs/execute-lua-03.png" alt=""><figcaption></figcaption></figure>

1. Description of the command and what it does.
2. Description of all arguments and what influence they can have.
3. Example(s) of correct execution of the command.

{% hint style="info" %}
We have here a command with 4 arguments. One mandatory and three optional.

First we look for the name or ID of the NPC we want to wait for. We simply take the ID "12345" as an example.
{% endhint %}

The simplest execution of the command would now look like this:

```
WaitForNPC("12345")
```

If we now want to change the maximum waiting time, we extend the command and specify a waiting time of 30 seconds:

```
WaitForNPC("12345", "30")
```

We would now like to extend the maximum search radius to 60 yards:

```
WaitForNPC("12345", "30", "60")
```

If we assume that we are looking for a dead target, we set the DeadOrAlive argument to "0":

```
WaitForNPC("12345", "30", "60", "0")
```

{% hint style="warning" %}
Custom LUA commands cannot be tested.
{% endhint %}
