From b67054f3dedefc4dbd983a75c1a600ad5cf5c8db Mon Sep 17 00:00:00 2001 From: ddidderr Date: Tue, 30 Dec 2025 11:00:06 +0100 Subject: [PATCH] 1.1.0 --- README.md | 38 ++++++++++++++++++++++--------------- control.lua | 45 ++++++++++++++++++++++++++++++++++++++++---- info.json | 14 +++++++------- locale/en/locale.cfg | 5 +++++ settings.lua | 10 ++++++++++ 5 files changed, 86 insertions(+), 26 deletions(-) create mode 100644 locale/en/locale.cfg create mode 100644 settings.lua diff --git a/README.md b/README.md index a0c6894..f1c99d9 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,23 @@ -# no-stone-wall-alarm Factorio Mod - -## Purpose -Disables the alarm sound and notifications for destroyed stone walls and construction robots. - -## Installation -Install via https://mods.factorio.com/mod/no-stone-wall-alarm or directly in-game. - -## License -GPLv3 only. - -## Quirks -The ghosts for Stone Walls will look wrong (not like the wall was destroyed, but like you manually placed ghosts). - -Note: This mod suppresses the `on_entity_died` events for stone walls and construction robots. If you have other mods that rely on these events for those items, then you shouldn't use this mod. +# no-stone-wall-alarm Factorio Mod + +## Purpose +Disables the alarm sound and notifications for destroyed entities (configurable). +Default entities: +- Stone walls +- Construction robots +- Land mines + +Add more entities via the mod settings. It's a comma-separated list of entity names. + +You can lookup those names here: https://wiki.factorio.com/Data.raw#item + +## Installation +Install via https://mods.factorio.com/mod/no-stone-wall-alarm or directly in-game. + +## License +GPLv3 only. + +## Quirks +The ghosts for destroyed entities will look wrong (not like they were destroyed, but like you manually placed ghosts). + +Note: This mod suppresses the `on_entity_died` events for your configured entities. If you have other mods that rely on these events for those items, then you shouldn't use this mod. diff --git a/control.lua b/control.lua index ed001d9..cb05ab2 100644 --- a/control.lua +++ b/control.lua @@ -1,8 +1,45 @@ +local function split_string_to_map(str, separator) + local parts = {} + for part in string.gmatch(str, "([^" .. separator .. "]+)") do + -- Trim leading/trailing whitespace: + part = part:gsub("^%s*(.-)%s*$", "%1") + parts[part] = true + end + return parts + end + +local no_alarm_entities = {} +local no_ghost_possible_entities = { + ["car"] = true, + ["tank"] = true, + ["construction-robot"] = true, + ["logistic-robot"] = true, + ["player"] = true +} + +local function build_no_alarm_table(setting_value) + no_alarm_entities = split_string_to_map(setting_value, ",") +end + +script.on_init(function() + build_no_alarm_table(settings.global["no-alarm-entities"].value) +end) + +script.on_load(function() + build_no_alarm_table(settings.global["no-alarm-entities"].value) +end) + +script.on_event(defines.events.on_runtime_mod_setting_changed, function(event) + if event.setting == "no-alarm-entities" then + build_no_alarm_table(settings.global["no-alarm-entities"].value) + end +end) + script.on_event(defines.events.on_entity_damaged, function(event) local entity = event.entity - -- Check if the damaged entity is a stone wall or a construction robot - if entity and entity.valid and (entity.name == "stone-wall" or entity.name == "construction-robot") then + -- Check if the damaged entity is in our list of no-alarm entities + if entity and entity.valid and no_alarm_entities[entity.name] then -- Check if the damage would destroy the entity if event.final_health <= 0 then local surface = entity.surface @@ -17,8 +54,8 @@ script.on_event(defines.events.on_entity_damaged, function(event) -- Check if the force has researched ghost placement if force.technologies["construction-robotics"] and force.technologies["construction-robotics"].researched then - -- Don't create a ghost for construction robots (not possible) - if name == "construction-robot" then + -- Don't create a ghost for entities that cannot have a ghost + if no_ghost_possible_entities[name] then return end diff --git a/info.json b/info.json index 10a1221..b56c33a 100644 --- a/info.json +++ b/info.json @@ -1,8 +1,8 @@ { - "name": "no-stone-wall-alarm", - "version": "1.0.1", - "title": "No Stone Wall and Construction Robot Alarm", - "author": "ddidderr", - "description": "Disables the alarm sound and notifications for destroyed stone walls and construction robots.", - "factorio_version": "2.0" - } + "name": "no-stone-wall-alarm", + "version": "1.1.0", + "title": "No Stone Wall, Construction Robot, Land Mine Alarm", + "author": "ddidderr", + "description": "Disables the alarm sound and notifications for destroyed items (configurable).", + "factorio_version": "2.0" +} diff --git a/locale/en/locale.cfg b/locale/en/locale.cfg new file mode 100644 index 0000000..89edae7 --- /dev/null +++ b/locale/en/locale.cfg @@ -0,0 +1,5 @@ +[mod-setting-name] +no-alarm-entities=Entities that don't trigger an alarm on destruction + +[mod-setting-description] +no-alarm-entities=Comma-separated list of entity names that won't trigger an alarm when destroyed diff --git a/settings.lua b/settings.lua new file mode 100644 index 0000000..5a7b889 --- /dev/null +++ b/settings.lua @@ -0,0 +1,10 @@ +data:extend({ + { + type = "string-setting", + name = "no-alarm-entities", + setting_type = "runtime-global", + default_value = "stone-wall,construction-robot,land-mine", + allow_blank = true, + order = "a" + } +})