What are the arguments for CanSaveUnit?

Craig_Sutter

Deity
Joined
Aug 13, 2002
Messages
2,773
Location
Calgary, Canada
I need to derive the name of unit killed in combat. I have found possibilities in the following two functions:

GameEvents.CanSaveUnit
GameEvents.UnitKilledInCombat

Correct me if I am wrong, but it looks like UnitKilledinCombat only gives me the unit type (ie. UNIT_WARRIOR). However, it does not give me the identity of the particular unit killed.

On the other hand, from my reading, I think I can use CanSaveUnit. The problem is that I cannot seem to find the arguments for it... I could not find it as a GameEvent in the Wiki and do not know where to look to get the arguments. I think it does give the plot position of the killed unit... from which I can probably derive the identity of said unit.

So, what are the parameters of CanSaveUnit?

And how can I derive the identity of a particular unit from those parameters (not the type)? In my case, I need to get the particular unit's identity... derive its name from that ("Earl of Northumbria (Earl)")... check that the actual unit name matches that particular unit...delete a dummy building on that basis.

Assuming that all instances of unit destruction including death in combat cause the functions above to fire off... I am also going to have to use hex position to match it to the unit's capital city (since the may "die" there as it is also a spaceship part that disappears when used in the capital).

Thank-you for your assistance.
 
See attachments to post #6 here

UnitKilledInCombat can't give you the ID of the unit, as the event triggers AFTER the unit is killed and no longer exists, so any attempt to reference the unit from the handler would cause a null pointer exception and CTD

CanSaveUnit does give you the ID, as it's called BEFORE the unit is killed

You will need to test that CanSaveUnit triggers for all situations you need it for (it should, as it's called from CvUnit::kill() - which gets called for all unit removal) and that it doesn't trigger more than once. The event was added for the Civil War scenario (heroic escape for generals IIRC) so would only have been added to do what Firaxis needed - so make no general or common sense assumptions about it, test it works for your specific requirements
 
Back
Top Bottom