how to add fallout from dead units?

Hulfgar

Emperor
Joined
Mar 31, 2008
Messages
1,798
Location
France
Hi,

I wish to have fallout spawns on the tile where an uranium powered unit has been destroyed.

Putmalk has provided me with the following code but nothing happens and we don't find what's wrong :

Code:
print("---- Fallout mod ----");


Events.EndCombatSim.Add(function ( 	iAttackingPlayer, iAttackingUnit, iAttackingUnitDamage, iAttackingUnitFinalDamage,
									iAttackingUnitMaxHitPoints, iDefendingPlayer, iDefendingUnit, iDefendingUnitDamage,
									iDefendingUnitFinalDamage, iDefendingUnitMaxHitPoints )
									
	-- Case: Both die
	if(iAttackingUnitFinalDamage <= 0 and iDefendingUnitFinalDamage <= 0) then
		CreateFalloutOnUnitPlot(iAttackingUnit);
		CreateFalloutOnUnitPlot(iDefendingUnit);
	-- Case: Attacker dies
	elseif(iAttackingUnitFinalDamage <= 0) then
		CreateFalloutOnUnitPlot(iAttackingUnit);
	-- Case: Defender dies
	elseif(iDefendingUnitFinalDamage <= 0) then
		CreateFalloutOnUnitPlot(iDefendingUnit);
	end
end);

function CreateFalloutOnUnitPlot(unitType)
	iNumResourceNeeded = Game.GetNumResourceForUnit(unitType, GameInfo.Resources["RESOURCE_URANIUM"].ID);
	
	-- This unit requires uranium, let's get his plot.
	if(iNumResourceNeeded > 0) then
		local plotX = unitType:GetX();
		local plotY = unitType:GetY();
	-- Unit doesn't require uranium.
	else
		return;
	end
	
	-- Get the fallout ID
	featureFallout = FeatureTypes.FEATURE_FALLOUT;
	
	-- Create fallout on Unit's X, Y
	local plot = Map.GetPlot(plotX, plotY);
	pPlot:SetFeatureType(featureFallout);
end

The file with the code has been loaded with an InGameUIAddin line, it's VFS is set to true and there is no runtime error in the lua console.

Maybe on of you will have an idea ?
 
IIRC EndCombatSim is not called if the defending unit is killed in the combat since patch .674.

And iAttackingUnit, iDefendingUnit are unit id for a player.

So to make it work at least for the attacking unit, you want the unit Type ID in CreateFalloutOnUnitPlot(unitType), you'll get it this way in EndCombatSim:

Code:
local attackingPlayer = Players[iAttackingPlayer]
local attackingUnit = attackingPlayer:GetUnitByID(iAttackingUnit)
local attackingUnitType = attackingUnit:GetUnitType()
 
IIRC EndCombatSim is not called if the defending unit is killed in the combat since patch .674.

Yep. And it's not always called if the attacking unit dies either. That one "tweak" by Firaxis is what killed Spatz's mods. (They also changed the call sequence of events around the same time, which screwed several of my own mods.)
 
yep, it's the call sequence new order that was the major problem for me too.

@Hulfgar: whoward's DLL contains a replacement for EndCombatSim that you could use.
 
Thanks for all those answers guys.

@Hulfgar: whoward's DLL contains a replacement for EndCombatSim that you could use.
Good to know, I will have a look into it.
 
Back
Top Bottom