LeeS
Imperator
LOL @ eating crow. Have never heard that expression until now. Would it be too much to ask of you to try to finish the Lua script Lee? The promotion is working btw, tested it in-game today. Only weird thing is that it gives +2 faith per death instead of +1, despite the Lua value being set to 1. Oh, and the promotion icon is the 'instant heal' icon, but I'm sure I can figure out how to change that myself.
GameEvents.UnitPrekill(iPlayer, iUnit, eUnit, iPlotX,iPlotY,bDelay,eByPlayer) is a dreadful PITA to bend to your will:
- It fires at least once for every unit-removal from the game for whatever cause
- When a unit is disbanded
- when a Settler founds a city
- when a civiian unit is captured
- when a Great Person does thier Great Person 'thing' (either improvement or 'action')
- when a unit is upgraded (the original unit is removed and therefore 'killed')
- it fires twice for any unit that is killed off as a result of actual combat. Incidentally, this is why your code is not working as anticipated.
- When a unit is killed off in actual combat, the event fires twice for that unit.
- the first time it fires for the killing of a unit, bDelay will be equal to true, and eByPlayer will be equal to the Player ID# of the player who was victorious in the combat.
- other than grabbing who did the killing to whom (iPlayer and eByPlayer) there really is not much usable information beyond what unit was killed.
- the second time it fires for the killing of a unit, bDelay will be equal to false, and eByPlayer will be equal to -1.
- during this second firing, additional information can be gleaned on which actual unit was the victorious unit, but in order to do so, you must get the plot info for the X,Y position of the plot, and then check all units that are seen as being on the plot.
- when doing this check of all units seen to be on the plot, you must weed out the unit that was killed when you are interested in the victorious unit, because the defeated unit will also be shown as being a unit still occupying the plot
- however, this only works for direct-attack units that attacked and killed off another unit. Direct-attack units as in Melee, Gunpowder, Mounted, Armor units.
- you will get no usable information for Ranged or Siege units that attacked and killed off another unit
- if the unit that was victorious was attacked by the unit that was killed, you will have no usable information about the unit that survived the combat.
- the first time it fires for the killing of a unit, bDelay will be equal to true, and eByPlayer will be equal to the Player ID# of the player who was victorious in the combat.
- It took me weeks to work out methods to bend this event to my will when attempting to determine who killed who in terms of which units did what for the Scipio's Rome mod. And even then there are mis-firings and mis-application of results from time to time because of the reasons outlined above. I have zero desire to leap back into that fetid cesspool of Firaxis-nopes.
- It is pretty easy to use UnitPrekill when all you are interested in is which player killed off which unit of which other player and where this unit was killed. But as soon as you start down the path of determining which unit killed which unit, you are in for an interesting experience in lua coding for Civ5.