This commit is contained in:
2025-12-30 11:00:06 +01:00
parent 24fefbcbea
commit b67054f3de
5 changed files with 86 additions and 26 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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"
}

5
locale/en/locale.cfg Normal file
View File

@@ -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

10
settings.lua Normal file
View File

@@ -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"
}
})