EnergyStorage Module Reference
Module defined in `lua/vehicle/energyStorage.lua`. Central manager for all vehicle energy containers (fuel tanks, batteries, N2O tanks, pressure tanks). Handles discovery from JBeam, links containers to powertrain devices that consume energy, tracks fuel levels and leak states, and manages rupture callbacks when beams break.
Module defined in lua/vehicle/energyStorage.lua. Central manager for all vehicle energy containers (fuel tanks, batteries, N2O tanks, pressure tanks). Handles discovery from JBeam, links containers to powertrain devices that consume energy, tracks fuel levels and leak states, and manages rupture callbacks when beams break.
See Also
- Energy Storage Folder: Specific container types (Fuel, Battery).
- Powertrain: For devices that consume energy.
State Fields
| Variable | Description |
|---|---|
nilStorage | Proxy for safe missing-storage access. |
Public API
| Function | Signature | Description |
|---|---|---|
beamBroke | (id) (**hook**) | Container rupture callback. |
getPartCondition | (partTypeData) (**callable**) | Health aggregation for part-linked storages. See Part Condition. Returns multiple values. |
getStorage | (name) (**callable**) | Data retrieval. Returns energyStorages[name]. |
getStorages | () (**callable**) | Full storage list. Returns energyStorages. |
getStorageSafe | (name) (**callable**) | Safety-wrapped retrieval. |
init | () (**hook**) | JBeam discovery and Powertrain linking. |
onCouplerAttached | (nodeId, obj2id, obj2nodeId, attachSpeed, attachEnergy) (**hook**) | Coupling state callback. |
onCouplerDetached | (nodeId, obj2id, obj2nodeId, breakForce) (**hook**) | Decoupling state callback. |
onCouplerFound | (nodeId, obj2id, obj2nodeId, nodeDist) (**hook**) | Discovery callback. |
onDeserialize | (data) (**hook**) | State restoration hook. |
onSerialize | () (**hook**) | Persistence hook. Returns data. |
reset | () (**hook**) | Level reset. |
setPartCondition | (partTypeData, odometer, integrity, visual) (**callable**) | Condition restoration. |
updateGFX | (dt) (**hook**) | Ratio calculation and per-storage updates. |
Usage Example
-- Get the main fuel tank and check its level
local tank = energyStorage.getStorage("mainTank")
if tank then
print("Fuel remaining: " .. (tank.remainingRatio * 100) .. "%")
end
-- Set fuel to half capacity
local tank = energyStorage.getStorage("mainTank")
if tank then
tank:setRemainingRatio(0.5)
endElectrics Custom Value Parser
Module defined in `lua/vehicle/electricsCustomValueParser.lua`. Parses and evaluates custom expression-based electrics values defined in JBeam. Allows modders to create computed electrical signals using mathematical expressions that reference other electrics values.
Extensions Module Reference
Infrastructure for managing vehicle extensions, dependency resolution, and event hooking. This module allows for modular scripts to be loaded, unloaded, and updated at runtime, providing a flexible pl