Fix Saving
This commit is contained in:
81
lua/ge/extensions/career/vehicleRetrieval.lua
Normal file
81
lua/ge/extensions/career/vehicleRetrieval.lua
Normal file
@@ -0,0 +1,81 @@
|
||||
-- Copyright (C) 2025 snoutie
|
||||
-- Authors: snoutie (copyright@achtarmig.org)
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU Affero General Public License as published
|
||||
-- by the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
|
||||
-- This program is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU Affero General Public License for more details.
|
||||
|
||||
-- You should have received a copy of the GNU Affero General Public License
|
||||
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
local M = {}
|
||||
|
||||
M.dependencies = { 'career_modules_inventory', 'freeroam_facilities', "career_vehicleSaveSystem" }
|
||||
|
||||
local career_modules_inventory_removeVehicleObject
|
||||
local vehicleObjectsToRemove = {}
|
||||
|
||||
local function spawnVehicle(inventoryId, callback)
|
||||
if career_modules_inventory.getVehicleIdFromInventoryId(inventoryId) then
|
||||
callback()
|
||||
else
|
||||
career_modules_inventory.spawnVehicle(inventoryId, nil, callback)
|
||||
end
|
||||
end
|
||||
|
||||
local function Retrieve()
|
||||
local fav_veh_id = career_modules_inventory.getFavoriteVehicle()
|
||||
|
||||
extensions.core_jobsystem.create(
|
||||
function(job)
|
||||
spawnVehicle(fav_veh_id, function()
|
||||
local veh = be:getObjectByID(career_modules_inventory.getVehicleIdFromInventoryId(fav_veh_id))
|
||||
local location = { pos = veh:getPosition(), rot = quat(0, 0, 1, 0) * quat(veh:getRefNodeRotation()) }
|
||||
local garage = career_modules_inventory.getClosestGarage(location.pos)
|
||||
job.sleep(1)
|
||||
career_vehicleSaveSystem.LoadVehicle(fav_veh_id)
|
||||
freeroam_facilities.teleportToGarage(garage.id, veh, false)
|
||||
end)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
local function onComputerAddFunctions(menuData, computerFunctions)
|
||||
if menuData.computerFacility.functions["vehicleInventory"] then
|
||||
local computerFunctionData = {
|
||||
id = "retrieve_damaged",
|
||||
label = "Retrieve Favourite Damaged",
|
||||
callback = Retrieve,
|
||||
order = 1
|
||||
}
|
||||
if menuData.tutorialPartShoppingActive or menuData.tutorialTuningActive then
|
||||
computerFunctionData.disabled = true
|
||||
computerFunctionData.reason = career_modules_computer.reasons.tutorialActive
|
||||
end
|
||||
computerFunctions.general[computerFunctionData.id] = computerFunctionData
|
||||
end
|
||||
end
|
||||
|
||||
local function RemoveVehicleObject(inventoryId)
|
||||
table.insert(vehicleObjectsToRemove, inventoryId)
|
||||
career_vehicleSaveSystem.QueueVehicleToSave(inventoryId)
|
||||
career_vehicleSaveSystem.SaveVehicle(inventoryId)
|
||||
career_vehicleSaveSystem.CheckSavedAsync(function()
|
||||
career_modules_inventory_removeVehicleObject(inventoryId)
|
||||
end)
|
||||
end
|
||||
|
||||
local function onCareerActive()
|
||||
career_modules_inventory_removeVehicleObject = career_modules_inventory.removeVehicleObject
|
||||
career_modules_inventory.removeVehicleObject = RemoveVehicleObject
|
||||
end
|
||||
|
||||
M.onComputerAddFunctions = onComputerAddFunctions
|
||||
M.onCareerActive = onCareerActive
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user