I created a function that generates a new resource, when a Great Person constructs a special improvement. That improvement is removed and the resource appears somewhere on the map.
I used the BuildFinished event for this, but it behaves in a weird way: it fires twice, and both instances seem to be executed at the same time. So when I added a check if the improvement still exists, both instances of the event detect that it does. The result is that two resources instead of one are created, which is not what I wanted to do.
Or perhaps they aren't really executed at the same time, but Plot:SetImprovementType has a delayed effect, so it doesn't change the improvement on the plot before the event fires again. Anyway, both events report that the improvement still exists on the plot, despite the fact that they both remove it.
Is there a way to avoid this problem? (I can post my Lua code if needed, although it will require some changes to run without the entire mod, as it uses some new tables in the database, and new columns in existing tables.)
I used the BuildFinished event for this, but it behaves in a weird way: it fires twice, and both instances seem to be executed at the same time. So when I added a check if the improvement still exists, both instances of the event detect that it does. The result is that two resources instead of one are created, which is not what I wanted to do.
Or perhaps they aren't really executed at the same time, but Plot:SetImprovementType has a delayed effect, so it doesn't change the improvement on the plot before the event fires again. Anyway, both events report that the improvement still exists on the plot, despite the fact that they both remove it.
Is there a way to avoid this problem? (I can post my Lua code if needed, although it will require some changes to run without the entire mod, as it uses some new tables in the database, and new columns in existing tables.)