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

Place to post guides, observations, things related to modding that are not mods themselves.
Phoscur
Burner Inserter
Burner Inserter
Posts: 6
Joined: Wed Jan 04, 2017 9:04 pm
Contact:

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

Post 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!
Last edited by Phoscur on Sun Jan 08, 2017 3:33 pm, edited 1 time in total.
Creat
Inserter
Inserter
Posts: 41
Joined: Sun Jun 22, 2014 4:35 pm
Contact:

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

Post by Creat »

I'd also very much like to know, so: bump :)
Articulating
Long Handed Inserter
Long Handed Inserter
Posts: 71
Joined: Mon Oct 17, 2016 10:33 am
Contact:

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

Post 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.
Phoscur
Burner Inserter
Burner Inserter
Posts: 6
Joined: Wed Jan 04, 2017 9:04 pm
Contact:

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

Post 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?
daniel34
Global Moderator
Global Moderator
Posts: 2761
Joined: Thu Dec 25, 2014 7:30 am
Contact:

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

Post 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.
quick links: log file | graphical issues | wiki
Phoscur
Burner Inserter
Burner Inserter
Posts: 6
Joined: Wed Jan 04, 2017 9:04 pm
Contact:

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

Post by Phoscur »

Brilliant daniel34! I'm going to test this asap. Having the next multiplayer session on tuesday :)
Phoscur
Burner Inserter
Burner Inserter
Posts: 6
Joined: Wed Jan 04, 2017 9:04 pm
Contact:

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

Post 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 ?
Articulating
Long Handed Inserter
Long Handed Inserter
Posts: 71
Joined: Mon Oct 17, 2016 10:33 am
Contact:

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

Post by Articulating »

It's being added in 0.15, until then you'll have to wait :)
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

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

Post by Nexela »

You can use on_player_died to log deaths. However what caused the death will have to wait until .15
Phoscur
Burner Inserter
Burner Inserter
Posts: 6
Joined: Wed Jan 04, 2017 9:04 pm
Contact:

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

Post by Phoscur »

Great! And if I wanted to register players logging off, or dropping, which events would I subscribe to?
on_player_left_game?
Articulating
Long Handed Inserter
Long Handed Inserter
Posts: 71
Joined: Mon Oct 17, 2016 10:33 am
Contact:

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

Post 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.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

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

Post 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
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Post Reply

Return to “Modding discussion”