Experimental Fuel Persistence Mod

Discussion in 'Mods and Skins' started by epicduck410, Dec 3, 2024.

  1. epicduck410

    epicduck410
    Expand Collapse

    Joined:
    Dec 3, 2024
    Messages:
    2
    This mod was tested across all vanilla cars, though not all configs. If you encounter any issues with vanilla vehicles, DM or post them here, and include the config you were using, if it isn't already included in the game. Issues caused by mods will not be fixed, that is up to you to add functionality for, which really isn't hard to do.

    First, unpack the mod in the mod manager. You can do that by double clicking the mod and clicking unpack.
    upload_2024-12-2_22-2-56.png
    upload_2024-12-2_22-3-10.png

    Then, click "Open in Explorer", this will bring you to the mod directory. Keep this folder open for now.

    Go into the game and spawn the car you wish to add support for. Let's say you want to add support for the Gavril Vertex. Open the console using the tilda key (~) or (`) under the escape key. Look closely at the output for the name of your vehicle:
    upload_2024-12-2_22-5-18.png
    "/vehicles/gavril_vertex/"

    Make the folder in /vehicles/ as so:
    upload_2024-12-2_22-6-25.png

    Now, copy the lua folder from the atv folder into the folder you just made.
    upload_2024-12-2_22-8-13.png
    Enter the lua folder in the new folder you just made for the car, and open fuelManager.lua.

    Copy and paste this outside of a function:

    local function printTable(tbl, indent)
    indent = indent or 0
    local indentString = string.rep(" ", indent)

    for key, value in pairs(tbl) do
    if type(value) == "table" then
    print(indentString .. tostring(key) .. ": {")
    printTable(value, indent + 1)
    print(indentString .. "}")
    else
    print(indentString .. tostring(key) .. ": " .. tostring(value))
    end
    end
    end

    And then paste this inside of the onInit() function:

    printTable(energyStorage.getStorages())

    This will provide us with the names of the fuel tanks on the car.
    upload_2024-12-2_22-12-54.png
    Save, go into the game, and press CTRL + R to reload the Lua environment. Scroll up to the printed information:
    upload_2024-12-2_22-16-20.png
    As we can see, the main fuel tank is called mainTank, and remainingVolume is the field that indicates how much fuel is left.

    With this, we can see it's already implemented into the table of storages here, meaning we don't need to do anything. However, this may not be the case for all vehicles, and some vehicles can have multiple fuel tanks, so it's still important to check. You should also check this for battery configurations.
    upload_2024-12-2_22-17-55.png
    If you did everything correctly, it should begin working. You can repack by going back to the first step and clicking "Pack", if you feel its necessary.

    This mod allows you to break your car without resetting burnt fuel. Only CTRL + R or vehicle configuration will reset your fuel level. If you think I should add more, like maybe even saving fuel across game sessions (if that's even possible), up to even mileage, feel free to pitch in ideas. I have no clue why nobody has made anything like this before as far as I know.

    Updates:
    (v1.1): Added support for the Bruckell Nine in v0.34
     

    Attached Files:

    #1 epicduck410, Dec 3, 2024
    Last edited: Jan 5, 2025
    • Like Like x 7
  2. Redknee

    Redknee
    Expand Collapse

    Joined:
    May 4, 2023
    Messages:
    24
    this is cool i hope you develop more on it
     
  3. MrMoose27

    MrMoose27
    Expand Collapse

    Joined:
    Aug 12, 2024
    Messages:
    4
    will this be getting updated for 0.34? it, at least for me, doesn't work after the update
    --- Post updated ---
    nvm
     
    • Agree Agree x 1
  4. epicduck410

    epicduck410
    Expand Collapse

    Joined:
    Dec 3, 2024
    Messages:
    2
    The latest vehicle likely needs added. I'll look into it now.
     
  5. Kizyo

    Kizyo
    Expand Collapse

    Joined:
    Mar 13, 2024
    Messages:
    1

    Yes please add a persistent odometer I am begging you cus this is a feature that I have been trying to implement all the way back in 0.23 and never got it to fn work !
     
    • Like Like x 1
  6. DonV2003

    DonV2003
    Expand Collapse

    Joined:
    Feb 7, 2025
    Messages:
    1
    Does/would this work with modded/automation vehicles? Or does it need to be physically coded fully for each car by you?

    Also, would this work in multiplayer if set up by the host? I would guess the answer would be no as it probably wouldnt be able to keep track of everyone's fuel properly.
    But in theory at least if everyone is in different cars it may work.

    Thanks

    Edit: I have tested both of these things and they work flawlessly. Even having multiple people in the same type of car works and it only resets each persons car. Overall very happy, this makes endurance races possible and i can finally force pits without going off of tire wear which is inconsistent.
     
    #6 DonV2003, Feb 7, 2025
    Last edited: Feb 12, 2025
  7. Z_M71

    Z_M71
    Expand Collapse

    Joined:
    Jan 20, 2026
    Messages:
    17
    Please add support for modded vehicles.
     
  8. JoshD

    JoshD
    Expand Collapse

    Joined:
    Dec 31, 2020
    Messages:
    1,414
    Try reading.

     
  9. Z_M71

    Z_M71
    Expand Collapse

    Joined:
    Jan 20, 2026
    Messages:
    17
     
    #9 Z_M71, Aug 22, 2026
    Last edited: Aug 30, 2026
  10. Z_M71

    Z_M71
    Expand Collapse

    Joined:
    Jan 20, 2026
    Messages:
    17
    Yes it does but you need to configure that. Here is the code that worked for me "
    local M = {}

    local storages = {{name = 'mainTank', field = 'remainingVolume', lastVolume = -1}, {name = 'mainBattery', field = 'storedEnergy', lastVolume = -1}} -- All possible storages. Any storages present on the vehicle will be managed by the script.
    -- name is the name of the storage.
    -- field is what determines the "fuel level" of the storage.
    -- lastVolume is to be ignored, but still included predefined as -1.
    local presentStorages = {}
    local scheduleFuelSet = false
    local loaded = false

    local function onInit()
    loaded = false

    -- Attempt to find valid storages based on the defined list
    for _, storage in ipairs(storages) do
    local storageRef = energyStorage.getStorage(storage.name)
    if storageRef then
    presentStorages[storage.name] = storageRef
    end
    end
    end

    local function onReset()
    if not loaded then return end

    -- Store the remaining volumes or energy from all present storages
    for _, storage in ipairs(storages) do
    local storageRef = presentStorages[storage.name]
    if storageRef then
    storage.lastVolume = storageRef[storage.field] -- Set the lastVolume using the correct field
    end
    end
    scheduleFuelSet = true
    end

    local function onUpdate()
    if scheduleFuelSet then
    -- Print fuel info for debugging
    for _, storage in ipairs(storages) do
    local storageRef = presentStorages[storage.name]
    if storageRef then
    storageRef["set" .. storage.field:sub(1, 1):upper() .. storage.field:sub(2)](storageRef, storage.lastVolume)
    end
    end
    scheduleFuelSet = false
    end

    loaded = true
    end

    M.onInit = onInit
    M.onReset = onReset
    M.updateGFX = onUpdate

    return M"
     
    #10 Z_M71, Aug 30, 2026
    Last edited: Oct 8, 2026
  11. Z_M71

    Z_M71
    Expand Collapse

    Joined:
    Jan 20, 2026
    Messages:
    17
    How to add support for all mod vehicles automatically?
     
    #11 Z_M71, Oct 4, 2026
    Last edited: Oct 5, 2026
  12. Kreunz

    Kreunz
    Expand Collapse

    Joined:
    Mar 13, 2014
    Messages:
    184
    Author hasent been online in 6 months, mod ahsent been updated since jan 2025 and theres intructiosn how to add it if you bothered to read
     
  13. Z_M71

    Z_M71
    Expand Collapse

    Joined:
    Jan 20, 2026
    Messages:
    17
     
    #13 Z_M71, Oct 5, 2026
    Last edited: Oct 6, 2026
  14. Z_M71

    Z_M71
    Expand Collapse

    Joined:
    Jan 20, 2026
    Messages:
    17
    :
     
    #14 Z_M71, Oct 7, 2026
    Last edited: Oct 8, 2026
  15. Z_M71

    Z_M71
    Expand Collapse

    Joined:
    Jan 20, 2026
    Messages:
    17
    To anyone struggling here is the code that worked for me. I made the vehicle folder and i used this code.
    "
    local M = {}

    local storages = {{name = 'mainTank', field = 'remainingVolume', lastVolume = -1}, {name = 'mainBattery', field = 'storedEnergy', lastVolume = -1}} -- All possible storages. Any storages present on the vehicle will be managed by the script.
    -- name is the name of the storage.
    -- field is what determines the "fuel level" of the storage.
    -- lastVolume is to be ignored, but still included predefined as -1.
    local presentStorages = {}
    local scheduleFuelSet = false
    local loaded = false

    local function onInit()
    loaded = false

    -- Attempt to find valid storages based on the defined list
    for _, storage in ipairs(storages) do
    local storageRef = energyStorage.getStorage(storage.name)
    if storageRef then
    presentStorages[storage.name] = storageRef
    end
    end
    end

    local function onReset()
    if not loaded then return end

    -- Store the remaining volumes or energy from all present storages
    for _, storage in ipairs(storages) do
    local storageRef = presentStorages[storage.name]
    if storageRef then
    storage.lastVolume = storageRef[storage.field] -- Set the lastVolume using the correct field
    end
    end
    scheduleFuelSet = true
    end

    local function onUpdate()
    if scheduleFuelSet then
    -- Print fuel info for debugging
    for _, storage in ipairs(storages) do
    local storageRef = presentStorages[storage.name]
    if storageRef then
    storageRef["set" .. storage.field:sub(1, 1):upper() .. storage.field:sub(2)](storageRef, storage.lastVolume)
    end
    end
    scheduleFuelSet = false
    end

    loaded = true
    end

    M.onInit = onInit
    M.onReset = onReset
    M.updateGFX = onUpdate

    return M"
     
    #15 Z_M71, Oct 8, 2026
    Last edited: Oct 8, 2026
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice