Building completion that automatically creates a Unit

Moyomi

Chieftain
Joined
Mar 23, 2017
Messages
5
So I wanted to make it so whenever I complete a Monument, a unit is automatically created in the city.

I know that can be easily done with LUA, but I'm illiterate towards it, so I'm wondering if there's any way to through XML?
 
There is a way to do it, but you'll need to create a Dummy Building, and use the Modifier "MODIFIER_PLAYER_SINGLE_CITY_GRANT_UNIT" or something similar to that.

I did a similar thing where I wanted to generate a great person upon creating a district. Scroll down this previous page until you find the topic 'Really Stuck on a Civ Trait!' Another forum member assisted me by creating the dummy building. Perhaps you could use this as guide to help you. It should be the same principal in practice.
 
@Moyomi

Hey, I know you asked for advice, not for a solution, but it was easier for me to simply adapt the code I already had for another purpose. The SQL statements below yield XML code that:

- grants 1 UNIT_WARRIOR in any of CIVILIZATION_EGYPT's cities that build (buy) a BUILDING_MONUMENT
You can change all of these values (unit type, number of units, civilization, building) by going through the code. It's pretty easy to parse through it once you get the hang of it. To use this code, you can insert into any of you current SQL-based mods, or, if you need help, let me know, and I'll put together a mod for you. This solution does not rely on or require any dummy buildings, clean and neat.

I did not include any additional requirement (e.g. technology requirements), but you may wish to. Good luck!

Code:
-- UNIT GENERATION TRAIT
-- (1) Required Building - BUILDING_MONUMENT -- Change as desired
-- (2) Civilization - CIVILIZATION_EGYPT - Change as desired
-- (3) UnitType - Set to UNIT_WARRIOR
-- (4) Number of Units - Set to 1
-- (5) No other requirements (e.g. no Technology Requirements), but can be added as desired

INSERT INTO Types (Type, Kind) VALUES
('MODIFIER_PLAYER_CITIES_GRANT_UNIT_IN_CITY_ON_REQUIREMENTS', 'KIND_MODIFIER'),
('TRAIT_GRANTING_UNIT_IN_QUALIFIED_CITY', 'KIND_TRAIT');

INSERT INTO DynamicModifiers (ModifierType, CollectionType, EffectType) VALUES
('MODIFIER_PLAYER_CITIES_GRANT_UNIT_IN_CITY_ON_REQUIREMENTS', 'COLLECTION_PLAYER_CITIES', 'EFFECT_GRANT_UNIT_IN_CITY');

INSERT INTO Traits (TraitType, Name, Description) VALUES
('TRAIT_GRANTING_UNIT_IN_QUALIFIED_CITY', 'LOC_TRAIT_GRANTING_UNIT_IN_QUALIFIED_CITY_NAME', 'LOC_TRAIT_GRANTING_UNIT_IN_QUALIFIED_CITY_DESCRIPTION');

INSERT INTO CivilizationTraits (CivilizationType, TraitType) VALUES
('CIVILIZATION_EGYPT', 'TRAIT_GRANTING_UNIT_IN_QUALIFIED_CITY');

INSERT INTO TraitModifiers (TraitType, ModifierId) VALUES
('TRAIT_GRANTING_UNIT_IN_QUALIFIED_CITY', 'GRANTING_UNIT_IN_QUALIFIED_CITY_MODIFIER');

INSERT INTO Modifiers (ModifierId, ModifierType, RunOnce, Permanent, OwnerRequirementSetId, SubjectRequirementSetId) VALUES
('GRANTING_UNIT_IN_QUALIFIED_CITY_MODIFIER', 'MODIFIER_PLAYER_CITIES_GRANT_UNIT_IN_CITY_ON_REQUIREMENTS', 0, 1, NULL, 'CITY_HAS_MONUMENT_REQUIREMENTS');

INSERT INTO ModifierArguments (ModifierId, Name, Type, Value, Extra, SecondExtra) VALUES
('GRANTING_UNIT_IN_QUALIFIED_CITY_MODIFIER', 'UnitType', 'ARGTYPE_IDENTITY', 'UNIT_WARRIOR', NULL, NULL),
('GRANTING_UNIT_IN_QUALIFIED_CITY_MODIFIER', 'Amount', 'ARGTYPE_IDENTITY', '1', NULL, NULL);

INSERT INTO RequirementSets (RequirementSetId, RequirementSetType) VALUES
('CITY_HAS_MONUMENT_REQUIREMENTS', 'REQUIREMENTSET_TEST_ALL');

INSERT INTO RequirementSetRequirements (RequirementSetId, RequirementId) VALUES
('CITY_HAS_MONUMENT_REQUIREMENTS', 'REQUIRES_CITY_HAS_MONUMENT');

INSERT INTO Requirements (RequirementId, RequirementType) VALUES
('REQUIRES_CITY_HAS_MONUMENT', 'REQUIREMENT_CITY_HAS_BUILDING');

INSERT INTO RequirementArguments (RequirementId, Name, Type, Value, Extra, SecondExtra) VALUES
('REQUIRES_CITY_HAS_MONUMENT', 'BuildingType', 'ARGTYPE_IDENTITY', 'BUILDING_MONUMENT', NULL, NULL);
 
Also, I am not sure whether you need this for a mod, or just to supplement your own game, whenever you are playing as any civilization, but deny this ability to the AI. If it's the latter, as a kind of leg-up for you as the human player, use the following code instead. This way, this ability will follow you whatever civilization you play. In this variation, the Modifier is attached to TRAIT_LEADER_MAJOR_CIV (which means any civilization you may wish to play) and is restricted to human player only.

Code:
INSERT INTO Types (Type, Kind) VALUES
('MODIFIER_PLAYER_CITIES_GRANT_UNIT_IN_CITY_ON_REQUIREMENTS', 'KIND_MODIFIER');

INSERT INTO DynamicModifiers (ModifierType, CollectionType, EffectType) VALUES
('MODIFIER_PLAYER_CITIES_GRANT_UNIT_IN_CITY_ON_REQUIREMENTS', 'COLLECTION_PLAYER_CITIES', 'EFFECT_GRANT_UNIT_IN_CITY');

INSERT INTO TraitModifiers (TraitType, ModifierId) VALUES
('TRAIT_LEADER_MAJOR_CIV', 'GRANTING_UNIT_IN_QUALIFIED_CITY_MODIFIER');

INSERT INTO Modifiers (ModifierId, ModifierType, RunOnce, Permanent, OwnerRequirementSetId, SubjectRequirementSetId) VALUES
('GRANTING_UNIT_IN_QUALIFIED_CITY_MODIFIER', 'MODIFIER_PLAYER_CITIES_GRANT_UNIT_IN_CITY_ON_REQUIREMENTS', 0, 1, 'PLAYER_IS_HUMAN', 'CITY_HAS_MONUMENT_REQUIREMENTS');

INSERT INTO ModifierArguments (ModifierId, Name, Type, Value, Extra, SecondExtra) VALUES
('GRANTING_UNIT_IN_QUALIFIED_CITY_MODIFIER', 'UnitType', 'ARGTYPE_IDENTITY', 'UNIT_WARRIOR', NULL, NULL),
('GRANTING_UNIT_IN_QUALIFIED_CITY_MODIFIER', 'Amount', 'ARGTYPE_IDENTITY', '1', NULL, NULL);

INSERT INTO RequirementSets (RequirementSetId, RequirementSetType) VALUES
('CITY_HAS_MONUMENT_REQUIREMENTS', 'REQUIREMENTSET_TEST_ALL');

INSERT INTO RequirementSetRequirements (RequirementSetId, RequirementId) VALUES
('CITY_HAS_MONUMENT_REQUIREMENTS', 'REQUIRES_CITY_HAS_MONUMENT');

INSERT INTO Requirements (RequirementId, RequirementType) VALUES
('REQUIRES_CITY_HAS_MONUMENT', 'REQUIREMENT_CITY_HAS_BUILDING');

INSERT INTO RequirementArguments (RequirementId, Name, Type, Value, Extra, SecondExtra) VALUES
('REQUIRES_CITY_HAS_MONUMENT', 'BuildingType', 'ARGTYPE_IDENTITY', 'BUILDING_MONUMENT', NULL, NULL);
 
@Gleb Bazov

I did give it a try yesterday as per Cagarustus suggestion, though I never got around to actually test it, ended up adding a bunch of other things and was short on time.

I probably messed up somewhere though, so your solution is much appreciated. Thank you for your time. I'll use it as reference once I get home back from work and let you know.

On a related note, am I correct in assuming that, if instead of a Building creation as RequirementType, you were to use a Tech being researched, it would follow the same procedure?
 
Yes. It would follow the same process. You would have the following. BUT, there is a KEY difference:

Code:
INSERT INTO Modifiers (ModifierId, ModifierType, RunOnce, Permanent, OwnerRequirementSetId, SubjectRequirementSetId) VALUES
('GRANTING_UNIT_IN_QUALIFIED_CITY_MODIFIER', 'MODIFIER_PLAYER_CITIES_GRANT_UNIT_IN_CITY_ON_REQUIREMENTS', 0, 1, 'PLAYER_HAS_REQUIRED_TECH_REQUIREMENTS', NULL);

INSERT INTO ModifierArguments (ModifierId, Name, Type, Value, Extra, SecondExtra) VALUES
('GRANTING_UNIT_IN_QUALIFIED_CITY_MODIFIER', 'UnitType', 'ARGTYPE_IDENTITY', 'UNIT_WARRIOR', NULL, NULL),
('GRANTING_UNIT_IN_QUALIFIED_CITY_MODIFIER', 'Amount', 'ARGTYPE_IDENTITY', '1', NULL, NULL);

INSERT INTO RequirementSets (RequirementSetId, RequirementSetType) VALUES
('PLAYER_HAS_REQUIRED_TECH_REQUIREMENTS', 'REQUIREMENTSET_TEST_ALL');

INSERT INTO RequirementSetRequirements (RequirementSetId, RequirementId) VALUES
('PLAYER_HAS_REQUIRED_TECH_REQUIREMENTS', 'REQUIRES_REQUIRED_TECH');

INSERT INTO Requirements (RequirementId, RequirementType) VALUES
('REQUIRES_REQUIRED_TECH', 'REQUIREMENT_PLAYER_HAS_TECHNOLOGY');

INSERT INTO RequirementArguments (RequirementId, Name, Type, Value, Extra, SecondExtra) VALUES
('REQUIRES_REQUIRED_TECH', 'TechnologyType', 'ARGTYPE_IDENTITY', 'TECH_THE_WHEEL', NULL, NULL);

THE KEY DIFFERENCE is that you would have OwnerRequirementSetId instead of SubjectRequirementSetId for the technology requirements. In other words, the requirement applies to the owner of the Modifier - to the Civlization (or Leader, whatever), not to the city. The building requirement has to go with the subject -- the city -- because it is on a per city basis.

Note that I am using SQL statements here, not XML, so you would need an SQL file to implement this. You can convert this to XML easy enough, though, if you read through it carefully.

And don't bother going through my earlier solutions. The dummy buildings are not necessary for this approach above. I've provided a new solution (without dummy buildings) for Cagarustus' objective as well. So, yes, just stick with the approach I gave above.
 
You can also combine the two:

Owner Requirement Set (applies to the player) --
PLAYER_HAS_REQUIRED_TECH_REQUIREMENTS

Subject Requirement Set (applies to cities, on a per city basis) --
CITY_HAS_MONUMENT_REQUIREMENTS

in a single Modifier set.
 
Yes. Just change the building identifier BUILDING_X (instead of BUILDING_MONUMENT use your own unique building).
 
Last edited:
What an idiot I am, I did not copy and paste all of your solution to my SQL..........doh!
Thanks Gleb Bazov. :)
 
@Gleb Bazov
It works many thanks for that but in my Database log I am getting this:
[Database] ERROR: cannot start a transaction within a transaction
 
@Riker13 I don't think this error is related to the code I gave you. At least I don't remember ever seeing an error like this. Perhaps one of your other mods?
 
@Gleb Bazov
Strange I dont have any other mods activated other than my own and when I take that SQL code out it disappears.
Nevermind, I will try and track it down. Thanks Again for the code anyway. :)
 
Back
Top Bottom