Companion Drones Gadgetroch


Companion Gadgetroch Fork: personal fork of Companion Drones for Factorio 2.1. Adds the /companion command to hand out a build/defend drone when you join a server mid-game. See mod description.

Utilities
3 months ago
2.1
367
Logistics Combat Manufacturing

g Crash on 2.1.20 - fuel category

10 days ago

Broken by the latest fuel category changes in 2.1.20

22090.535 Error MainLoop.cpp:1488: Exception at tick 127862307: The mod Companion Gadgetroch Fork (3.2.0) caused a non-recoverable error.
Please report this error to the mod author.

Error while running event companion-drones-gadgetroch::on_built_entity (ID 6)
LuaItemPrototype doesn't contain key fuel_category.
stack traceback:
[C]: in function 'index'
__companion-drones-gadgetroch
/script/companion.lua:179: in function 'get_fuel_items'
companion-drones-gadgetroch/script/companion.lua:736: in function 'try_to_refuel'
companion-drones-gadgetroch/script/companion.lua:328: in function 'new'
companion-drones-gadgetroch/script/companion.lua:1259: in function 'handler'
core/lualib/event_handler.lua:72: in function <core/lualib/event_handler.lua:70>

10 days ago

possible hotfix (around line 179:

local get_fuel_items = function(player)
    local fuel_items = {}
    for k, item in pairs(prototypes.item) do
        if item.fuel_value > 0 then
            for _, fuel_category in pairs(item.fuel_categories) do
                if fuel_category == "chemical" then
                    table.insert(fuel_items, {name = item.name, count = 1, fuel_top_speed_multiplier = item.fuel_top_speed_multiplier})
                    break
                end
            end
        end
    end

    local use_best_fuel_first = settings.get_player_settings(player)["set-fuel-preference"].value
9 days ago
(updated 9 days ago)

Possibly more performant fix. Doesn't require LUA to parse the entire list of Item Prototypes. Lets the engine do that and provide a much shorter list.

local get_fuel_items = function(player)
    local fuel_items = {}
    local chemical_fuel = prototypes.get_item_filtered({{filter = "fuel-value", comparison = ">", value = 0}, {filter = "fuel-category", ["fuel-category"] = "chemical", mode = "and"}})
    for k, item in pairs(chemical_fuel) do
        table.insert(fuel_items, { name = item.name, count = 1, fuel_top_speed_multiplier = item.fuel_top_speed_multiplier })
    end

    local use_best_fuel_first = settings.get_player_settings(player)["set-fuel-preference"].value

New response