Guides

External Fuel Script

If the built-in fuel script isn't sufficient for your needs, an external fuel script can be used.

Edit GetFuelLevel

To make use of an the external fuel script of your choice, you will need to edit the GetFuelLevel function in functions.lua.
We will use BigDaddy-Fuel as an example external fuel script.

Open functions.lua in the rhud resource folder in the text editor of your choice.1

Go to your external fuel script's documentation (if it has one) and find the export that retrieves the fuel level.
For BigDaddy-Fuel, this export is exports['BigDaddy-Fuel']:GetFuel(vehicle).

Replace the contents of the GetFuelLevel function to return the fuel level using the external fuel script's export.

functions.lua
--- Gets the fuel level of a vehicle. Used by all vehicle modules.
--- @param veh integer The vehicle handle.
--- @return number fuel The fuel level of the vehicle as a percentage.
function GetFuelLevel(veh)
  local max = GetVehicleHandlingFloat(veh, 'CHandlingData', 'fPetrolTankVolume') 
  local fuel = GetVehicleFuelLevel(veh) 
  return (fuel / max) * 100
  return exports['BigDaddy-Fuel']:GetFuel(veh) 
end

Save functions.lua and restart rHUD or your server.

Add Dependency (Optional)

To ensure that rHUD starts after the external fuel script, you can add the external fuel script as a dependency of rHUD in its fxmanifest.lua.

fxmanifest.lua
-- above contents of fxmanifest.lua ...
 
dependency '/assetpacks' 
dependencies { 
  '/assetpacks', 
  'BigDaddy-Fuel', 
} 

Footnotes

  1. See Recommended Tools for the recommended text editor (VSCode) and its extensions.

On this page