Trying to get a unit to heal after combat.

luei333

Warlord
Joined
May 25, 2014
Messages
185
Hello again everyone. I'm almost done with another mod, but I'm running into one snag that I really hope you all can help me solve.

The problem is thus: I've made a promotion that I want to grant the unit a combat bonus for their next combat, and then heal them after that combat. To do this, I'm trying to use Lua to remove the promotion after combat (the promotion grants +25% combat bonus correctly and everything):

Code:
function DEPHeal(attackingPlayer, attackingUnit, attackingUnitDamage, attackingUnitFinalDamage, attackingUnitMaxHitPoints, defendingPlayer, defendingUnit, defendingUnitDamage, defendingUnitFinalDamage, defendingUnitMaxHitPoints)
	local pPlayer = Players[attackingPlayer];
	local pUnit = pPlayer:GetUnitByID(attackingUnit);
	if pUnit then
		if pUnit:IsHasPromotion(iDEPPromotionBonus) then
			pUnit:ChangeDamage(-25);
			pUnit:SetHasPromotion(iDEPPromotionBonus, false);
		end
	end
	pPlayer = Players[defendingPlayer];
	pUnit = pPlayer:GetUnitByID(defendingUnit);
	if pUnit then
		if pUnit:IsHasPromotion(iDEPPromotionBonus) then
			pUnit:ChangeDamage(-25);
			pUnit:SetHasPromotion(iDEPPromotionBonus, false);
		end
	end
end
Events.EndCombatSim.Add(DEPHeal)

Now, the code works.... but not when Quick Combat is on. The event I'm using seems to only fire after combat animations, so unless the player watches every combat animation, the promotion will never heal the unit and get removed. Please, for the love of Firaxis, tell me there's another event I can hook my function into to have the same effect, or some non-dll way to implement this. This is pretty much the last thing I have to do for this mod to be completely done!
 
No love from Firaxis.....:sad:

As you've discovered, the 'Sims' are meant for usage when the human player can see the action during animation, and don't fire when there is no animation or when the human player can't observe the action.

Firaxis provided no love for mod-makers who wish to detect combat and to know who attacked who, which did what to which, etc. Without using (for example) VMC and the Battle Events W.Howard added to his VMC DLL mod, you're stuck.
 
I used Events.EndCombatSim for Kurdistan and Minoa with the understanding - supplied, IIRC, by bane_ - that it's a bit quirky as events go in that it does fire even when not actually seen. The caveat, as I understand it - this time supplied by whoward - is that it won't fire with Quick Combat enabled or in SV mode.

If anyone wants to test it, I suppose we could discover once and for all.
 
The RunCombatSim and EndCombatSim events have changed over time. Originally, both triggered for every combat, provided you were playing on the 3D-map without Quick Combat. RunCombatSim was then changed such that it only triggered for combat the active human player could see - this change is what killed "Crazy Spatz's Alpha Centauri Mod" stone dead. If you're looking for the precise mechanics of the change, you'll need to search that sub-forum. IIRC it's also what forced Gedemon to write his own RED events into the DLL.
 
Well ffffffffffffffffffffdang it. Is there really no event hook that fires after combat? Even if it can't catch a unit before it dies that would be fine for me. I suppose the way I can do it is to use the PostCombatRandomPromotions table and give it another unique promotion, then check at the end of the turn and heal them then. Which would be less than ideal, but at least it would work.
 
Well ffffffffffffffffffffdang it. Is there really no event hook that fires after combat?

There is not - quite possibly the single most glaring omission from the default DLL's Lua API (and that's saying a lot!). The closest thing I can think of is GameEvents.UnitPrekill, but that (as the name implies) only runs when a unit is killed, and it only gives the killing player, not the specific unit.
 
Top Bottom