Event Hook for a player manually destroying a unit?

The_Space_Cows

Chieftain
Joined
Mar 18, 2023
Messages
19
I have a mod feature I've been working on where tiles improvements that provide defensive bonuses (forts, citadels and chateaus) give and additional +2 culture if there is a unit in the tile. When the unit leaves the tile by any means or the tile improvement is changed, the culture yield is removed from the tile.

I can detect when a unit moves using GameEvents.UnitSetXY, I can detect when a unit is killed using GameEvents.UnitPreKill (an event hook from another mod, DLL - Various Mod Components).

But if the player manually destroys the unit using the menu options, neither UnitSetXY nor UnitPreKill will trigger.

There is an event in the base game, Events.SerialEventUnitDestroyed which does trigger, but unfortunately the plot coordinates are not passed into the function. I could go the super inefficient route of checking every single tile within that player's borders for a tile improvement producing culture that it shouldn't be, but I thought maybe there was a better solution and I thought I'd ask.

Does anyone know of a better solution, involving less bashing my head against my keyboard?
 
You might not also get an event if a unit is disbanded due to supply issues.

To detect the player manually disbanding a unit you could mod the UI unit panel to send your own LuaEvent.

You don't need to scan the entire map, just record (in the mod db) at what plots you added the culture bonus, then just scan those plots at the end of a player's turn to see if they are still valid
 
Top Bottom