-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.lua
More file actions
65 lines (55 loc) · 2 KB
/
Copy pathcontrol.lua
File metadata and controls
65 lines (55 loc) · 2 KB
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
script.on_event({defines.events.on_tick},
function (e)
if e.tick % 60 == 0 then -- only check every 1 second
for index, player in pairs(game.connected_players) do
autoCraft(player)
end
end
end
)
function autoCraft(player)
local config = settings.get_player_settings(player)
if not config["quickbarcrafting-enabled"].value then return end
if player.character == nil then return end
if player.crafting_queue_size ~= 0 then return end
-- process primary quick bar
local bar = player.get_active_quick_bar_page(1)
if craftQB(player, bar) then return end
local secondary = config["quickbarcrafting-craft-secondary"].value or false
local all = config["quickbarcrafting-craft-all"].value or false
-- process secondary quickbar
if secondary or all then
local bar = player.get_active_quick_bar_page(2)
if craftQB(player, bar) then return end
end
-- process all quick bars
if all then
for bar = 1,10 do
if craftQB(player, bar) then return end
end
end
end
-- Perform crafting in specified quick bar for player
-- returns true if something queued, false otherwise
function craftQB(player, bar)
local config = settings.get_player_settings(player)
local minimum = config["quickbarcrafting-minimum"].value
local craftamount = config["quickbarcrafting-craft-amount"].value
local notify = config["quickbarcrafting-notify"].value
local bar = bar - 1 -- Fix for 0.17.2, won't be surprised if this needs fixing again
-- loop through each item in the quick bar
for i = 1,10 do
local item = player.get_quick_bar_slot(bar*10+i)
if item ~= nil and player.get_item_count(item.name) < minimum then
-- check if this item can be crafted
local recipe = game.recipe_prototypes[item.name]
if recipe ~= nil and recipe.allow_as_intermediate then
if player.begin_crafting({count=craftamount, recipe=item.name, silent=true}) > 0 then
if notify then player.print("Quick Bar Crafting " .. item.name) end
return true -- stop at first item to craft
end
end
end
end
return false
end