> For the complete documentation index, see [llms.txt](https://docs.settlers-united.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.settlers-united.com/s4-lua-api-de/tutorials/advanced-tipps/externe-lua-skripte.md).

# Externe Lua Skripte

Skripte können direkt über den Editor in der Karte (**.map**-Datei) abgespeichert werden, haben dann jedoch eine **Zeichenlimitierung** von ca. **65.000 Zeichen**. Für wen das zu wenig ist:

**⇒** Externe Lua Skripts, die **umgehen** diese **Zeichenlimitierung**.

## Verwendung

#### ACHTUNG: jede/r Spieler/in muss das Skript manuell in den entsprechenden Ordner kopieren!

#### Gleicher Name, Script-Ordner - kein Problem

Das Spiel sucht automatisch bei Spielstart im Installationsordner von S4 unter `.\Script` nach einer **.txt**-Datei mit genau **demselben Namen wie die Karte** und lädt dieses Skript.\
Z.B. `C:\Program Files (x86)\Ubisoft\Ubisoft Game Launcher\games\thesettlers4\Script`.

#### Unterordner

Soll ein Skript aus einem expliziten **Unterordner** von `.\Script` wie z.B. `.\Script\User` verwendet werden, muss

```lua
$User\$
```

im Editor **als Karten-Skript** gesetzt werden, wobei "User" bereits **relativ zu ".\Script"** ist, auch mehrere Verschachtelungen sind möglich (`.\Script\User\sub1\sub2` etc.).

#### Skript-Name ≠ Karten-Name

Bei dem SU-Balancing-Modus **UBO-Test** können auch explizit Skripte geladen werden, indem direkt die **.txt**-Datei angegeben wird. Z.B. lädt

```lua
$User\myScript.txt$
```

als Karten-Skript direkt das Skript "myScript.txt" aus dem Ordner `.\thesettlers4\Script\User`,  egal wie die Karte heißt - praktisch für allgemeine Skripte.

#### Notizen

* $-Zeichen nicht vergessen!
* **Lua-Skripte** müssen die **Endung ".txt"** haben, **nicht** "~~.lua~~"!
* **Umlaute** werden nur richtig als Textnachricht im Chat ausgegeben (dbg.stm(), etc.), wenn die **.txt-Datei** als **"ISO 8859-1" kodiert** ist, siehe <https://php-de.github.io/jumpto/utf-8/> (in Notepad++ einzustellen unter "Codierung > Weitere Codepages > Westeuropäisch > ISO 8859-1").


---

# 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://docs.settlers-united.com/s4-lua-api-de/tutorials/advanced-tipps/externe-lua-skripte.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.
