Player.InitUnit (Civ5 API)

From Civilization Modding Wiki
Jump to navigationJump to search

This page is a part of the Lua and UI Reference (Civ5).


Function.png This function is a member of Player.

This is an instance method, invoke it with a colon.

Creates a new unit for the calling player. Note: Using this function in a map script may crash WorldBuilder.

Usage

Unit Player:InitUnit(UnitType unit, int x, int y, UnitAIType unitAI = NO_UNITAI, DirectionType facingDirection = NO_DIRECTION)

Returned Value

Returns a reference to the created unit.

Parameters

unit: The UnitType ID of the unit to be created.
x: The X coordinate on the map where the unit is to be created.
y: The Y coordinate on the map where the unit is to be created.
unitAI: Optional. The AI tactics for the unit to use upon being created. If not specified, it will be the default AI for this unit type.
facingDirection: Optional. The direction for the newly created unit to be facing. If not specified, it will be random.


Source code samples

Too many occurences. Only 50 out of 350 are listed.

TurnsRemaining.lua - DLC_02 DLC

DLC/DLC_02/Scenarios/NewWorldScenario/TurnsRemaining.lua
0338
unit = pLoopPlayer:InitUnit (iUnitID, pLoopPlayer:GetStartingPlot():GetX(), pLoopPlayer:GetStartingPlot():GetY());
0413
pPlayer:InitUnit (iUnitID, adjacentPlot:GetX(), adjacentPlot:GetY());


TurnsRemaining.lua - DLC_04 DLC

DLC/DLC_04/Scenarios/1066Scenario/TurnsRemaining.lua
0515
unit = player:InitUnit (iUnitID, playerStartPlot:GetX(), playerStartPlot:GetY(), UNITAI_DEFENSE, DirectionTypes.DIRECTION_WEST);
0545
unit = player:InitUnit (iUnitID, 36, 6, UNITAI_DEFENSE, DirectionTypes.DIRECTION_WEST);
0549
unit = player:InitUnit (iUnitID, 37, 6, UNITAI_DEFENSE, DirectionTypes.DIRECTION_WEST);
0553
unit = player:InitUnit (iUnitID, 38, 6, UNITAI_DEFENSE, DirectionTypes.DIRECTION_WEST);
0561
unit = player:InitUnit (iUnitID, 40, 6, UNITAI_DEFENSE, DirectionTypes.DIRECTION_WEST);
0599
unit = player:InitUnit (iUnitID, 52, 21, UNITAI_DEFENSE, DirectionTypes.DIRECTION_WEST);
0607
unit = player:InitUnit (iUnitID, 51, 19, UNITAI_DEFENSE, DirectionTypes.DIRECTION_WEST);
0615
unit = player:InitUnit (iUnitID, 52, 19, UNITAI_RANGED, DirectionTypes.DIRECTION_WEST);
0623
unit = player:InitUnit (iUnitID, 53, 21, UNITAI_RANGED, DirectionTypes.DIRECTION_WEST);
0653
unit = player:InitUnit (iUnitID, 31, 34, UNITAI_DEFENSE, DirectionTypes.DIRECTION_WEST);
0665
unit = player:InitUnit (iUnitID, 29, 33, UNITAI_RANGED, DirectionTypes.DIRECTION_WEST);
0669
unit = player:InitUnit (iUnitID, 30, 34, UNITAI_RANGED, DirectionTypes.DIRECTION_WEST);
0693
unit = player:InitUnit (iUnitID, 50, 11, UNITAI_DEFENSE, DirectionTypes.DIRECTION_WEST);
0701
unit = player:InitUnit (iUnitID, 51, 13, UNITAI_DEFENSE, DirectionTypes.DIRECTION_WEST);
0713
unit = player:InitUnit (iUnitID, 51, 11, UNITAI_RANGED, DirectionTypes.DIRECTION_WEST);


TurnsRemaining.lua (G&K)

DLC/Expansion/Scenarios/SteampunkScenario/TurnsRemaining.lua
0850
local pUnit = pPlayer:InitUnit(eUnitType, pPlot:GetX(), pPlot:GetY());


TurnsRemaining.lua (G&K)

DLC/Expansion/Scenarios/FallOfRomeScenario/TurnsRemaining.lua
0378
unit = newPlayer:InitUnit(iUnitID, iX, iY);
1309
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_ROMAN_LEGION"], 20, 47); -- Legion @ Lutetia
1323
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_ROMAN_BALLISTA"], 26, 49); -- Ballista @ Trier
1330
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_HORSEMAN"], 22, 42); -- Horseman @ Lugundium
1344
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_COMPOSITE_BOWMAN"], 49, 34); -- Archer @ Naissus
1346
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_COMPOSITE_BOWMAN"], 75, 26); -- Archer @ Melitene
1352
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_CATAPULT"], 76, 21); -- Catapult @ Edessa
1358
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_ROMAN_LEGION"], 76, 21); -- Legion @ Edessa
1369
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_BYZANTINE_CATAPHRACT"], 49, 34); -- Cataphract @ Naissus
1371
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_BYZANTINE_CATAPHRACT"], 71, 30); -- Cataphract @ Amasia
1388
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_SWORDSMAN"], 81, 33); -- Swordsman @ Anium
1413
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_SWORDSMAN"], 79, 24); -- Swordsman @ Amida
1432
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_HORSEMAN"], 84, 58); -- Horseman @ Attila's Court -- extra to encourage an attack
1442
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_HUN_HORSE_ARCHER"], 84, 58); -- Horse archer @ Attila's Court
1448
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_HUN_BATTERING_RAM"], 84, 58); -- battering ram! @ Attila's Court
1476
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_COMPOSITE_BOWMAN"], 17, 57); -- Bowman @ mid-country
1480
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_CATAPULT"], 17, 57); -- Catapult @ mid-country
1528
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_COMPOSITE_BOWMAN"], 32, 54); -- Bowman @ Tongres
1556
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_GOTH_GADRAUHT"], 50, 37); -- Gadrauht @ ERE border
1586
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_COMPOSITE_BOWMAN"], 4, 19); -- Bowman @ Caput Vada -- added to get army up to city-attacking size
1592
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_CARTHAGINIAN_QUINQUEREME"], 4, 19); -- Tri @ Caput Vada
1594
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_VANDAL_AXEMAN"], 4, 19); -- Axeman @ Caput Vada
1600
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_CATAPULT"], 4, 19); -- Catapult @ Caput Vada
1816
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_CATAPULT"], iSpawnX, iSpawnY);
1819
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_COMPOSITE_BOWMAN"], iSpawnX, iSpawnY);
2018
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_CELT_PICTISH_WARRIOR"], iSpawnX, iSpawnY);
2108
unit = pPlayer:InitUnit(GameInfoTypes["UNIT_FRANK_SEAXMAN"], iSpawnX, iSpawnY);


TurnsRemaining.lua (G&K)

DLC/Expansion/Scenarios/MedievalScenario/TurnsRemaining.lua
1064
unit = pPlayer:InitUnit (iUnitID, capital:GetX(), capital:GetY(), UNITAI_DEFENSE, DirectionTypes.DIRECTION_EAST);
1276
unit = pPlayer:InitUnit (iUnitID, capital:GetX(), capital:GetY(), UNITAI_WORKER, DirectionTypes.DIRECTION_WEST);
1300
unit = pPlayer:InitUnit (iUnitID, capital:GetX(), capital:GetY(), UNITAI_GENERAL, DirectionTypes.DIRECTION_WEST);
1612
unit = pPlayer:InitUnit (iUnitID, capital:GetX(), capital:GetY(), UNITAI_SETTLE, DirectionTypes.DIRECTION_EAST);


WorldView.lua

UI/InGame/WorldView/WorldView.lua
0264
pActivePlayer:InitUnit(iUnitID, plotX, plotY);



The initial version of this page was created by the Civ5 API Bot, see the Civ5 API Reference FAQ. Some of the texts come from the 2kgames' wiki and most of code samples are copyrighted to Firaxis.
Functions' signatures were either copied from the 2kgames' wiki, or infered from the Lua source files and the binaries. Errors are possible.
Contributors may find help in the Contributors guide to the Civ5 API.