fixed
This commit is contained in:
@@ -33,6 +33,19 @@ local function getTowBarItem(playerObj)
|
||||
return inventory:getItemFromTypeRecurse("TowBar.TowBar")
|
||||
end
|
||||
|
||||
local function sendTowAttachCommand(playerObj, args)
|
||||
if not playerObj or not args then return end
|
||||
|
||||
-- MP-safe/server-authoritative attach path (Landtrain style).
|
||||
if isClient() and isMultiplayer() then
|
||||
sendClientCommand(playerObj, "towbar", "attachTowBar", args)
|
||||
return
|
||||
end
|
||||
|
||||
-- Keep vanilla attach path for SP/local behavior.
|
||||
sendClientCommand(playerObj, "vehicle", "attachTrailer", args)
|
||||
end
|
||||
|
||||
local TowbarVariantSize = 24
|
||||
local TowbarNormalStart = 0
|
||||
local TowbarLargeStart = 24
|
||||
@@ -278,11 +291,38 @@ local function reattachTowBarPair(playerObj, towingVehicle, towedVehicle, requir
|
||||
attachmentA = attachmentA,
|
||||
attachmentB = attachmentB
|
||||
}
|
||||
sendClientCommand(playerObj, "vehicle", "attachTrailer", args)
|
||||
sendTowAttachCommand(playerObj, args)
|
||||
ISTimedActionQueue.add(TowBarScheduleAction:new(playerObj, 10, TowBarMod.Hook.setVehiclePostAttach, towedVehicle))
|
||||
return true
|
||||
end
|
||||
|
||||
local function reattachTowBarPairAfterCleanDetach(playerObj, towingVehicle, towedVehicle, requireDriver)
|
||||
if not playerObj or not towingVehicle or not towedVehicle then
|
||||
return false
|
||||
end
|
||||
if requireDriver and not towingVehicle:isDriver(playerObj) then
|
||||
return false
|
||||
end
|
||||
|
||||
local detachArgs = {
|
||||
towingVehicle = towingVehicle:getId(),
|
||||
vehicle = towedVehicle:getId()
|
||||
}
|
||||
sendClientCommand(playerObj, "towbar", "detachTowBar", detachArgs)
|
||||
|
||||
-- World load/spawn can restore constraints in a bad state. Reattach one
|
||||
-- short tick later so the detach is fully applied first.
|
||||
ISTimedActionQueue.add(TowBarScheduleAction:new(
|
||||
playerObj,
|
||||
1,
|
||||
reattachTowBarPair,
|
||||
towingVehicle,
|
||||
towedVehicle,
|
||||
requireDriver
|
||||
))
|
||||
return true
|
||||
end
|
||||
|
||||
local function recoverTowBarVehicleAfterLoad(playerObj, vehicle, retriesLeft)
|
||||
if not vehicle then return end
|
||||
|
||||
@@ -295,8 +335,14 @@ local function recoverTowBarVehicleAfterLoad(playerObj, vehicle, retriesLeft)
|
||||
local localPlayer = playerObj or getPlayer()
|
||||
local towingVehicle = vehicle:getVehicleTowedBy()
|
||||
|
||||
if towingVehicle then
|
||||
-- Apply rigid spacing as soon as the tow link exists to avoid a visible
|
||||
-- bumper-to-bumper snap while waiting for reattach recovery.
|
||||
TowBarMod.Hook.setVehiclePostAttach(nil, vehicle)
|
||||
end
|
||||
|
||||
if localPlayer and towingVehicle then
|
||||
if reattachTowBarPair(localPlayer, towingVehicle, vehicle, false) then
|
||||
if reattachTowBarPairAfterCleanDetach(localPlayer, towingVehicle, vehicle, false) then
|
||||
return
|
||||
end
|
||||
end
|
||||
@@ -376,7 +422,7 @@ function TowBarMod.Hook.performAttachTowBar(playerObj, towingVehicle, towedVehic
|
||||
attachmentA = attachmentA,
|
||||
attachmentB = attachmentB
|
||||
}
|
||||
sendClientCommand(playerObj, "vehicle", "attachTrailer", args)
|
||||
sendTowAttachCommand(playerObj, args)
|
||||
ISTimedActionQueue.add(TowBarScheduleAction:new(playerObj, 10, TowBarMod.Hook.setVehiclePostAttach, towedVehicle))
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user