diff --git a/control-util.lua b/control-util.lua new file mode 100644 index 0000000..968b924 --- /dev/null +++ b/control-util.lua @@ -0,0 +1,23 @@ +local me = require("me") + +local util = {} +util.me = me + +function decode(data) + if type(data) == "string" then return data end + local str = {} + for i = 2, #data do + str[i-1] = decode(data[i]) + end + return table.concat(str, "") +end + +function util.get_list() + local p = game.item_prototypes[me.name.."-list"] + if p then + data = p.localised_description + return decode(data) + end +end + +return util diff --git a/control.lua b/control.lua new file mode 100644 index 0000000..2afa613 --- /dev/null +++ b/control.lua @@ -0,0 +1,16 @@ +local util = require("control-util") + +function on_console_chat(event) + if event.message and string.lower(event.message) == "bzlist" then + local player = game.players[event.player_index] + if player and player.connected then + local list = util.get_list() + if list and #list>0 then + local filename = util.me.name..".txt" + game.write_file(filename, list, false, event.player_index) + player.print("Wrote recipes to script-output/"..filename) + end + end + end +end +script.on_event(defines.events.on_console_chat, on_console_chat)