CREDIT: viewtopic.php?f=25&t=47980&p=278536&hil ... le#p278536 Bob mentions that there must exist an item with the property place_result = [the entity you want to deconstruct]
Factorio has most of the code necessary to create these items for spaceship wreckage. There even exists icon graphics for all the debris!
![Image](https://forums.factorio.com/images/ext/7bf7d9f0523a78ab41c4a8759259e8f5.jpg)
The functions to create these items are in
Code: Select all
prototypes/item/demo-crash-site-item.lua
Code: Select all
local big_wreck_item = function(n)
return
{
type = "item",
name = "crash-site-spaceship-wreck-big-"..n,
icon = "__base__/graphics/icons/crash-site-spaceship-wreck-big-"..n..".png",
icon_size = 64, icon_mipmaps = 4,
subgroup = "crash-site",
order = "z[crash-site-spaceship]-b",
place_result = "crash-site-spaceship-wreck-big-"..n,
stack_size = 1,
flags = {"hidden"}
}
end
The TWO other things you need to do to make these items deconstructible, is remove the "not-deconstructable" flag...
Code: Select all
local deconstructable = {
['container'] = {
"crash-site-chest-1",
"crash-site-chest-2",
"crash-site-spaceship-wreck-big-1",
"crash-site-spaceship-wreck-big-2",
"crash-site-spaceship-wreck-medium-1",
"crash-site-spaceship-wreck-medium-2",
"crash-site-spaceship-wreck-medium-3"
},
['simple-entity-with-owner'] = {
"crash-site-spaceship-wreck-small-1",
"crash-site-spaceship-wreck-small-2",
"crash-site-spaceship-wreck-small-3",
"crash-site-spaceship-wreck-small-4",
"crash-site-spaceship-wreck-small-5",
"crash-site-spaceship-wreck-small-6"
}
}
Code: Select all
for type_, array in pairs(deconstructable) do
for _, name in pairs(array) do
for i, flag in pairs(data.raw[type_][name].flags) do
if flag == "not-deconstructable" then
table.remove(data.raw[type_][name].flags, i)
end
end
end
end
Code: Select all
local wreckage = {
"crash-site-spaceship-wreck-big-1",
"crash-site-spaceship-wreck-big-2",
"crash-site-spaceship-wreck-medium-1",
"crash-site-spaceship-wreck-medium-2",
"crash-site-spaceship-wreck-medium-3",
"crash-site-spaceship-wreck-small-1",
"crash-site-spaceship-wreck-small-2",
"crash-site-spaceship-wreck-small-3",
"crash-site-spaceship-wreck-small-4",
"crash-site-spaceship-wreck-small-5",
"crash-site-spaceship-wreck-small-6"
}
script.on_event(defines.events.on_player_created, function(event)
for i, entity in pairs(game.surfaces[1].find_entities_filtered{position = {0, 0}, radius = 50, name = wreckage}) do
entity.force = "player"
end
end)