forked from DRY411S/Recipe-Output
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.lua
75 lines (70 loc) · 2.29 KB
/
control.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
-- GLOBAL defines--
local function logrecipes()
local output = "Name|Category|Group|Subgroup|Force|(Base) Craft Time|"
local prodstring, indstring
prodstring = ""
indstring = ""
local prodcount = 0
while prodcount < 6 do
prodcount = prodcount + 1
prodstring = prodstring .. "Product " .. prodcount .. " Type|Product " .. prodcount .. "|Product " .. prodcount .. " Amount|"
indstring = indstring .. "Ingredient " .. prodcount .. " Type|Ingredient " .. prodcount .. "|Ingredient " .. prodcount .. " Amount|"
end
game.write_file("recipedump.txt",output .. prodstring .. indstring .. "\n")
for _, nextforce in pairs(game.forces) do
force = nextforce
for _,v in pairs(force.recipes) do
logrecipe(v)
end
end
end
function logrecipe(recipe)
-- Dumps the recipe into a logfile
local output = ""
local prodcount = 0
output = recipe.name .. "|" .. recipe.category .. "|" .. recipe.group.name .. "|" .. recipe.subgroup.name .. "|" .. recipe.force.name .. "|" .. recipe.energy .. "|"
for _,p in pairs(recipe.products) do
prodcount = prodcount + 1
if p.type ~= nil then
output = output .. p.type .. "|"
else
output = output .. "|"
end
output = output .. p.name .. "|"
if p.amount ~= nil then
output = output .. p.amount .. "|"
else
output = output .. "1|"
end
end
while prodcount < 6 do
prodcount = prodcount + 1
output = output .. "|||"
end
prodcount = 0
for _,p in pairs(recipe.ingredients) do
if p.type ~= nil then
output = output .. p.type .. "|"
else
output = output .. "|"
end
output = output .. p.name .. "|"
if p.amount ~= nil then
output = output .. p.amount .. "|"
else
output = output .. "1|"
end
end
while prodcount < 6 do
prodcount = prodcount + 1
output = output .. "|||"
end
output = output .. "\n"
game.write_file("recipedump.txt",output,true)
end
-- LOCAL Variables
local force = nil
script.on_init(logrecipes)
script.on_event(defines.events.on_player_created, function(event)
game.players[event.player_index].print{"recipe.dump"}
end)