Page 1 of 1

[Solved]Export Game Event Data and Players to Log File again

Posted: Wed Jan 04, 2017 9:32 pm
by Phoscur
Hi!
I'm posting this Log File related issue here, because it seems the obvious solution to write a mod (but I don't know how to do this yet) and also because I need help and I want more opinions on this.

In conjunction with a v.0.13.x dedicated multiplayer server, a friend of mine ran a Telegram (Messenger) Bot, which would post logins in the groupchat. As of 0.14.1, the Log File has changed, and Player Names are no longer in the server Log Files. Would be nice to hear some reasoning on this from the devs too!

The bot can also control initialization of the game and could take care about maintaining mods and saves.

In the interest of reviving the Bot's best features (announcing player joins [and deaths}) I want to create a mod that writes these events down to a specific file or server log.
Any example how this is done in Lua would be very appreciated!

Re: Export Game Event Data [and Player Names to Log File again]

Posted: Sun Jan 08, 2017 1:26 pm
by Creat
I'd also very much like to know, so: bump :)

Re: Export Game Event Data [and Player Names to Log File again]

Posted: Sun Jan 08, 2017 1:48 pm
by Articulating

Code: Select all

script.on_event(defines.events.on_player_joined_game, function(event)
    game.write_file("joinlist", game.players[event.player_index].name.."\n", true, 0)
end)
Just an example, you can use any event you like. The first argument of game.write_file is the file path (it appears in script-output/filepath), the second is the data, the third argument is a bool (true or false). If it's true then the data will be appended to whatever is already in the file, if false then it will be overwritten. The final argument is for_player, and when it is 0 only the server will have the file written to. If it is not specified then all of the players will have the file written.

Re: Export Game Event Data [and Player Names to Log File again]

Posted: Sun Jan 08, 2017 2:41 pm
by Phoscur
Thank you Articulating!
These are the lines I was looking for. Now I only have to put them with some Factorio Mod Config and Bootstrapping.

Then I probably should publish them to have them easily distributed to the clients too.
Although I don't see why this code needs to run on the clients. Is it possible to only run this Mod on the server?

It would be like a GFX mod for clients, but for the server, as this is only output related.

Could we hack this directly into the server too?

Re: Export Game Event Data [and Player Names to Log File again]

Posted: Sun Jan 08, 2017 3:08 pm
by daniel34
Phoscur wrote:Then I probably should publish them to have them easily distributed to the clients too.
Although I don't see why this code needs to run on the clients. Is it possible to only run this Mod on the server?

It would be like a GFX mod for clients, but for the server, as this is only output related.

Could we hack this directly into the server too?
You can add the code directly to savegames, just unzip a savegame and add it to the control.lua file, no mod required.
The code will still be run on all clients, but if the last argument (for_player) of the write_file function is set to 0 then it only writes the file on the server. The other clients won't even notice.

Re: Export Game Event Data [and Player Names to Log File again]

Posted: Sun Jan 08, 2017 3:30 pm
by Phoscur
Brilliant daniel34! I'm going to test this asap. Having the next multiplayer session on tuesday :)

Re: [Solved]Export Game Event Data and Players to Log File again

Posted: Sun Jan 08, 2017 4:30 pm
by Phoscur
I can confirm, the proposed codelines from Articulating work as expected!

Now player join, respawn and even rocket launch data is exported.

I tested this by killing myself ingame with a modified control.lua xD

There is an ingame message when a player is killed. Which would be the kill event to subscribe to, and how do I get the "killer" e.g. a Diesel Locomotive ?

Re: [Solved]Export Game Event Data and Players to Log File again

Posted: Mon Jan 09, 2017 12:50 am
by Articulating
It's being added in 0.15, until then you'll have to wait :)

Re: [Solved]Export Game Event Data and Players to Log File again

Posted: Mon Jan 09, 2017 9:46 am
by Nexela
You can use on_player_died to log deaths. However what caused the death will have to wait until .15

Re: [Solved]Export Game Event Data and Players to Log File again

Posted: Mon Jan 16, 2017 7:04 pm
by Phoscur
Great! And if I wanted to register players logging off, or dropping, which events would I subscribe to?
on_player_left_game?

Re: [Solved]Export Game Event Data and Players to Log File again

Posted: Tue Jan 17, 2017 1:17 am
by Articulating
Phoscur wrote:Great! And if I wanted to register players logging off, or dropping, which events would I subscribe to?
on_player_left_game?
You can find the list of events here, in this case on_player_left_game is correct.

Re: [Solved]Export Game Event Data and Players to Log File again

Posted: Thu Feb 02, 2017 12:17 am
by aubergine18
FYI, if you want to very quickly log events without any coding, you can use Mooncat's "Creative Mode" mod - it has a set of options to display events in-game and also log them to disk for later review, etc. https://mods.factorio.com/mods/Mooncat/creative-mode