Using promotions as LUA Triggers

GenEngineer

Prince
Joined
Aug 24, 2014
Messages
456
Hey everyone. I had some questions about using dummy promotions as triggers for an LUA script. I've got the basics of the script written, but I'm unsure what the exact game events I'm looking for are and I can't find a compilation that describes them. I'm looking to have the script run when a promotion is granted, run the part I've written, and then grant another promotion to the unit. I just need to know the trigger and the 'grant promotion' step.

On a secondary note, something I've noticed in the Tech Web - if a building is coded to require 2 affinity types to build, the tooltip in the web will only list 1 of the two (the second one listed in the code). It builds correctly, but I don't know how to fix the tooltip. Thoughts?
 
As far as I know there is no Lua-Event that can be called when a Promotion is granted (though I may be wrong on that).

As a workaround you can circle through all Units of a player at the beginning of each turn and use the Unit:IsHasPromotion-Check to add another Promotion to units that have your dummy-promotion.

You could fix the tooltip in two ways:
- edit the InfoTooltipInclude.lua (in the UI-Folder, not Gameplay), but this will run into compatibility issues with mods that edit this file (which some mods already do)
- the far easier method is to just add an additional line manually as part of the <Help>-TXT-KEY. Of course you'd have to maintain them manually then.
 
I think that should do what I need it to - at worst, there's a turn delay before the effect triggers, which is acceptable. As for the tooltips, I'm manually editing most of them to make the new buildings, not afraid to add a bit more work.

Thanks!
 
On second thought, there might be other issues. On further testing, the TrainedFreePromotion thing doesn't seem to do anything - I made a quick test mod where the OER gave the Panopticon Promotion to see if it worked, but no there's no difference between a soldier built after the OER and one built before. Is there something I'm missing in getting that functionality to work?
 
There isn't a Lua event that fires when a promotion is acquired but it is possible to detect when a unit is created if you're trying to make a certain set of complex circumstances grant promotions.

Could you provide a specification of what you're trying to do?
 
The general idea is to add in a building that will grant 1 of 5 random promotions to units built in a city afterwards. The 'Cycle through every unit to find dummy promotion' idea seems like it might work,but the issue that I've run into now is that the default "TrainedFreePromotion" functionality in the XML doesn't appear to be granting a promotion - the logic behind the LUA may or may not be sound, but I can't test it yet because I can't seem to grant the dummy promotion.
 
You probably have an error in your code somewhere, because this here works perfectly fine for me:

Code:
<GameData>		
	<Buildings>
		<Update>
			<Where Type="BUILDING_HEADQUARTERS"/>
			<Set TrainedFreePromotion="PROMOTION_PANOPTICON"/>
		</Update>		
	</Buildings>
</GameData>
All Units start with the +1 Sight Promotion.
 
The general idea is to add in a building that will grant 1 of 5 random promotions to units built in a city afterwards.
That will be easy. Use the unit created event to detect when a unit is created. Check the plot to see if it is a city and if the city has the building. Get a random number and give the promotion to the unit.
 
I think I've identified the issue, actually. Setting the TrainedFreePromotion functionality to add an existing promotion (a la Panopticon) works perfectly (if you don't make a typo in the test code). The issue is that the code won't seem to create another promotion - Copy and paste the code for the panopticon promotion to make a new promotion, rename it PROMOTION_DUMMY (in both the promotion section and the building), and the promotion doesn't seem to be added/do anything. The rest of the code will work fine, allowing the parts that add a building to add the building, but the promotions seem to just be missing.

Suggestions?
 
First, I'd check in the civilopedia, to see if your new promotion is listed there. If it's not then there's probably a typo or mistake in the promotion's definition.

If the promotion exists but is not being granted, then you may have forgotten to make <UnitPromotions_UnitCombats> entries for it. The game will only grant a promotion to units with a CombatClass eligible to recieve it, as defined in that table.
 
Top Bottom