Skip to content

Instantly share code, notes, and snippets.

@rpdelaney
Created February 8, 2022 02:02
Show Gist options
  • Save rpdelaney/75a7fab3889ebadf4fc6b6911145f7a7 to your computer and use it in GitHub Desktop.
Save rpdelaney/75a7fab3889ebadf4fc6b6911145f7a7 to your computer and use it in GitHub Desktop.
Factorio Constant Combinator item stack size signal generator
-- From "Fooluaintblack" on the TechnicalFactorio discord:
-- > Caught up with a friend and we adjusted Halke's index script to create a series
-- > of CCs with items, in item ID order, with their stack size as their signal
-- > values. The script changes include:
-- > -reorganised, whitespace, removed "count" as its redundant with "index"
-- > -overwrite the selected CC instead of creating a new one beside it
-- > -spot at the top to add signal names to exclude. You'll see magic lamp,
-- > pushbutton, and textplates are excluded. Textplate string includes wildcards
-- > to capture all signals that start with "textplate"
--
-- /c
local map={}
local excludedItems = {"magic%-lamp", "pushbutton", "textplate%-.+"}
function createStackSizeCcs()
cc = game.player.selected
index = 0
for _, item in pairs(game.item_prototypes) do
if isIncluded(item) then
if index > 0 and index % 20 == 0 then
cc = createCc(cc)
end
addSignal(cc, index % 20 + 1, item)
index = index + 1
end
end
end
function addSignal(combinator, index, item)
combinator.get_control_behavior().set_signal(index, {
signal = {
type = "item",
name = item.name
},
count = item.stack_size
})
end
function createCc(prev)
return game.player.surface.create_entity({
name = "constant-combinator",
force = game.forces.player,
position = {
x = prev.position.x + 1,
y = prev.position.y
}
})
end
function isIncluded(item)
if item.has_flag("hidden") then
return false
end
for _, pattern in ipairs(excludedItems) do
if string.find(item.name, pattern) then
return false
end
end
return true
end
createStackSizeCcs()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment