> 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/library-functions/global-functions/new_game.md).

# new\_game

## `new_game()`

Dies ist der Einstiegspunkt, der von einer Karte aufgerufen wird. Schon bevor das Spiel seinen ersten Tick durchlaufen hat, wird diese Funktion aufgerufen. Normalerweise werden in dieser Funktion Sachen festgelegt, die schon am Spielbeginn feststehen. Dies beinhaltet zum Beispiel festgelegte Objekte die platziert werden oder die Kampfkraft einer Partei. Auch werden hier Events angemeldet.

#### Rückgabewert

Da diese Funktion selbst geschrieben wird und vom Spiel intern aufgerufen wird, hat diese Funktion keinen Rückgabewert

#### Beispiel

```lua
----
-- Script von "Wacah Chan"
----
function new_game()

--//Anfang Spielereinstellungen//--

     --//Angriffsmodi//--
     AI.SetPlayerVar(2,"AttackMode",1,2,2)
     AI.SetPlayerVar(3,"AttackMode",1,2,2)
   
     --//Angriffsfolge//--
     AI.SetPlayerVar(2,"AttackDelay",50,40,90)
     AI.SetPlayerVar(3,"AttackDelay",60,30,90)

     --//Soldatenanzahl//--
     AI.SetPlayerVar(2,"SoldierLimitAbsolute",150,300,1000)
     AI.SetPlayerVar(2,"SoldierLimitRelative",75,250,700)

     AI.SetPlayerVar(3,"SoldierLimitAbsolute",150,300,1000)
     AI.SetPlayerVar(3,"SoldierLimitRelative",75,250,700)

--//Ende Spielereinstellungen//--


--registriere Funktion VictoryConditionCheck als Siegesbedingungscheck
  request_event(VictoryConditionCheck, Events.VICTORY_CONDITION_CHECK)
end

function register_functions()
--registriere VictoryConditionCheck als Funktion, die in mind. einem Event vorkommt
  reg_func(VictoryConditionCheck)
end

function VictoryConditionCheck()
  -- Prüfe ob durch Standartregeln ein Spieler verloren hat
  Game.DefaultPlayersLostCheck()
 
  -- wenn Spieler 2 und 3 Veloren haben und Spieler 1 noch im Spiel ist, verlieren alle Gegner von 1
  if Game.HasPlayerLost(1) == 0
  and Game.HasPlayerLost(2) == 1
  and Game.HasPlayerLost(3) == 1
  then
    Game.EnemyPlayersLost(1)
  end
 
  -- Notwendig, damit die Nachrichten wie "Sie haben Gewonnen" erscheinen
  Game.DefaultGameEndCheck()
endlu
```


---

# 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/library-functions/global-functions/new_game.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.
