• Civilization 7 has been announced. For more info please check the forum here .
Resource icon

Unit Created Event [snippet for mod makers] 2016-10-05

This mod contains code that defines a lua event that fires off when a unit is created. The event does not fire when a unit is upgraded. The lua event provides the information you need to get the owning player object and the unit object.

If you want to delete the unit don't use "unit:Kill()" as that could cause other code hooked into this event to crash. Instead use "unit:SetHasPromotion(GameInfoTypes["PROMOTION_UCE_MARKED_FOR_DEATH"], true)". The UCE stands for Unit created event. Units with that promotion will automatically be killed after all functions hooked into the event are executed.

If an end-user is playing with multiple mods that use this snippet it will work properly.

IMPORTANT: Because this snippet adds a promotion users of any mod that incorporates this snippet will need to "enable->back->re-enable" your mod for to avoid the flaw in Fraxis's design for UnitPanel. If they don't do this all their units will be killed when they start or load a game (along with general rending issues for the UnitPanel).

More information at the discussion thread.
  • unitcreatedevent_6Y6.jpg
    30.7 KB · Views: 148
First release
Last update
0.00 star(s) 0 ratings

More resources from Machiavelli24

Top Bottom