Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions UniversalAutoload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2585,32 +2585,37 @@ function UniversalAutoload:doUpdate(dt, isActiveForInput, isActiveForInputIgnore
spec.customOffset = spec.customOffset or 0
spec.customRotation = spec.customRotation or 0

local rotationshift = spec.loadVolume.length / 3
local direction = (spec.currentTipside == "right") and 1 or -1
local function clampOffset()
local minOffset = (spec.customRotation == 0) and 0 or rotationshift
local maxOffset = spec.loadVolume.length / 2 + minOffset
spec.customOffset = math.clamp(spec.customOffset, minOffset, maxOffset)
end
-- spec.loadVolume is only populated server-side by initialiseTransformGroups,
-- or for vehicles without a valid loadArea config. Skip the shift/rotate logic
-- in those cases to avoid "attempt to index nil with 'length'".
if spec.loadVolume then
local rotationshift = spec.loadVolume.length / 3
local direction = (spec.currentTipside == "right") and 1 or -1
local function clampOffset()
local minOffset = (spec.customRotation == 0) and 0 or rotationshift
local maxOffset = spec.loadVolume.length / 2 + minOffset
spec.customOffset = math.clamp(spec.customOffset, minOffset, maxOffset)
end

if spec.leftKeyPressed then
spec.customOffset = spec.customOffset - (UniversalAutoload.SHIFT_DELTA * direction)
clampOffset()
end
if spec.leftKeyPressed then
spec.customOffset = spec.customOffset - (UniversalAutoload.SHIFT_DELTA * direction)
clampOffset()
end

if spec.rightKeyPressed then
spec.customOffset = spec.customOffset + (UniversalAutoload.SHIFT_DELTA * direction)
clampOffset()
end
if spec.rightKeyPressed then
spec.customOffset = spec.customOffset + (UniversalAutoload.SHIFT_DELTA * direction)
clampOffset()
end

if spec.rotateKeyPressed then
local rotated = spec.customRotation ~= 0
if spec.rotateKeyPressed then
local rotated = spec.customRotation ~= 0

spec.customRotation = rotated and 0 or -math.pi / 2
spec.customOffset = spec.customOffset + (rotated and -rotationshift or rotationshift)
spec.customRotation = rotated and 0 or -math.pi / 2
spec.customOffset = spec.customOffset + (rotated and -rotationshift or rotationshift)

spec.rotateKeyPressed = false
clampOffset()
spec.rotateKeyPressed = false
clampOffset()
end
end

end
Expand Down