Is there a way to add and delete traits at change of eras?

skynogi

Chieftain
Joined
Oct 4, 2008
Messages
5
When era changes, I want to add a new custom trait, and delete the past custom trait to the leader by using lua if possible. All traits will be listed in the DB, and one default trait will be constant throughout the era. Can this be possible by making as a mod?
 
GS allows us to attach Database modifiers to a player or a city, but we cannot remove a modifier via lua.
Code:
pPlayer:AttachModifierByID("SCENARIO_EVENT_MOD_ALL_FALL_DOWN_CITY_YIELDS");
"SCENARIO_EVENT_MOD_ALL_FALL_DOWN_CITY_YIELDS" is the Name of a ModifierId used in the Black Death Scenario.

If you are creative with your modifiers, however, you can create two modifiers that would have equally opposite effects. So MODIFIER_ADD_X would add whatever "X" is to the player, and MODIFIER_REMOVE_X would have a logical or numerical opposite effect. At the start of the game you would attach MODIFIER_ADD_X to the correct player, and then when that player hits the era where that effect should cease, you would attach the MODIFIER_REMOVE_X modifier to the player, thus canceling the "X" effect. You could then attach a new modifier to the player called MODIFIER_ADD_Y, remove it when needed, and add a third effect "Z", etc, as the player moves through the game's eras.

Remember that Traits in and of themselves really don't do anything much -- they're really just "holders" to which we normally attach Modifiers via the <TraitModifiers> table.
 
Last edited:
I have a similar question. Is there any way to add traits with lua now? I want to be able to control the unlocking of unique units/improvements/buildings/districts with lua. If I could add/attach traits then that would make things simple. From what I can see for uniques it seems to be just the trait itself that controls them, and not the TraitModifiers.

I have done some experimenting with the MODIFIER_PLAYER_ADJUST_VALID_UNIT_BUILD, but unlocking a unique unit with that does not have the same behavior as the normal method. I was testing it with the Aztec eagle warrior and was able to build both normal warrior and eagle warriors instead of replacing the warrior. I also did not see any era score added for building an eagle warrior.
 
It is possible to make modifier requirements based on era, e.g.
GAME_ERA_ATLEAST_EXPANSION
GAME_ERA_ATMOST_EXPANSION
GAME_ERA_IS
PLAYER_ERA_AT_LEAST
You may experiment to see if an effect you wanna use for the trait is available and then build a proper modifier that will attach / detach features based on an era.
 
Thanks everyone for the ideas. In my case I am not doing anything related to eras like the OP, but wanted to attach traits with LUA if possible which was part of the original question. My purpose is to unlock uniques from other civs/leaders for any player under certain circumstances. I am close to my desired behavior by attaching player modifiers, but attaching new traits would make it all simpler.

The remaining difficulty is with unique units that replace another unit. For now I am using a combination of MODIFIER_PLAYER_UNIT_BUILD_DISABLED and MODIFIER_PLAYER_ADJUST_VALID_UNIT_BUILD to disable the normal unit and enable the unique unit. This works for city build queue options, but there is still a problem with upgrading units. Units still upgrade to the disabled unit instead of the unique unit. For example, I was testing with Nubian Pitati Archer (enabling it for non-Nubian civs) - cities could build it and no longer had the option to build the regular archer. However, slingers still upgraded to the regular archer.

To fix the upgrade issue I am thinking of writing a hook for the UnitUpgraded event that will replace the upgraded unit with the correct unique unit. To the user I still want it to appear the same as other upgrades so the unit needs to inherit promotions, etc... Does anyone know if this is possible and perhaps some mod or Firaxis code that does similar? I was looking through the UnitPanel.lua. I can see there is UnitCommandTypes.UPGRADE but I am not sure what other parameters I need to pass to UnitManager.RequestCommand().

Unique buildings do not give me the same problems even though they replace existing things because the EFFECT_ADJUST_PLAYER_VALID_BUILDING takes the arguments BuildingType and BuildingTypeToReplace. As far as I know EFFECT_ADJUST_PLAYER_VALID_UNIT_BUILD only takes a UnitType.
 
Back
Top Bottom