Skip to content

Commit 89cb817

Browse files
committed
feat: LocationToString to print LevelName as well
feat: Check if player is already in the right Level before trying to load fix: Presaved locations
1 parent 98fe4dc commit 89cb817

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

scripts/LocationsManager.lua

+19-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ local LocationsManager = {}
99
function LocationToString(Location)
1010
if not Location or not Location.Name then return "" end
1111

12-
return Location.Name .. ": Coordinates " .. VectorToString(Location.Location) .. ", Rotation: " .. RotatorToString(Location.Rotation)
12+
local result = Location.Name .. ": Coordinates " .. VectorToString(Location.Location) .. ", Rotation: " .. RotatorToString(Location.Rotation)
13+
if Location.LevelName then
14+
result = result .. ", LevelName: " .. Location.LevelName
15+
end
16+
return result
1317
end
1418

1519
---@param Name string
@@ -77,14 +81,20 @@ function LocationsManager.LoadLocation(Name)
7781
local myPlayer = AFUtils.GetMyPlayer()
7882
if myPlayer then
7983
if location.LevelName then
80-
local outSuccess = { bSuccess = false }
81-
local outNotLoaded = { bNotLoaded = false }
82-
AFUtils.GetLevelStreamingCustom():LoadStreamLevel(myPlayer, location.LevelName, true, false, outSuccess, outNotLoaded)
83-
LogDebug("LoadLocation: LoadStreamLevel Success: ", outSuccess.bSuccess)
84-
LogDebug("LoadLocation: LoadStreamLevel NotLoaded: " .. outNotLoaded.bNotLoaded)
85-
if not outSuccess or not outSuccess.bSuccess then
86-
LogError("LoadLocation: Failed to LoadStreamLevel, LevelName: " .. location.LevelName)
87-
return false
84+
local myPlayerController = AFUtils.GetMyPlayerController()
85+
if myPlayerController and myPlayerController.ActiveLevelName:ToString() ~= location.LevelName then
86+
LogDebug("LoadLocation: ActiveLevelName: " .. myPlayerController.ActiveLevelName:ToString())
87+
local outSuccess = { bSuccess = false }
88+
local outNotLoaded = { bNotLoaded = false }
89+
LogDebug("LoadLocation: LoadStreamLevel with name: " .. location.LevelName)
90+
local steamLevel = AFUtils.GetLevelStreamingCustom():LoadStreamLevel(myPlayerController:GetWorld(), location.LevelName, false, false, outSuccess, outNotLoaded)
91+
LogDebug("LoadLocation: LoadStreamLevel Success: ", outSuccess.bSuccess)
92+
LogDebug("LoadLocation: LoadStreamLevel NotLoaded: ", outNotLoaded.bNotLoaded)
93+
if not outSuccess or not outSuccess.bSuccess then
94+
LogError("LoadLocation: Failed to LoadStreamLevel, LevelName: " .. location.LevelName)
95+
end
96+
else
97+
LogDebug("LoadLocation: Skip LoadStreamLevel, ActiveLevelName and location LevelName are the same")
8898
end
8999
else
90100
LogInfo("LoadLocation: Warning! Loading a Location wtihout a LevelName!")

scripts/Settings.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local BaseUtils = require("AFUtils.BaseUtils.BaseUtils")
88
---@field Rotation FRotator
99

1010
---@param Name string
11-
---@field LevelName string
11+
---@param LevelName string
1212
---@param Location FVector
1313
---@param Rotation FRotator?
1414
---@return LocationStruct
@@ -50,9 +50,9 @@ Settings = {
5050
InventorySlotCount = -1,
5151
DistantShore = false,
5252
Locations = {
53-
LocationStruct("Cafeteria", "Facility_Office1", FVector(12529, 128, -15377)),
54-
LocationStruct("Flathill", "V_FOG", FVector(335956, 1294, 6203)),
55-
LocationStruct("Distant Shore", "V_DistantShore", FVector(331136, -334205, 906)),
53+
LocationStruct("Cafeteria", "Facility_Office1", FVector(-15314, 12532, 128), FRotator(0, 359, 0)),
54+
LocationStruct("Flathill", "V_FOG", FVector(6275, 337158, 1294), FRotator(358, 268, 0)),
55+
LocationStruct("Distant Shore", "V_DistantShore", FVector(331428, -334214, 908), FRotator(1, 3, 0)),
5656
}, ---@type LocationStruct[]
5757
}
5858

scripts/main.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
local AFUtils = require("AFUtils.AFUtils")
1111

1212
ModName = "CheatConsoleCommands"
13-
ModVersion = "1.8.0"
13+
ModVersion = "1.8.1"
1414
DebugMode = true
1515
IsModEnabled = true
1616

0 commit comments

Comments
 (0)