dying_trigger_effect: if a unit dies on a certain tile, replace that tile with another

Place to get help with not working mods / modding interface.
User avatar
adamwong246
Fast Inserter
Fast Inserter
Posts: 148
Joined: Tue Dec 01, 2020 5:01 am
Contact:

dying_trigger_effect: if a unit dies on a certain tile, replace that tile with another

Post by adamwong246 »

I'm trying to suss this out: if a unit dies on a `garbageFill` or a `sacrificezoneFill`, it should replace that tile with a landfill tile. I haven't so far been able to find the correct combination of collision masks. Perhaps some other mechanism exists?

Code: Select all

local CollisionMaskUtil = require("__core__.lualib.collision-mask-util");
local layer1 = CollisionMaskUtil.get_first_unused_layer();

-- you CAN pave over Garbage
local garbageFillMask = {layer1}

-- you CAN NOT pave over a Sacfice Zone
local sacrificeZoneMask = {layer1, "water-tile", "floor-layer", "item-layer", "object-layer"}

for _, unit in pairs(data.raw.unit) do

    if not unit.dying_trigger_effect then
        unit.dying_trigger_effect = {};
    end
    table.insert(unit.dying_trigger_effect, {
        type = "set-tile",
        tile_name = "landfill",
        radius = 5,
        apply_projection = true,
        tile_collision_mask = {layer1}; -- {"water-tile", "floor-layer", "item-layer", "object-layer"}
    });

    data:extend({unit});
end
User avatar
adamwong246
Fast Inserter
Fast Inserter
Posts: 148
Joined: Tue Dec 01, 2020 5:01 am
Contact:

Re: dying_trigger_effect: if a unit dies on a certain tile, replace that tile with another

Post by adamwong246 »

solution:

Code: Select all

local CollisionMaskUtil = require("__core__.lualib.collision-mask-util");
local nonToxicTiles = CollisionMaskUtil.get_first_unused_layer();

for _, tile in pairs(data.raw.tile) do
    table.insert(tile.collision_mask, nonToxicTiles);
    data:extend({tile});
end


local toxicTiles = CollisionMaskUtil.get_first_unused_layer();


-- you CAN pave over Garbage
local garbageFillMask = {toxicTiles}

-- you CAN NOT pave over a Sacfice Zone
local sacrificeZoneMask = {toxicTiles, "water-tile", "floor-layer", "item-layer", "object-layer"}


for _, unit in pairs(data.raw.unit) do

    if not unit.dying_trigger_effect then
        unit.dying_trigger_effect = {};
    end
    table.insert(unit.dying_trigger_effect, {
        type = "set-tile",
        tile_name = "landfill",
        radius = 5,
        apply_projection = true,
        tile_collision_mask =  {nonToxicTiles}
    });

    data:extend({unit});
end
Post Reply

Return to “Modding help”