Flamethrower Fluid


Adds a fluid version of flamethrower ammo, for use in flamethrower turrets.

Content
a month ago
0.16 - 2.0
1.48K
Combat

i Fix the technology

29 days ago
(updated 29 days ago)

Hello! I like the idea of ​​your mod.

But it has a poorly developed issue of unlocking recipes.

I am currently finalizing my mod My_add_pack_0.0.4. And specifically for flamethrower upgrades like yours, I created a technology:
https://i.postimg.cc/KYdbmxkn/Fire-weapon-upgrades.png

data:extend({
{
type = "technology",
name = "Fire-weapon-upgrades",
icon = "My_add_pack/graphics/dragons-breath-shotgun-pellet/Fire-weapon-upgrades.png",
icon_size = 256,
effects =
{
{
type = "unlock-recipe",
recipe = ""
}
},
prerequisites = {"flamethrower", "advanced-oil-processing", "military-3"},
unit =
{
count = 50,
ingredients =
{
{"automation-science-pack", 1},
{"logistic-science-pack", 1},
{"chemical-science-pack", 1},
{"military-science-pack", 1}
},
time = 15
}
}
})

Unfortunately, I was unable to bind your recipes to this technology via dependency.

I suggest you create this technology in your mod. And then I will bind my recipes to it.

Or this technology will be in my mod, and you will add a conditional dependency with overriding recipes.

Thanks!

29 days ago

Or, if you don't mind, can I integrate your code into my mod?

25 days ago

I'm not sure what you are asking for. This mod (in data-updates) searches for any techs that unlock normal flamethrower ammo and add the fluid and ammo recipes to its unlocks. Unless I'm misunderstanding what you're saying, just add this mod as an optional dependency (to ensure it runs afterwards) to yours and do the same thing in reverse (search techs for anything unlocking my recipes and remove them), and add them to your tech instead.

24 days ago

Unfortunately, it doesn't work that way. I wrote in data-updates.lua:

if mods["flamethrower-fluid"] then

if data.raw.technology["flamethrower-ammo"] then
    for i = 1, #data.raw.technology["flamethrower-ammo"].effects do
        effect = data.raw.technology["flamethrower-ammo"].effects[i]
        if effect.type == "unlock-recipe" and effect.recipe == "flamethrower-fuel" then
            index = i
        end
    end

    table.remove(data.raw.technology["flamethrower-ammo"].effects, index)
end

if data.raw.technology["flamethrower-ammo"] then
    for i = 1, #data.raw.technology["flamethrower-ammo"].effects do
        effect = data.raw.technology["flamethrower-ammo"].effects[i]
        if effect.type == "unlock-recipe" and effect.recipe == "improved-flamethrower-ammo" then
            index = i
        end
    end

    table.remove(data.raw.technology["flamethrower-ammo"].effects, index)
end

end

It works with other mods, but not with yours..

23 days ago

That's because you're checking a tech that doesn't exist. Flamethrower Fluid doesn't add a "flamethrower-ammo" tech, it looks for any tech that unlocks normal ammo (under vanilla, only the "flamethrower" tech) and adds the new recipes to the unlocks. To [re]move them, you're going to have to do the same thing.

23 days ago
(updated 23 days ago)

Unfortunately, I don't have enough programming skills to take your advice

Actually, flamethrower-ammo technology does exist. This is a vanilla technology that actually unlocks the flamethrower-ammo recipe of the same name

You can achieve the same result, but in a simpler and less hemorrhoidal way:

You just need to replace this:
for ,t in pairs(data.raw.technology) do
for
,e in pairs(t.effects or {}) do
if e.type == "unlock-recipe" then
if e.recipe == "flamethrower-ammo" then
table.insert(t.effects,{type = "unlock-recipe",recipe = "flamethrower-fuel"})
table.insert(t.effects,{type = "unlock-recipe",recipe = "improved-flamethrower-ammo"})
end
end
end
en

To this:

if data.raw.technology["flamethrower-ammo"] then
table.insert(data.raw["technology"]["flamethrower-ammo"].effects, {type = "unlock-recipe",recipe = "flamethrower-fuel"})
table.insert(data.raw["technology"]["flamethrower-ammo"].effects, {type = "unlock-recipe",recipe = "improved-flamethrower-ammo"})
end

And then life would become a little easier.....

23 days ago
(updated 21 days ago)

I'm not sure what version of Factorio you're playing on, but mine doesn't have a "flamethrower-ammo" technology. In any case, Flamethrower Fluid is written to be flexible with any mods that add (or move) the basic ammo unlock, at least in the data.lua stage, and I want it to stay that way.

Try this in your data-updates:

if mods["flamethrower-fluid"] and true then
    for _,t in pairs(data.raw.technology) do
        if t.effects then
            for i=#t.effects,1,-1 do
                local e = t.effects[i]
                if e.type == "unlock-recipe" then
                    if e.recipe == "flamethrower-fuel" or e.recipe == "improved-flamethrower-ammo" then
                        t.effects[i] = t.effects[#t.effects]
                        t.effects[#t.effects] = nil
                    end
                end
            end
        end
    end

    --<re-add the unlocks to your intended technology here, omitted for line length>
end

Sorry for the many edits (if you managed to be here when I kept changing things). Markdown is not something I'm familiar with.

23 days ago
(updated 23 days ago)

Sorry! I just now discovered my mistake. Instead of:

if data.raw.technology["flamethrower-ammo"] then

I should have written:

if data.raw.technology["flamethrower"] then

And now my scripts work!!!

p.s.

Unfortunately, the code you suggested does not work. It shows the error:

The following mods failed to load:My_add_pack_updated/data-updates.lua:213: attempt to index global 'a' (a nil value)

23 days ago

Oops, typo'd it. That should be e.recipe == "improved-flamethrower-ammo", not a.recipe

23 days ago
(updated 23 days ago)

Unfortunately, a new error popped up:

Failed to load the following mods:My_add_pack_updated/data-updates.lua:214: table index is nil

Okay... The main thing is that my scripts worked.

Thanks for your help! Sorry for bothering you.

23 days ago

This is what I get for cobbling together code in text and not testing :D

The n should be i. Hopefully that's the last issue. I'd test it just to be sure but I'm just on my phone right now.

22 days ago

I have to disappoint you again... It worked only partially.

Only "flamethrower-fuel" was deleted. But "improved-flamethrower-ammo" remained.

21 days ago

I tested it this time (though not exhaustively), so it should work now. In my earlier code I thought I was taking advantage of Factorio's custom "more deterministic" implementation of pairs() but I guess I forgot something about how it worked, so the new version should be fine (as well as being better general Lua). I updated the earlier post.

21 days ago

THANK YOU VERY VERY MUCH!!!

Your code not only helped me integrate your mod with mine, but also helped me optimize the code of my own mod!!!

I also made a similar version for "prerequisites" based on your code:

for _,t in pairs(data.raw.technology) do
    if t.prerequisites then
        for i=#t.prerequisites,1,-1 do
            local e = t.prerequisites[i]
            if e == "fuel-processing" then
                    t.prerequisites[i] = t.prerequisites[#t.prerequisites]
                    t.prerequisites[#t.prerequisites] = nil
                end
            end
        end
    end

It is needed less often, but in cases where there is more than one "prerequisite" - it helps.

New response