I am trying to add in a Lua script where a player selects a unit "Draft A Unit" for production, and it produces one of three units at random. It is my first time trying to add in any Lua and have been using some references on these boards (http://forums.civfanatics.com/showthread.php?t=526843). I have the code below, while changing a couple of keywords. How do I have this code work for all Civilizations and not just a specified one? Would I just delete the "if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_CANADIENS"] then" and have it go into the next if statement "local unit = Players[playerID]:GetUnitByID(unitID)"?
Spoiler :
function Unit_Draft(playerID, unitID, hexVec, unitType, cultureType, civID, primaryColor, secondaryColor, unitFlagIndex, fogState, selected, military, notInvisible)
local player = Players[playerID]
local unit = player:GetUnitByID(unitID)
if(player == nil or
unit == nil or
unit:IsDead()) then
return
end
--------------
-- Choose Random Drafted Unit
--------------
if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_CANADIENS"] then
local unit = Players[playerID]:GetUnitByID(unitID)
if unit:GetUnitType() == GameInfoTypes["UNIT_DRAFT_A_UNIT"] then
local spawn = { "UNIT_SNIPER", "UNIT_PLAYMAKER", "UNIT_GRINDER" }
local unitRnd = player:InitUnit(GameInfo.Units[spawn[math.random(#spawn)]].ID, unit:GetX(), unit:GetY())
unitRnd:Convert(unit)
end
end
end
Events.SerialEventUnitCreated.Add(Unit_Draft)
local player = Players[playerID]
local unit = player:GetUnitByID(unitID)
if(player == nil or
unit == nil or
unit:IsDead()) then
return
end
--------------
-- Choose Random Drafted Unit
--------------
if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_CANADIENS"] then
local unit = Players[playerID]:GetUnitByID(unitID)
if unit:GetUnitType() == GameInfoTypes["UNIT_DRAFT_A_UNIT"] then
local spawn = { "UNIT_SNIPER", "UNIT_PLAYMAKER", "UNIT_GRINDER" }
local unitRnd = player:InitUnit(GameInfo.Units[spawn[math.random(#spawn)]].ID, unit:GetX(), unit:GetY())
unitRnd:Convert(unit)
end
end
end
Events.SerialEventUnitCreated.Add(Unit_Draft)