-- check yor installed steam mods for reference here: \steamapps\workshop\content\289070 -- events: -- https://forums.civfanatics.com/threads/list-of-game-events.604914/#post-14561939 -- put your mod in: C:\Users\Miguel\Documents\My Games\Sid Meier's Civilization VI\Mods\SuperTimer -- lua log is here: /Documents and Settings/Miguel/My Documents/My Games/Sid Meier's Civilization VI/Logs -- Icon codes: https://forums.civfanatics.com/threads/list-of-all-icon-codes.613516/ -- lua objects: https://forums.civfanatics.com/threads/lua-objects.601146/ -- persistance: -- they're not saved, but see -- https://forums.civfanatics.com/threads/lua-objects.601146/page-4#post-14634018 -- https://forums.civfanatics.com/threads/saving-loading-simple-tables-with-a-game.609397/ -- https://forums.civfanatics.com/threads/persisting-custom-data-with-saves.611878/ -- this lua file, will be auto-reloaded on change by civ6 verbose = false function log( txt ) if verbose then print ( '[' .. os.time() .. ']' .. " [SuperTimer] " .. txt ); end end function getState() state = GameConfiguration.GetValue ("SuperTimerState") if state == nil then GameConfiguration.SetValue ("SuperTimerState","") return "" else return state end end function split(s, delimiter) result = {}; for match in (s..delimiter):gmatch("(.-)"..delimiter) do table.insert(result, match); end return result; end function toEvent(event, turn) if event == "B" then return "Turn " .. turn .. " begins" end if event == "E" then return "Turn ends" end if event == "S" then return "Game Saved" end if event == "L" then return "Game Loaded" end return "Unknown Event" end function addState( state, turn ) newstate = getState() .. os.time() .. " " .. turn .. " " .. state .. "|"; GameConfiguration.SetValue ("SuperTimerState",newstate); tooltip = "[ICON_Capital]Miguel's SuperTimer[ICON_Capital][NEWLINE]" lastturn=0 lastevent=0; sumtime=0; for m in (newstate):gmatch("(.-)".."|") do spl = split(m," ") unixtime = tonumber(spl[1]); turn = tonumber(spl[2]); event = spl[3]; if event == "B" then lastturn = turn - 1 end if event == "L" then lastevent = unixtime; else sumtime = sumtime + ( unixtime-lastevent ); log (sumtime); lastevent = unixtime; end t = os.date("*t", unixtime) txt = toEvent(event,spl[2]); log (t.hour .. ":" .. t.min .. ":" .. t.sec .. " " .. txt) end log("Total: " .. sumtime .. " seconds"); log("Total: " .. os.date('!%T', sumtime)); if lastturn == 0 then tooltip = "[ICON_Capital]Miguel's SuperTimer[ICON_Capital]" .. "[NEWLINE]Complete first turn to collect data" else tooltip = "[ICON_Capital]Miguel's SuperTimer[ICON_Capital]" .. "[NEWLINE]Turns Completed:" .. lastturn .. "[NEWLINE]Total Time: " .. os.date('!%T', sumtime) .. "[NEWLINE]Average Turn: " .. os.date('!%T', sumtime/lastturn); end if Controls.SuperTimerButton ~= nil then Controls.SuperTimerButton:SetToolTipString (tooltip); end end function mouseOverTimer() log ( "mouseOverTimer" ); end function Initialise() log ( "Game started/loaded" ); addState( "L" , 0 ); local topPanel = ContextPtr:LookUpControl("/InGame/TopPanel/RightContents"); Controls.SuperTimerButton:ChangeParent(topPanel); topPanel:AddChildAtIndex(Controls.SuperTimerButton, 0); topPanel:CalculateSize(); topPanel:ReprocessAnchoring(); Controls.SuperTimerButton:RegisterCallback( Mouse.eMouseEnter, mouseOverTimer); end function OnTurnBegin( turn ) addState( "B" , turn ) end function OnTurnEnd() addState( "E" , 0 ); end function OnPlayerTurnEnd( player ) end function SaveList() log( "Show Savegame List" ); addState( "S" , 0 ); end function SaveButton ( actionID ) log( "InputAction" ); if actionID == Input.GetActionId("QuickSave") then addState( "S" , 0 ); end end function SaveKey ( pInputStruct:table ) log( "InputHandler" ); local uiMsg = pInputStruct:GetMessageType(); if uiMsg == KeyEvents.KeyDown then if pInputStruct:GetKey() == Keys.VK_F5 then -- but the binding can be changed... addState( "S" , 0 ); end end end log ( "Mod Loaded" ); --- EVENTS LuaEvents.FileListQueryComplete.Add( SaveList ); Events.InputActionTriggered.Add( SaveButton ); ContextPtr:SetInputHandler( SaveKey, true ); -- does not work ? Events.LoadScreenClose.Add( Initialise ); Events.TurnBegin.Add( OnTurnBegin ); Events.LocalPlayerTurnEnd.Add( OnTurnEnd ); Events.RemotePlayerTurnEnd.Add( OnPlayerTurnEnd );