-- for _, ammo in pairs{data.raw["ammo"]["artillery-shell"], data.raw["fluid-turret"]["flamethrower-turret"].attack_parameters} do -- local action_delivery = ammo.ammo_type.action.action_delivery -- action_delivery.source_effects = -- { -- action_delivery.source_effects, -- current effect -- {type = "script", effect_id = "turret-consume-energy"} -- } -- end -- tbl[field] should be nil, a single Trigger, or an array of Trigger's -- (Also works for TriggerDelivery's, and TriggerEffect's) -- get_trigger will either return on of the triggers, or return default_trigger, after storing it in tbl[field] function get_trigger(tbl, field, default_trigger) if not tbl[field] then -- no Triggers tbl[field] = default_trigger return tbl[field] elseif tbl[field].type then -- not an array return tbl[field] elseif #tbl[field] > 0 then -- non-empty array of Triggers return tbl[field][#tbl[field]] -- use the last Trigger else -- should be an empty array table.insert(tbl[field], default_trigger) end return tbl[field][1] end for _, ammo in pairs{data.raw["ammo"]["artillery-shell"], data.raw["fluid-turret"]["flamethrower-turret"].attack_parameters} do local action = get_trigger(ammo.ammo_type, "action", {type = "direct"}) local action_delivery = get_trigger(action, "action_delivery", {type = "instant"}) insert_trigger(action_delivery, "source_effects", {type = "script", effect_id = "turret-consume-energy"}) end -- Альтернативный вариант -- -- Similar, but inserts a new trigger -- function insert_trigger(tbl, field, new_trigger) -- if not tbl[field] then -- tbl[field] = new_trigger -- elseif tbl[field].type then -- not an array, turn it into one -- tbl[field] = {tbl[field], new_trigger} -- else -- should be an array -- tbl.insert(tbl[field], new_trigger) -- end -- return new_trigger -- end -- for _, ammo in pairs{data.raw["ammo"]["artillery-shell"], data.raw["fluid-turret"]["flamethrower-turret"].attack_parameters} do -- local action = insert_trigger(ammo.ammo_type, "action", {type = "direct"}) -- local action_delivery = insert_trigger(action, "action_delivery", {type = "instant"}) -- insert_trigger(action_delivery, "source_effects", {type = "script", effect_id = "turret-consume-energy"}) -- end