Copy and paste this somewhere into the TokyoExpressUnits.lua
Probably best to do so at the end of the file
It will fire twice every time a unit is killed or removed from the game
Code:
function prekillListener(iOwner, iUnit, iUnitType, iX, iY, bDelay, iKiller)
print("prekillListener: Dumping data..")
print("iOwner: " .. iOwner)
print("iUnit: " .. iUnit)
print("iUnitType: " .. iUnitType .. " (" .. GameInfo.Units[iUnitType].Type .. ")")
print("iX: " .. iX)
print("iY: " .. iY)
print("bDelay: " .. tostring(bDelay))
-- bDelay returns true before unit is killed (before UnitKilledInCombat) and only has one unit on the plot
-- bDelay returns false after the unit is killed (after UnitKilledInCombat) and an enemy melee unit may be on the same plot at this point
print("iKiller: " .. iKiller)
local pPlot = Map.GetPlot(iX, iY)
local iNumTileUnits = pPlot:GetNumUnits()
print("numUnits: " .. iNumTileUnits)
--in the following loop through the units that are still 'on the tile' the unit that was killed will also be listed
--if the killed unit was destroyed by a direct-attack unit that direct-attack unit will also be shown as occupting the tile
--if the killed unit was destroyed by a ranged unit of any kind then the killer unit will NOT be shown as occupying the tile
for i = 0, pPlot:GetNumUnits() do
local pUnit = pPlot:GetUnit(i)
if pUnit then
print("Unit's Owner is: " .. pUnit:GetOwner())
print("UnitType is: " .. pUnit:GetUnitType() .. " (" .. GameInfo.Units[pUnit:GetUnitType()].Type .. ")")
end
end
end
GameEvents.UnitPrekill.Add(prekillListener)
----------------------------------------------------------------------------------------------------------------------------
Example of the sort of print-out you get in the lua log when a unit is killed or otherwise removed from the game.
Following example print-outs were from before I changed the code to make it list all units "occupying" the tile: