Page 1 of 1

[0.16.51] Only able to run command in multiplayer?

Posted: Sat Jun 23, 2018 4:41 pm
by AreYouScared
I'm attempting to fun the following command to get the play time for all players on 43 maps, sadly one at a time.

Command:

Code: Select all

/command 
game.write_file("TimeOnline/timeOnline.txt","",false,0)  
for _,player in pairs(game.players) do    
local tick = player.online_time    
local pre_seconds = tick/60    
local pre_minutes = pre_seconds/60    
local pre_hours = pre_minutes/60    
local days = math.floor((pre_hours)/24)    
local hours = math.floor(pre_hours - 24*days)    
local minutes = math.floor((pre_minutes - 60*(hours + 24*days)))    
local seconds = math.floor(((pre_seconds - 60*minutes)-60*(60*(hours + 24*days))))    
local returnString = "name: "..player.name.." has played on the server for "..days.." days "..hours.." hours "..minutes.." minutes "..seconds.." seconds"        game.write_file("TimeOnline/timeOnline.txt",returnString.."\n",true,0)  end
Issue: When a map is loaded in single player the command shows its ran as a command but doesn't export the file like it should, Load the map on a headless or 'Host saved game'

Re: [0.16.51] Only able to run command in multiplayer?

Posted: Sat Jun 23, 2018 5:20 pm
by Bilka
game.write_file("TimeOnline/timeOnline.txt","",false,0)
game.write_file("TimeOnline/timeOnline.txt",returnString.."\n",true,0)
You are writing for player 0, the headless server (http://lua-api.factorio.com/latest/LuaG ... write_file). Remove the parameter and it will also write to file in singleplayer.

Moved to modding help.