SoehnelS
Chieftain
- Joined
- May 22, 2018
- Messages
- 6
Hello!
I started coding with LUA to get the possibility for more Statistics.
(In a far away future I want to create political maps.)
Thanks to the helpfull posts of different peoples here!
In a first step I want to save data in an external file, without success (only the Lua.log is possible).
First question: Is there a way to save data in an own file? (so it not get lost when restart the game, for example).
Actually I get it how to save data from the map (Map.GetPlotByIndex()).
I also get the turn number (Game.GetCurrentGameTurn()).
Not working is the Calendar-object (Calendar.MakeYearStr(TurnNumber)).
In FireTuner it is working, when I change to "InGame".
Second question: What I have todo, to get it working in my script too? (Something to include or different deffinition in modinfo?)
Thanks in advance!
I started coding with LUA to get the possibility for more Statistics.
(In a far away future I want to create political maps.)
Thanks to the helpfull posts of different peoples here!
In a first step I want to save data in an external file, without success (only the Lua.log is possible).
First question: Is there a way to save data in an own file? (so it not get lost when restart the game, for example).
Actually I get it how to save data from the map (Map.GetPlotByIndex()).
I also get the turn number (Game.GetCurrentGameTurn()).
Not working is the Calendar-object (Calendar.MakeYearStr(TurnNumber)).
In FireTuner it is working, when I change to "InGame".
Second question: What I have todo, to get it working in my script too? (Something to include or different deffinition in modinfo?)
Thanks in advance!
Spoiler modinfo :
PHP:
<?xml version="1.0" encoding="utf-8"?>
<Mod id="b70aa6c7-760a-43ce-a877-5535f1b05be7" version="1">
<Properties>
<Name>SoehnelS01</Name>
<Description>First LUA-Test</Description>
<Teaser>First LUA-Test</Teaser>
<Authors>SoehnelS</Authors>
</Properties>
<Files>
<File>SoehnelS01.lua</File>
</Files>
<InGameActions>
<AddGameplayScripts id="SoehnelS01">
<File>SoehnelS01.lua</File>
</AddGameplayScripts>
</InGameActions>
</Mod>
Spoiler lua :
PHP:
-- MainScript
-- Author: SoehnelS
-- DateCreated: 5/20/2018 7:35:33 PM
--------------------------------------------------------------
print ("Loaded SoehnelS01.lua")
--include( "InstanceManager" );
--include( "SupportFunctions" );
--include( "Civ6Common" );
--include( "LuaClass" );
--include("GameCapabilities");
--include "AssignStartingPlots"
--include( "ToolTipHelper_PlayerYields" );
--include("TabSupport");
--include("AnimSidePanelSupport");
--include("TeamSupport");
function PrintMap()
local iPlotCount = Map.GetPlotCount();
for iPlotLoop = 0, iPlotCount-1, 1 do
local bData = false
local plot = Map.GetPlotByIndex(iPlotLoop)
local NEOfCliff = 0
local WOfCliff = 0
local NWOfCliff = 0
if plot:IsNEOfCliff() then NEOfCliff = 1 end
if plot:IsWOfCliff() then WOfCliff = 1 end
if plot:IsNWOfCliff() then NWOfCliff = 1 end
local NEOfRiver = 0
local WOfRiver = 0
local NWOfRiver = 0
if plot:IsNEOfRiver() then NEOfRiver = 1 end -- GetRiverSWFlowDirection()
if plot:IsWOfRiver() then WOfRiver = 1 end -- GetRiverEFlowDirection()
if plot:IsNWOfRiver() then NWOfRiver = 1 end -- GetRiverSEFlowDirection()
print("MapToConvert["..plot:GetX().."]["..plot:GetY().."]={"..plot:GetTerrainType()..","..plot:GetFeatureType()..","..plot:GetContinentType()..",{{"..NEOfRiver..","..plot:GetRiverSWFlowDirection().. "},{"..WOfRiver..","..plot:GetRiverEFlowDirection().."},{"..NWOfRiver..","..plot:GetRiverSEFlowDirection().."}},{"..plot:GetResourceType(-1)..","..tostring(1).."},{"..NEOfCliff..","..WOfCliff..","..NWOfCliff.."}}")
end
end
function PrintPlayerInformations()
-- Create list of Civilizations and leaders in game
for iPlayer = 0, PlayerManager.GetWasEverAliveCount() - 1 do
local CivilizationTypeName = PlayerConfigurations[iPlayer]:GetCivilizationTypeName()
local LeaderTypeName = PlayerConfigurations[iPlayer]:GetLeaderTypeName()
local IsInGame = PlayerConfigurations[iPlayer]:IsAlive()
-- IsInGame = "UNKNOWN"
print("ID: " .. tostring(iPlayer) .. ": Civilization: " .. CivilizationTypeName .. ": Leader: " .. LeaderTypeName .. ": Active: " .. IsInGame)
end
end
function ListPlayers()
local listItems = {};
local i = 1;
local aPlayers = PlayerManager.GetAlive();
for _, pPlayer in ipairs(aPlayers) do
local pPlayerConfig = PlayerConfigurations[pPlayer:GetID()];
local str = tostring(pPlayer:GetID()) .. ";";
str = str .. pPlayerConfig:GetNickName();
listItems[i] = str;
i = i + 1;
end
return listItems;
end
function writetofile(Data)
TurnNumber = Game.GetCurrentGameTurn();
if TurnNumber == nil then
TurnNumber = 0
end;
-- strDate = Calendar.MakeYearStr(TurnNumber);
strDate ="UNKNOWN"
print( Data .. "------------------------------------------------------------");
print("Year: " .. strDate .. ": Turn: " .. TurnNumber);
-- PrintPlayerInformations()
PrintMap()
--file = io.open("SoehnelS01.txt", "a")
-- file:write("hello", "\n")
--file:write(TextLine, "\n")
--file:close()
print( Data .. "------------------------------------------------------------");
end
function SoehnelSUpdate()
Data = os.date("%Y.%m.%d %H%M%S")
print("Start update " .. Data);
writetofile(Data)
Data = os.date("%Y.%m.%d %H%M%S")
print("End Update " .. Data);
end -- function Update
Events.TurnBegin.Add(SoehnelSUpdate);