AmmoGroup


Put Ammo subgroup into a separate new “Ammo” group tab, containing all vanilla and most modded vehicles. Designed for players who have lots of modded Ammo the “Combat” tab.

Utilities
17 hours ago
1.1 - 2.1
4.61K

g 2.1版本,并且更新代码

a month ago

"
-- AmmoGroup_1.1.3/data.lua
data:extend{
{
type = "item-group",
name = "ammo",
order = settings.startup["ammogroup-order"].value,
icon = "base/graphics/technology/uranium-ammo.png",
icon_size = 256, icon_mipmaps = 4,
},
}

Write in data.lua.


-- AmmoGroup_1.1.3/data-final-fixes.lua
local dr = data.raw

-- =============================================================================
-- 1. 强迫症专属:行顺序定义表 (严格按此顺序从上到下分行)
-- =============================================================================
local category_orders = {
["bullet"] = "a", -- 第一行:常规步枪/机枪弹夹
["shotgun-shell"] = "b", -- 第二行:散弹枪弹药
["combat-robot-capsule"] = "c",-- 第三行:战斗机器人胶囊
["capsule"] = "d", -- 第四行:手雷、有毒/减速胶囊
["flamethrower"] = "e", -- 第五行:喷火燃料罐
["rocket"] = "f", -- 第六行:火箭弹
["cannon-shell"] = "g", -- 第七行:坦克炮弹
["artillery-shell"] = "h", -- 第八行:远程火炮大炮弹
["landmine"] = "i", -- 第九行:地雷/防御战术类
["laser-rifle"] = "j", -- 第十行:能量/激光武器弹药
}

-- 辅助函数:动态创建或归类子分类行
local function ensure_subgroup(sg_name, group_name, order_letter)
if not dr["item-subgroup"][sg_name] then
data:extend{{
type = "item-subgroup",
name = sg_name,
group = group_name,
order = order_letter or "z"
}}
else
dr["item-subgroup"][sg_name].group = group_name
if order_letter then
dr["item-subgroup"][sg_name].order = order_letter
end
end
end

-- =============================================================================
-- 2. 终极全量扫描:此时所有模组的物品都已到齐,开始强制分类
-- =============================================================================

-- A. 扫描并分类所有常规及魔改弹药 (type = "ammo")
if dr["ammo"] then
for item_name, item in pairs(dr["ammo"]) do
local category = "other-ammo"
if item.ammo_category then
category = item.ammo_category
elseif item.ammo_type and item.ammo_type.category then
category = item.ammo_type.category
end

    -- 生成该类弹药专属的行名称
    local sg_name = "ammo-row-" .. category
    local order = category_orders[category] or ("y-" .. category)

    -- 确保这行存在于 Ammo 大组中
    ensure_subgroup(sg_name, "ammo", order)
    -- 将这枚子弹强制塞进该行
    item.subgroup = sg_name
end

end

-- B. 兜底保障:把原版的 "ammo" 子分类也顺便搬过来,防止有漏网之鱼
if dr["item-subgroup"]["ammo"] then
dr["item-subgroup"]["ammo"].group = "ammo"
dr["item-subgroup"]["ammo"].order = "a"
end

-- C. 扫描并全量收容投掷物胶囊 (Capsules)
if dr["capsule"] then
local sg_name = "ammo-row-capsule"
ensure_subgroup(sg_name, "ammo", category_orders["capsule"])
for _, item in pairs(dr["capsule"]) do
item.subgroup = sg_name
end
end

-- D. 扫描并全量收容战术地雷 (Landmines)
if dr["land-mine"] then
local sg_name = "ammo-row-landmine"
ensure_subgroup(sg_name, "ammo", category_orders["landmine"])
for _, item in pairs(dr["land-mine"]) do
item.subgroup = sg_name
end
end

Write in data-final-fixes.lua

It works great this way.
Note that this code hasn't been updated for the 2.1 API; I simply modified your mod for personal use on version 2.0. I never released it—and couldn't be bothered to—so I'm just sharing the code here for you.

17 hours ago
(updated 17 hours ago)

FIX in version 1.1.4
Thanks for letting me know! I usually don't install experimental versions.

This thread has been locked.