GE Lua Documentation

Press F to search!

switchCycleVehicle

Definition


-- @/lua/ge/extensions/core/input/vehicleSwitching.lua:14

local function switchCycleVehicle(player, dir)
  player = player or 0
  -- custom order only if vehicleOrder is present, otherwise default behaviour
  if vehicleOrder ~= nil and #vehicleOrder > 0 then
    local currentId = be:getPlayerVehicleID(player)
    local currentIndex = tableFindKey(vehicleOrder, currentId) or lastIndex
    if currentIndex ~= -1 then
      -- cycle index
      local nextIndex = (currentIndex + dir)
      if nextIndex > #vehicleOrder then
        nextIndex = nextIndex - #vehicleOrder
      elseif nextIndex < 1 then
        nextIndex = nextIndex + #vehicleOrder
      end

      local nextId = vehicleOrder[nextIndex]
      if scenetree.findObjectById(nextId) then
        if be then
          be:enterVehicle(player, scenetree.findObjectById(nextId))
          extensions.hook('trackNewVeh')
        end
        return
      else
        log("E","","Tried switching with custom order to vehicle, but vehicle not found! ")
        vehicleOrder = nil
      end
    else
      log("E","","Tried switching with custom order to vehicle, but player is not in a vehicle in the list!")
      vehicleOrder = nil
    end
  end

  -- if no success with custom order, use default behaviour
  if be then
    be:enterNextVehicle(player, dir)
    extensions.hook('trackNewVeh')
  end
end

Callers

@/ui/ui-vue/mockdata/inputBindings.js
                "title": "ui.inputActions.gameplay.switch_next_vehicle.title",
                "onDown": "extensions.core_input_vehicleSwitching.switchCycleVehicle(PLAYER, 1)",
                "order": 11,
                "title": "ui.inputActions.gameplay.switch_previous_vehicle.title",
                "onDown": "extensions.core_input_vehicleSwitching.switchCycleVehicle(PLAYER, -1)",
                "order": 10,