Craig_Sutter
Deity
I am trying to get a city able to train a specific unit if the city has a palace or a specific building (Burgh Court) and the number of units is less than the number Burgh Courts plus the palace. Later I will add more units and civilizations with or statements added to the parts outlined in green...
In testing, when I get to the build screen, no units show up at all. Something is not working with my logic, but I can't figure it out.
I think I am close, but no cigar.
Thanks for advice.
PS My newest try came with similar results... must be using faulty logic...
Another attempt, but this time I can build a unit... but no restrictions on numbers.
In testing, when I get to the build screen, no units show up at all. Something is not working with my logic, but I can't figure it out.
Code:
--allows Northumbria to build anglo-saxon units equal to its number of Burgh Court plus one for the capital
function NorthumbriaUnit (iPlayer, iCity, iUnit)
local ASunit = false
local ASciv = false
local iCeorl = GameInfoTypes.UNIT_CEORL
local iBuilding = GameInfoTypes.BUILDING_BURGH_COURT
local iPalace = GameInfoTypes.BUILDING_PALACE
local player = Players[iPlayer]
local city = player:GetCityByID(iCity);
-- determine if unit is Anglo-Saxon
[COLOR="SeaGreen"]if iUnit == iCeorl then[/COLOR]
ASunit = true
end
-- determine if civ is Anglo-Saxon
[COLOR="SeaGreen"]if iPlayer == GameInfoTypes.CIVILIZATION_RUSSIA then[/COLOR]
ASciv = true
end
-- check for unit, civ and building
if ASunit and ASciv and city:IsHasBuilding(iBuilding) or ASunit and ASciv and city:IsHasBuilding(iPalace) then
local BuildingCount = 0
for pCity in player:Cities() do
if pCity:IsHasBuilding(iBuilding) then
BuildingCount = BuildingCount + 1
end
end
return (BuildingCount+1 > player:GetUnitClassCount(iCeorl))
else
return false
end
return true
end
GameEvents.CityCanTrain.Add(NorthumbriaUnit)
I think I am close, but no cigar.
Thanks for advice.
PS My newest try came with similar results... must be using faulty logic...
Code:
--allows Northumbria to build anglo-saxon units equal to its number of Burgh Courts plus one for the capital
function NorthumbriaUnit (iPlayer, iCity, iUnit)
local iCeorl = GameInfoTypes.UNIT_CEORL
local iBuilding = GameInfoTypes.BUILDING_BURGH_COURT
local iPalace = GameInfoTypes.BUILDING_PALACE
local iNorthumbria = GameInfoTypes.CIVILIZATION_RUSSIA
local player = Players[iPlayer]
local city = player:GetCityByID(iCity);
-- determine if unit is Anglo-Saxon
if iUnit == iCeorl and iPlayer == iNorthumbria and city:IsHasBuilding(iBuilding) or
iUnit == iCeorl and iPlayer == iNorthumbria and city:IsHasBuilding(iPalace) then
local BuildingCount = 0
for pCity in player:Cities() do
if pCity:IsHasBuilding(iBuilding) then
BuildingCount = BuildingCount + 1
end
end
return (BuildingCount+1 > player:GetUnitClassCount(iCeorl))
else
return false
end
return true
end
GameEvents.CityCanTrain.Add(NorthumbriaUnit)
Another attempt, but this time I can build a unit... but no restrictions on numbers.

Code:
--allows Northumbria to build anglo-saxon units equal to its number of Burgh Courst plus one for the capital
function NorthumbriaUnit (iPlayer, iCity, iUnit)
local iCeorl = GameInfoTypes.UNIT_CEORL
local iBuilding = GameInfoTypes.BUILDING_BURGH_COURT
local iPalace = GameInfoTypes.BUILDING_PALACE
local iNorthumbria = GameInfoTypes.CIVILIZATION_RUSSIA
local player = Players[iPlayer]
local city = player:GetCityByID(iCity);
-- determine if unit is Anglo-Saxon
if iUnit == iCeorl and iPlayer == iNorthumbria and city:IsHasBuilding(iBuilding) or
iUnit == iCeorl and iPlayer == iNorthumbria and city:IsHasBuilding(iPalace) then
local BuildingCount = 0
for pCity in player:Cities() do
if pCity:IsHasBuilding(iBuilding) then
BuildingCount = BuildingCount + 1
end
end
if (BuildingCount+1 > player:GetUnitClassCount(iCeorl)) then
return true
else
return false
end
end
return true
end
GameEvents.CityCanTrain.Add(NorthumbriaUnit)