Great Person Expending

Graan

Chieftain
Joined
Feb 10, 2013
Messages
20
I'm trying to capture the moment where a Great Person is expended. What I tried was:

Code:
function MyFunction(iPlayer, iUnit)
	local pPlayer = Players[iPlayer]
	local pUnit = pPlayer:GetUnitByID(iUnit)

	print("EVENT TRIGGERED: ", pPlayer:GetName(), " - ", pUnit:GetUnitType(), " - ", pUnit:IsDead())

end

Events.SerialEventUnitDestroyed.Add(MyFunction)

...and so forth, using UnitType and IsDead to determine which type of Great Person was expended (I am aware this would trigger on Great People that were actually killed, but I'm okay with that).

The problem I encountered: when I try to retrieve the Unit from its UnitID, it will fail as the unit is dead and can no longer be found. I can't find any other event that might help me, and I don't think the one I'm currently using will get me anywhere either.

Does anyone know a way to do this?
 
You can do it in Lua by caching every GP at the start of a player's turn, and then matching your cached data to the unit you got the event for.

Or you can use the event I added to my DLL mod

Code:
// Event sent just before a unit is killed (via CvUnit::kill())
//   GameEvents.UnitPrekill.Add(function(iPlayer, iUnit, iUnitType, iX, iY, bDelay, iByPlayer) end)

as at the time the event is sent the unit still exists
 
Thanks! I'll look into these options when I have time. From a quick look, it seems the latter would likely have the best performance.
 
Back
Top Bottom