Spawning luxuries from cutting down forests/jungle?

Having a random chance of luxury spawning on a tile is possible through LUA because framedarchitecture did it with his Reforestation mod using a dummy improvement for a worker to build an "improvement" to later the improvement is replaced by the feature itself and then giving a chance of 1% to spawn a luxury.

Detecting whether a worker of your civilization just chopped a tree is beyond my knowledge. Perhaps, someone can also enlighten on a workaround.
 
If you're using a modded DLL (mine or CP) you can hook the TerraformingPlot event
 
If you don't mind including marshes in there too, I believe that something programmed like this will trigger whenever a worker finishes a action that does not build any improvement, and as far as I can recall that's only chop down jungles/forests and clear marshes.

Code:
function code(playerID, plotX, plotY, improvementID) 
	local player = Players[playerID]
	if improvementID == -1 then
		-- do stuff
	end
end
GameEvents.BuildFinished.Add(code)

If you REALLY want it to be only on jungles/forests, you must save those tiles at the start of each turn using saveutils, then compare the saved data when the BuildFinished is triggered. If the saved data says that there used to be jungles or forests there, make the luxury spawn on that tile.
 
Presumably that would trigger when scrubbing fallout as well though, right?

It wouldn't be an issue in most cases however.
Yes, scrubbing fallout as well.

Seems that you would need to go with the complicated route then: when a worker moves into a tile, save using saveutils whether that tile has a forest/jungle or not, and then when that game event triggers, check if the tile does not have a forest/jungle anymore, then trigger the bonus.
 
Yeah... I don't really wanna mess with DLL. How would I do it through the remembering the jungle tiles method?

On turn 1 check all the map plots and put jungle ones into a table. Save this table with SaveUtils.
On each next turn load the table (if not loaded), check all plots from the talbe and look if jungles are still there. If not, remove this plot from the table and place a lux. Save table.

or use BuildFinished event to check particular plots as proposed above instead of checking all plots each turn (didnt know about this event before)
 
Just bear in mind BuildFinished only fires for BNW.

Personally I would use TableSaverLoader for saving data you are putting in tables because once you make the hook-ups in your code (which when using DarkScythe's addon TSL Serializer is a trivial amount of code) you never ever need to make additional code for saving/loading persistent data -- TableSaverLoader handles all that for you, and does it when a save/load system really ought to: when the human player does some form of "save game". All you as the writer of your lua script do is manipulate the data within your table(s). The reloading of the data within the tables from the last game-session are done automatically, as is the saving of the data in the tables from the current game session when the player does savegame.
 
Sorry for my noobishness, but how do you create, load, and save tables?

google for "lua tables" and study them
then choose some modder's api, SaveUtils or this new fancy TableSaveLoader and read how to use it.
it should not be hard.
and best of all open some mod's lua files and see how things are done. i dont know what mod to recommend for anatomization (as my mods use a custom saving api) maybe other ppl will give such an advise..
 
Top Bottom