I wrote a 'delay' module a while ago. Here's the documentation at the top:
-- A module for specifying an action which might have to wait until
-- a different player's turn, (or, a turn at some point in the future)
--
-- Functions that can be delayed will be provided to this module in
-- a table indexed by strings
-- These functions will take a table as their argument.
-- The keys to the argument table must be strings or numbers,
-- and the values must be strings, numbers, or tables
-- (and each table must only have strings, numbers, and tables)
--
-- usage:
-- delay = require("delayedAction")
--
-- To enable a function to be delayed
-- delay.makeFunctionDelayable(functionNameString,function)
--
-- To delay a function use one of these two functions
-- delay.doInFuture(functionNameString,argumentTable,turn,tribeID=-1)
-- performs an action specified by the functionNameString
-- and the argumentTable, on the turn specified
-- happens after production of the tribe associated with tribeID,
-- or onTurn, if submitted tribeID is -1
--
-- delay.doNextOpportunity(functionNameString,argumentTable={},tribeOrTribeID=-1)
-- performs a delayed action the next time a tribe is active, or immediately
-- if the tribe is the currently active tribe. If no tribe is specified,
-- or the tribeID specified is -1,
-- the action will be performed with the onTurn actions for the next turn
-- if no argumentTable is specified, an empty table is generated
untested example (that I wrote based on looking at the documentation):
Code:
local delay = require("delay")
local function twoTurnsAfterCityCapture(argTable)
civ.ui.text(civ.getCity(argTable["cityID"]).name.." was captured two turns ago.")
end
delay.makeFunctionDelayable("MessageTwoTurnsAfterCityCapture",twoTurnsAfterCityCapture)
function cityTaken.onCityTaken(city,defender)
-- display a message to the tribe that lost the city 2 turns after it was captured, during their after production phase
delay.doInFuture("MessageTwoTunsAfterCapture",{["cityID"] = city.id},civ.getTurn()+2,defender)
end