> For the complete documentation index, see [llms.txt](https://tutorials.wow-jack.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tutorials.wow-jack.com/event-manager/events/execute-lua.md).

# 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="/files/gbRQPiCTBO9fXHKZzSGO" 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="/files/Z6C6Ll1WIdiY2VSYxvJc" 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="/files/N3J65PdLfE8UVEtrX0gm" 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="/files/r1mnVmZmAj9KoOi0hOcb" 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="/files/ExZpXURRVX0WPulQSGlX" 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 %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://tutorials.wow-jack.com/event-manager/events/execute-lua.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
