Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to add more events besides join/leave and chat messages. #6

Open
AGuyNamedJens opened this issue Jan 26, 2022 · 14 comments · Fixed by #12 · May be fixed by #5
Open

Ability to add more events besides join/leave and chat messages. #6

AGuyNamedJens opened this issue Jan 26, 2022 · 14 comments · Fixed by #12 · May be fixed by #5
Assignees
Labels
enhancement New feature or request

Comments

@AGuyNamedJens
Copy link
Owner

It does require manual save editing. The user would need to add custom events for this in control.lua which is located in the save file.

They would be adding a line like so:
script.on_event(defines.events.on_rocket_launched, function(event) print("A rocket was launched") end)

I'll test it on my own factorio server soon. Will update this issue accordingly.

@AGuyNamedJens AGuyNamedJens self-assigned this Jan 26, 2022
@AGuyNamedJens AGuyNamedJens added the enhancement New feature or request label Jan 26, 2022
@AGuyNamedJens AGuyNamedJens linked a pull request Jan 26, 2022 that will close this issue
9 tasks
@AGuyNamedJens
Copy link
Owner Author

AGuyNamedJens commented Jan 26, 2022

Looks like print won't work unless we dump everything with custom startup parameters into a different file..
log ("CustomLogger: " .. serpent.block(msg)) does, which logs

17.390 Script @/opt/factorio/temp/currently-playing/control.lua:6: CustomLogger: {
  created_entity = {
    __self = "userdata"
  },
  item = {
    __self = 0
  },
  name = 6,
  player_index = 1,
  stack = {
    __self = 0
  },
  tick = 10521775
}``` in factorio-current.log, seems like we're going to have to listen to the factorio-current.log to implement this?

@AGuyNamedJens
Copy link
Owner Author

So currently I have an idea for this, it does require a new custom log file, and the user editing their own save zip. It seems to work as it's logging everything needed right now. Only thing left seems to be parsing the ids into actual things if we want to log each placed item as shown in this image. Should work the same for the rest of the events.

image

@Mattie112
Copy link

Yeah it might be a nice feature but it is kinda complicated for someone to set up. Why wouldn't it be able to write to the same log file?

Might still want to offer this though, perhaps create a small companion mod that does this or allowing this for users who don't want mods.

What exactly do you want me to test? To add that custom logger and see what it logs?

@AGuyNamedJens
Copy link
Owner Author

It's not complicated, it's simply opening their save zip, edit control.lua and add events. Why it can't use the same file? Honestly i have no idea, seems like factorio either throws the custom events into factorio current, or into a special folder called scripts.. The parameters added on startup only logs joins, leaves and chats..

And yeah, I'm indeed considering making it a mod for the lazy people.

If you check out the rewrite branch, it should have the functions there.

@AGuyNamedJens
Copy link
Owner Author

AGuyNamedJens commented Jan 27, 2022

local baseFolder = "custom/";
local baseFile = "info_file.txt"

local function log_message(msg)
game.write_file(baseFolder..baseFile, "[LOGGER] Placement: " .. serpent.line( msg, {comment = false}))

end

script.on_event(defines.events.on_built_entity, function(event) log_message(event) end)`

Also a good thing to mention, add this into control.lua, then use /opt/factorio/script-output/custom/info_file.txt as the event file in config.json. This logs all placements into the consoleChannel. I'm working on a Typescript rewrite with one of the forks that were made, which means we now have the master, rewrite and typescript branches. rewrite will be master's rewrite, while typescript will include a lot more features, such as automatic update checking for mods and the server itself.

This event would log
image

@AGuyNamedJens AGuyNamedJens linked a pull request Jan 27, 2022 that will close this issue
@Mattie112
Copy link

Sorry for the late reply had a bunch of issues (unrelated) before being able to try it out. Also got config failures but as I build a docker container (and that was not merged) the path was simply not correct haha that was confusing.

But I have trouble getting this to work. I unzip the savegame, add those lines to control.lua and re-save it. But then when I try to start my server:

   3.610 Error ServerMultiplayerManager.cpp:91: MultiplayerManager failed: "level.dat not found."

So it won't load anymore.

@Mattie112
Copy link

Please ignore the message above, I copied the wrong error and I found the issue, the copy/paste from github included a ` so that was the problem.

I do get the log file, let me see if I can compile the bot for it.

@Mattie112
Copy link

Yes the bot seems happy, should it post messages with this extended output? Not yet right?

@Mattie112
Copy link

Research should also be possible:
https://lua-api.factorio.com/latest/events.html#on_research_finished

Now by seeing this the code you use in the control.lua is most likely the same as for a mod. So yeah would be nice imo to support both :) I might look into this tonight (the mod part) to see how this works.

@AGuyNamedJens
Copy link
Owner Author

Yes the bot seems happy, should it post messages with this extended output? Not yet right?

Currently the rewrite branch should be able to post the output from those events, it needs consoleChannel to have a channel ID.

Research should also be possible: https://lua-api.factorio.com/latest/events.html#on_research_finished

Now by seeing this the code you use in the control.lua is most likely the same as for a mod. So yeah would be nice imo to support both :) I might look into this tonight (the mod part) to see how this works.

Yes, it's pretty similar to a mod, it would definitely be great if we make a mod for it.

@Mattie112
Copy link

Ah, I missed the consoleChannel, will try it again tonight. Also: I will look into the modding part just to see what it takes :)

I think for a first version:
research (finish and perhaps started)
rocket launch
player dies

@AGuyNamedJens
Copy link
Owner Author

Sure thing!

You should also check out the typescript branch, there's a lot of new features there as well, such as the update checker. Eventually we'll move everything from rewrite to typescript which will eventually end up as master

@Mattie112
Copy link

Mattie112 commented Jan 28, 2022

Created a small companion mod:

https://mods.factorio.com/mod/FactorioChatBot-companion
https://github.com/Mattie112/FactorioChatBot-companion

(obviously it requires implementation by this bot but this is just an idea on what we can do)

Not 100% perfect yet, the file append is not working (so it logs only the last line). Perhaps you will miss some things now as it might write faster then the bot can read.

Do you want me to submit a PR for this? Perhaps to the typescript branch? Or the rewrite one?

(edit: found the append problem will make a new release tomorrow)

@AGuyNamedJens
Copy link
Owner Author

Interesting! You could submit a PR, sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants