Fix Spawning and Better Saving
This commit is contained in:
parent
3aaaa3a15f
commit
9517395e1e
@ -18,49 +18,79 @@ local M = {}
|
|||||||
M.dependencies = { 'career_career', 'career_modules_computer', 'career_modules_inventory', 'career_modules_payment',
|
M.dependencies = { 'career_career', 'career_modules_computer', 'career_modules_inventory', 'career_modules_payment',
|
||||||
'career_modules_playerAttributes' }
|
'career_modules_playerAttributes' }
|
||||||
|
|
||||||
local function tprint(tbl, indent)
|
local function getVehicleSavesFolder(savePath)
|
||||||
if not indent then indent = 0 end
|
return savePath .. "/career/_vehicle_saves"
|
||||||
local toprint = string.rep(" ", indent) .. "{\r\n"
|
|
||||||
indent = indent + 2
|
|
||||||
for k, v in pairs(tbl) do
|
|
||||||
toprint = toprint .. string.rep(" ", indent)
|
|
||||||
if (type(k) == "number") then
|
|
||||||
toprint = toprint .. "[" .. k .. "] = "
|
|
||||||
elseif (type(k) == "string") then
|
|
||||||
toprint = toprint .. k .. "= "
|
|
||||||
end
|
end
|
||||||
if (type(v) == "number") then
|
|
||||||
toprint = toprint .. v .. ",\r\n"
|
local function getInventoryIdFolder(vehicleSavesPath, inventoryId)
|
||||||
elseif (type(v) == "string") then
|
return vehicleSavesPath .. "/" .. inventoryId
|
||||||
toprint = toprint .. "\"" .. v .. "\",\r\n"
|
end
|
||||||
elseif (type(v) == "table") then
|
|
||||||
toprint = toprint .. tprint(v, indent + 2) .. ",\r\n"
|
local function getInventoryIdFile(inventoryIdPath)
|
||||||
|
return inventoryIdPath .. "/save.json"
|
||||||
|
end
|
||||||
|
|
||||||
|
local function createFolderIfNeeded(path)
|
||||||
|
if not FS:directoryExists(path) then
|
||||||
|
FS:directoryCreate(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function prepareFolders(inventoryId)
|
||||||
|
local _, savePath = career_saveSystem.getCurrentSaveSlot()
|
||||||
|
local vehicleSavesFolder = getVehicleSavesFolder(savePath)
|
||||||
|
createFolderIfNeeded(vehicleSavesFolder)
|
||||||
|
|
||||||
|
local inventoryIdFolder = getInventoryIdFolder(vehicleSavesFolder, inventoryId)
|
||||||
|
createFolderIfNeeded(inventoryIdFolder)
|
||||||
|
|
||||||
|
return getInventoryIdFile(inventoryIdFolder)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onSave(inventoryId)
|
||||||
|
local fileName = prepareFolders(inventoryId)
|
||||||
|
|
||||||
|
local vehicleId = career_modules_inventory.getVehicleIdFromInventoryId(inventoryId)
|
||||||
|
if vehicleId then
|
||||||
|
local object = be:getObjectByID(vehicleId)
|
||||||
|
object:queueLuaCommand('beamstate.save("' .. fileName .. '")')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function onLoad(inventoryId)
|
||||||
|
local fileName = prepareFolders(inventoryId)
|
||||||
|
|
||||||
|
local vehicleId = career_modules_inventory.getVehicleIdFromInventoryId(inventoryId)
|
||||||
|
if vehicleId then
|
||||||
|
local object = be:getObjectByID(vehicleId)
|
||||||
|
object:queueLuaCommand('beamstate.load("' .. fileName .. '")')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function spawnVehicle(inventoryId, callback)
|
||||||
|
if career_modules_inventory.getVehicleIdFromInventoryId(inventoryId) then
|
||||||
|
callback()
|
||||||
else
|
else
|
||||||
toprint = toprint .. "\"" .. tostring(v) .. "\",\r\n"
|
career_modules_inventory.spawnVehicle(inventoryId, nil, callback)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
toprint = toprint .. string.rep(" ", indent - 2) .. "}"
|
|
||||||
return toprint
|
|
||||||
end
|
|
||||||
|
|
||||||
local function retrieve_favourite()
|
local function retrieve_favourite()
|
||||||
local fav_veh_id = career_modules_inventory.getFavoriteVehicle()
|
local fav_veh_id = career_modules_inventory.getFavoriteVehicle()
|
||||||
local vid = career_modules_inventory.getVehicleIdFromInventoryId(fav_veh_id)
|
|
||||||
|
|
||||||
if vid then
|
|
||||||
local old_veh = be:getObjectByID(vid)
|
|
||||||
old_veh:queueLuaCommand("beamstate.save()")
|
|
||||||
end
|
|
||||||
|
|
||||||
extensions.core_jobsystem.create(
|
extensions.core_jobsystem.create(
|
||||||
function(job)
|
function(job)
|
||||||
job.sleep(0.2)
|
onSave(fav_veh_id)
|
||||||
local veh = career_modules_inventory.spawnVehicle(fav_veh_id, 2)
|
job.sleep(1)
|
||||||
local vehh = be:getObjectByID(career_modules_inventory.getVehicleIdFromInventoryId(fav_veh_id))
|
spawnVehicle(fav_veh_id, function()
|
||||||
local location = { pos = vehh:getPosition(), rot = quat(0, 0, 1, 0) * quat(vehh:getRefNodeRotation()) }
|
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)
|
local garage = career_modules_inventory.getClosestGarage(location.pos)
|
||||||
freeroam_facilities.teleportToGarage(garage.id, vehh, false)
|
|
||||||
veh:queueLuaCommand("beamstate.load()")
|
onLoad(fav_veh_id)
|
||||||
|
job.sleep(1)
|
||||||
|
freeroam_facilities.teleportToGarage(garage.id, veh, false)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -84,10 +114,7 @@ end
|
|||||||
local function onSaveCurrentSaveSlot(currentSavePath, oldSaveDate, vehiclesThumbnailUpdate)
|
local function onSaveCurrentSaveSlot(currentSavePath, oldSaveDate, vehiclesThumbnailUpdate)
|
||||||
local vs = career_modules_inventory.getVehicles()
|
local vs = career_modules_inventory.getVehicles()
|
||||||
for id, _ in pairs(vs) do
|
for id, _ in pairs(vs) do
|
||||||
local vid = career_modules_inventory.getVehicleIdFromInventoryId(id)
|
onSave(id)
|
||||||
|
|
||||||
local veh = be:getObjectByID(vid)
|
|
||||||
veh:queueLuaCommand("beamstate.save()")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user