Cool thank you for the reply chillbaka. I considered the new promotion class, but was afraid of any unwanted consequences. I went ahead and made a dummy building which is automatically built in human player cities, which allows for the creation of the unit. Your route might have been more elegant, and simpler, but I got the building and lua functionality fleshed out in about 45 mins so it wasn't too bad.
The unit is used to transfer population from one city to another. It reduces the population of the city it is produced in, and once you move it to another city that you own it is removed from the game and that city's pop is increased by 1.
But how did you add it to the other city?PopulationCost="1"
Just that one declaration when you set up your unit is all it takes =).
local iCitizen = GameInfo.Units["UNIT_CITIZEN"].Index;
function OnUnitMoveComplete(iPlayer, iunitID, iPlotX, iPlotY)
local pPlayer = Players[iPlayer];
local pPlayerUnits = pPlayer:GetUnits();
local pUnit = pPlayerUnits:FindID(iunitID);
if (pUnit:GetType() == iCitizen) then
local plot = Map.GetPlot(iPlotX, iPlotY);
local isCity = plot:IsCity();
if (isCity) then
local iPlotOwner = plot:GetOwner();
if (iPlotOwner == iPlayer) then
--destroys unit
pPlayerUnits:Destroy(pUnit);
--increase city population by 1
local pCity :table = Cities.GetCityInPlot(iPlotX,iPlotY);
pCity:ChangePopulation(1);
end
end
end
end
Events.UnitMoveComplete.Add(OnUnitMoveComplete);
Code:local iCitizen = GameInfo.Units["UNIT_CITIZEN"].Index; function OnUnitMoveComplete(iPlayer, iunitID, iPlotX, iPlotY) local pPlayer = Players[iPlayer]; local pPlayerUnits = pPlayer:GetUnits(); local pUnit = pPlayerUnits:FindID(iunitID); if (pUnit:GetType() == iCitizen) then local plot = Map.GetPlot(iPlotX, iPlotY); local isCity = plot:IsCity(); if (isCity) then local iPlotOwner = plot:GetOwner(); if (iPlotOwner == iPlayer) then --destroys unit pPlayerUnits:Destroy(pUnit); --increase city population by 1 local pCity :table = Cities.GetCityInPlot(iPlotX,iPlotY); pCity:ChangePopulation(1); end end end end Events.UnitMoveComplete.Add(OnUnitMoveComplete);
What it does: When a player moves a citizen unit to a city tile owned by that player, it will remove that unit from the game and increase the population of that city by 1.
Its just a document like .xml or .sql, but with the .lua extension. Id suggest just downloading any lua mod and digging around in it. My "strategic forts" mod on steam is primarily lua, feel free to use it as a learning tool
CREATE TABLE tblQuoBiomeEastEuropeSupportUnits AS
select unittype, technologies.eratype from units
inner join technologies on technologies.TechnologyType = units.PrereqTech
where promotionclass in ("PROMOTION_CLASS_SUPPORT") AND TraitType IS NULL
union
select unittype, civics.EraType from units
inner join civics on civics.CivicType = units.PrereqCivic
where promotionclass in ("PROMOTION_CLASS_SUPPORT") AND TraitType IS NULL;
INSERT INTO Modifiers
(ModifierId, ModifierType, RunOnce, Permanent, OwnerRequirementSetId, SubjectRequirementSetId)
SELECT 'QUO_BIOME_EAST_EUROPE_CANNOT_BUILD_' || tblQuoBiomeEastEuropeSupportUnits.UnitType, 'MODIFIER_PLAYER_UNIT_BUILD_DISABLED', 0, 0, NULL, NULL
FROM tblQuoBiomeEastEuropeSupportUnits;
INSERT INTO ModifierArguments
(ModifierId, Name, Type, Value, Extra, SecondExtra)
SELECT 'QUO_BIOME_EAST_EUROPE_CANNOT_BUILD_' || tblQuoBiomeEastEuropeSupportUnits.UnitType, 'UnitType', 'ARGTYPE_IDENTITY', tblQuoBiomeEastEuropeSupportUnits.UnitType, NULL, NULL
FROM tblQuoBiomeEastEuropeSupportUnits;
INSERT INTO TraitModifiers
(TraitType, ModifierID)
SELECT 'QUO_TRAIT_BIOME_EAST_EUROPE', 'QUO_BIOME_EAST_EUROPE_CANNOT_BUILD_' || tblQuoBiomeEastEuropeSupportUnits.UnitType
FROM tblQuoBiomeEastEuropeSupportUnits;
In Rise and Fall there is a Modifier that allows you to block the building of a particular unit entirely. Here's an example where one of the "Biomes" in my Combined Tweaks mod is blocked from building Support units:
Code:CREATE TABLE tblQuoBiomeEastEuropeSupportUnits AS select unittype, technologies.eratype from units inner join technologies on technologies.TechnologyType = units.PrereqTech where promotionclass in ("PROMOTION_CLASS_SUPPORT") AND TraitType IS NULL union select unittype, civics.EraType from units inner join civics on civics.CivicType = units.PrereqCivic where promotionclass in ("PROMOTION_CLASS_SUPPORT") AND TraitType IS NULL; INSERT INTO Modifiers (ModifierId, ModifierType, RunOnce, Permanent, OwnerRequirementSetId, SubjectRequirementSetId) SELECT 'QUO_BIOME_EAST_EUROPE_CANNOT_BUILD_' || tblQuoBiomeEastEuropeSupportUnits.UnitType, 'MODIFIER_PLAYER_UNIT_BUILD_DISABLED', 0, 0, NULL, NULL FROM tblQuoBiomeEastEuropeSupportUnits; INSERT INTO ModifierArguments (ModifierId, Name, Type, Value, Extra, SecondExtra) SELECT 'QUO_BIOME_EAST_EUROPE_CANNOT_BUILD_' || tblQuoBiomeEastEuropeSupportUnits.UnitType, 'UnitType', 'ARGTYPE_IDENTITY', tblQuoBiomeEastEuropeSupportUnits.UnitType, NULL, NULL FROM tblQuoBiomeEastEuropeSupportUnits; INSERT INTO TraitModifiers (TraitType, ModifierID) SELECT 'QUO_TRAIT_BIOME_EAST_EUROPE', 'QUO_BIOME_EAST_EUROPE_CANNOT_BUILD_' || tblQuoBiomeEastEuropeSupportUnits.UnitType FROM tblQuoBiomeEastEuropeSupportUnits;
This code does a few things:
- Creates a table containing a list of all units to affect (tblQuoBiomeEastEuropeSupportUnits). In this case, it's any unit that is a Support Unit. (Note that this code also contains joins to eras, so if we wanted to block all units of a certain era we could do that).
- Use the data in the temporary table created in the step above to creates a 'MODIFIER_PLAYER_UNIT_BUILD_DISABLED Modifier for each unit listed in that table, with an appropriate ModifierArgument.
- Applies these Modifiers to the Trait.
If you want to block the AI from ever building a particular unit, just use code similar to above (with your own custom table name) and populate that table with whatever units you want to block out. Then make sure on the Modifier that you have attach a RequirementSet that checks to see that the player is AI. You can use whatever means to populate your table that you want (e.g. you could directly INSERT into your temporary table, or you could do a SELECT query like the example above to pick out records based on a certain characteristic, e.g. EraType, PromotionClass, etc.