Generated Maps:Manually Placing Player Starts

From Age of Empires 4 Modding
Revision as of 13:48, 17 June 2022 by Drumsin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Return to Generated Maps - Home


Apart from the default functions described in the official documentation and generated map template, you can also place players completely manually.

To take teams into account, setup the team mapping table to know which player belongs to which team. The following is an example of placing team members on the same row next to each other, with one row per team. Critically, note how playerIndex works differently from playerID!

teamMappingTable = CreateTeamMappingTable()

for teamNum = 1, #teamMappingTable do
	for i = 1, #teamMappingTable[teamNum].players do
		-- IMPORTANT: playerIndex counts from 0, but playerID counts from 1. If you omit the "-1" here, the map will crash.
		terrainLayoutResult[teamNum][i].playerIndex = teamMappingTable[teamNum].players[i].playerID - 1
	end
end

For example, with the following setup in the game lobby:

LobbyTeamSetup.png

The code above results in this start:

GameTeamSetup.png

If you do not care about teams when placing players, a simpler way is to use worldPlayerCount directly. In the following example, we place all players on the first row next to each other.

-- IMPORTANT: Start this loop from 0, not 1!
for i = 0, worldPlayerCount - 1 do
	terrainLayoutResult[1][i + 1].playerIndex = i
end

When placing players manually without using the default helper functions, the game does not automatically add starting resources at player locations, so it is generally recommended to place one of the tt_player_start terrain types at the same coordinates:

-- ... some logic to determine row,col for player starts ...
terrainLayoutResult[row][col].playerIndex = i
terrainLayoutResult[row][col].terrainType =	tt_player_start_classic_plains