GE Lua Documentation

Press F to search!

refuelCar

Definition


-- @/lua/ge/extensions/freeroam/gasStations.lua:121


local function refuelCar(gasStation, fuelTypes, veh)
  --ui_missionInfo.closeDialogue()
  core_vehicleBridge.requestValue(veh,
    function(ret)
      local anySuccess, allSuccess = false, true
      local fuelTranslations = {}
      local invalidTanks = {}
      for _, tank in ipairs(ret[1]) do
        if not ignoreFuelTypes[tank.energyType] then
          local fuelType = fuelTypeToFuelTranslation[tank.energyType] and tank.energyType or "unknown"
          local valid = fuelTypes['any'] or fuelTypes[tank.energyType]

          anySuccess = anySuccess or valid
          allSuccess = allSuccess and valid
          fuelTranslations[fuelTypeToFuelTranslation[fuelType]] = (fuelTranslations[fuelTypeToFuelTranslation[fuelType]] or 0) + 1
          if valid then
            if career_career.isActive() then
              career_modules_fuel.startTransaction(gasStation)
              return
            else
              core_vehicleBridge.executeAction(veh,'setEnergyStorageEnergy', tank.name, tank.maxEnergy)
            end
          else
            invalidTanks[tank.energyType] = true
          end
        end
      end
      local key = next(fuelTranslations)
      if #tableKeys(fuelTranslations) > 1 then
        key = "refuelMixed"
      end
      if anySuccess then
        if allSuccess then
          guihooks.trigger('Message',{msg = "ui.freeroam."..key..".complete", category = "refueling", icon = "check", ttl=8})
          local pos = veh:getPosition()
          Engine.Audio.playOnce('AudioGui',soundByKey[key], {position = vec3(pos.x, pos.y, pos.z)})
        else
          guihooks.trigger('Message',{msg = "ui.freeroam."..key..".partial", category = "refueling", icon = "warning", ttl=8})
        end
      else
        guihooks.trigger('Message',{msg = "ui.freeroam.refuel.failed", category = "refueling", icon = "error", ttl=8})
      end
      if not allSuccess then
        for _, fuelType in ipairs(tableKeysSorted(invalidTanks)) do
          guihooks.trigger('Message',{msg = {txt = "ui.freeroam.refuel.notFilled", context = {fuelType = translateLanguage("ui.general.fuelType."..fuelType, fuelType, true)}}, category = "refueling-"..fuelType, icon = "warning", ttl=8})
        end
      end
    end
    , 'energyStorage')
end

Callers

@/lua/ge/extensions/career/modules/vehiclePerformance.lua

local function refuelCar(veh)
  core_vehicleBridge.requestValue(veh,
      career_modules_inventory.enterVehicle(inventoryId)
      refuelCar(getObjectByID(vehId))
      return true
@/lua/ge/extensions/freeroam/gasStations.lua
      data.buttonLabel = ("ui.freeroam."..key..".prompt")
      data.buttonFun = function() M.refuelCar(elem, fuelTypes, getPlayerVehicle(0)) end
      table.insert(activityData, data)