Universal Turret_fix

by Fr_Dae

One Turret, Any Ammo.

Content
3 years ago
0.18 - 1.0
17
Combat

b Rocket crash

4 years ago

Replying to this:

if you put 2 different rocket on turret, game crash.

I get this error message:

Error while running event uniturret_Fix::on_tick (ID 0)
Unknown item name: uniammo-rocket
stack traceback:
    __uniturret_Fix__/control.lua:473: in function <__uniturret_Fix__/control.lua:375>

So, the item "uniammo-rocket" has never been defined. Why? Let's have a look at data-final-fixes.lua (line 23 ff.):

ignore_ammo = {
["rocket"] = true,
["atomic-bomb"] = true,
}
local technologies = {}
for name, value in pairs(data.raw.ammo) do
    if value.ammo_type and not ignore_ammo[value.name] and (value.ammo_type.category == "rocket" or value.ammo_type.category == "railgun" or value.ammo_type.category == "cannon-shell") then
        local ammo = table.deepcopy(value)
        technologies[ammo.name]=true
        if settings.startup["uniturret-use-seperate-recipes"].value then
            table.insert(extend, {
                type = "recipe",
                name = "uniammo-"..ammo.name,
                enabled = false,
                energy_required = 1,
                ingredients =
                {
                {"electronic-circuit", 1},
                {ammo.name, 1},
                },
                result = "uniammo-"..ammo.name
            })
        else

It's reasonable not to load rockets or nuclear bombs into a turret that may shoot enemies at a short distance. But if you want your turret being able to shoot these, you should remove these types from the ignore list.

This would fix the bug with missing rockets. But suppose some mod decided to remove some ammo entirely! It would be a good idea to safeguard against that as well. So, let's look again at the original crash:

Error while running event uniturret_Fix::on_tick (ID 0)
Unknown item name: uniammo-rocket
stack traceback:
    __uniturret_Fix__/control.lua:473: in function <__uniturret_Fix__/control.lua:375>

Somewhere around that line, you should add a check:

for name,count in pairs(contents) do
   if string.sub(name,1,8) ~="uniammo-" and not ignore_ammo[ammo] then
replace_ammo = name
replace_ammo_count = count
inventory.remove{name = replace_ammo, count = replace_ammo_count}
inventory.insert{name = "uniammo-"..replace_ammo, count = replace_ammo_count}

Only proceed if the prototype exists:

for name,count in pairs(contents) do
   if string.sub(name,1,8) ~="uniammo-" and not ignore_ammo[ammo] and game.item_prototypes["uniammo-" .. name] then

Hope that helps! :-)

4 years ago

hello, thanks Pi for you help
could you contact me on discord ?
Dae#5125 =)

4 years ago

Sorry, I'm not on any social networks, just on the Factorio forum. You could PM me there, though...

4 years ago

Dae.anthony@gmail.com
i need your help you you can =)

New response