Intresting
This commit is contained in:
@@ -554,7 +554,32 @@ local function breakConstraintSafe(vehicle, reason)
|
||||
|
||||
local playerObj = getSpecificPlayer(0)
|
||||
if playerObj ~= nil then
|
||||
sendClientCommand(playerObj, "towbar", "detachConstraint", { vehicle = vehicle:getId() })
|
||||
local towingVehicle = vehicle
|
||||
local towedVehicle = vehicle:getVehicleTowing()
|
||||
if towedVehicle == nil then
|
||||
local frontVehicle = vehicle:getVehicleTowedBy()
|
||||
if frontVehicle ~= nil then
|
||||
towingVehicle = frontVehicle
|
||||
towedVehicle = vehicle
|
||||
end
|
||||
end
|
||||
|
||||
local detachCommand = "detachTowBar"
|
||||
if TowBarMod and TowBarMod.Hook and TowBarMod.Hook.performDetachTowBar == nil then
|
||||
detachCommand = "detachConstraint"
|
||||
end
|
||||
|
||||
local args = {}
|
||||
if towingVehicle ~= nil then
|
||||
args.towingVehicle = towingVehicle:getId()
|
||||
end
|
||||
if towedVehicle ~= nil then
|
||||
args.vehicle = towedVehicle:getId()
|
||||
else
|
||||
args.vehicle = vehicle:getId()
|
||||
end
|
||||
|
||||
sendClientCommand(playerObj, "towbar", detachCommand, args)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
@@ -1208,9 +1233,19 @@ local function menuHasTowbarAttachSlice(menu)
|
||||
return false
|
||||
end
|
||||
|
||||
local function getTowbarDetachAction()
|
||||
if TowBarMod == nil or TowBarMod.Hook == nil then return nil end
|
||||
return TowBarMod.Hook.deattachTowBarAction or TowBarMod.Hook.detachTowBarAction
|
||||
end
|
||||
|
||||
local function getTowbarPerformDetachHook()
|
||||
if TowBarMod == nil or TowBarMod.Hook == nil then return nil end
|
||||
return TowBarMod.Hook.performDetachTowBar or TowBarMod.Hook.performDeattachTowBar
|
||||
end
|
||||
|
||||
local function menuHasTowbarDetachSlice(menu)
|
||||
if menu == nil or menu.slices == nil then return false end
|
||||
local detachAction = TowBarMod and TowBarMod.Hook and TowBarMod.Hook.deattachTowBarAction or nil
|
||||
local detachAction = getTowbarDetachAction()
|
||||
if detachAction == nil then
|
||||
return false
|
||||
end
|
||||
@@ -1288,7 +1323,8 @@ end
|
||||
|
||||
local function addLandtrainUnhookOptionToMenu(playerObj, vehicle)
|
||||
if playerObj == nil or vehicle == nil then return end
|
||||
if TowBarMod == nil or TowBarMod.Hook == nil or TowBarMod.Hook.deattachTowBarAction == nil then return end
|
||||
local detachAction = getTowbarDetachAction()
|
||||
if detachAction == nil then return end
|
||||
|
||||
local menu = getPlayerRadialMenu(playerObj:getPlayerNum())
|
||||
if menu == nil then return end
|
||||
@@ -1300,7 +1336,7 @@ local function addLandtrainUnhookOptionToMenu(playerObj, vehicle)
|
||||
menu:addSlice(
|
||||
getText("ContextMenu_Vehicle_DetachTrailer", ISVehicleMenu.getVehicleDisplayName(towedVehicle)),
|
||||
getTexture("media/textures/tow_bar_detach.png"),
|
||||
TowBarMod.Hook.deattachTowBarAction,
|
||||
detachAction,
|
||||
playerObj,
|
||||
towedVehicle
|
||||
)
|
||||
@@ -1538,7 +1574,7 @@ local function installLandtrainTowbarPatch()
|
||||
return resolvedTowing, resolvedTowed
|
||||
end
|
||||
|
||||
local originalPerformDetach = TowBarMod.Hook.performDeattachTowBar
|
||||
local originalPerformDetach = getTowbarPerformDetachHook()
|
||||
if originalPerformDetach and originalPerformDetach ~= TowBarMod.Hook._landtrainPerformDetachWrapper then
|
||||
local performDetachWrapper = function(playerObj, towingVehicle, towedVehicle)
|
||||
local resolvedTowingVehicle, resolvedTowedVehicle = resolveTowbarDetachPair(towingVehicle, towedVehicle)
|
||||
@@ -1550,11 +1586,11 @@ local function installLandtrainTowbarPatch()
|
||||
return
|
||||
end
|
||||
|
||||
dumpTowState("performDeattachTowBar pre towing", resolvedTowingVehicle)
|
||||
dumpTowState("performDeattachTowBar pre towed", resolvedTowedVehicle)
|
||||
dumpTowState("performDetachTowBar pre towing", resolvedTowingVehicle)
|
||||
dumpTowState("performDetachTowBar pre towed", resolvedTowedVehicle)
|
||||
originalPerformDetach(playerObj, resolvedTowingVehicle, resolvedTowedVehicle)
|
||||
dumpTowState("performDeattachTowBar post-original towing", resolvedTowingVehicle)
|
||||
dumpTowState("performDeattachTowBar post-original towed", resolvedTowedVehicle)
|
||||
dumpTowState("performDetachTowBar post-original towing", resolvedTowingVehicle)
|
||||
dumpTowState("performDetachTowBar post-original towed", resolvedTowedVehicle)
|
||||
clearLandtrainFrontLinkData(resolvedTowedVehicle)
|
||||
|
||||
reconcileTowbarSplitAround(resolvedTowingVehicle)
|
||||
@@ -1573,13 +1609,14 @@ local function installLandtrainTowbarPatch()
|
||||
refreshTowBarState(resolvedTowedVehicle:getVehicleTowing())
|
||||
saveActiveLandtrainTowbarSnapshot()
|
||||
|
||||
dumpTowState("performDeattachTowBar post-reconcile towing", resolvedTowingVehicle)
|
||||
dumpTowState("performDeattachTowBar post-reconcile towed", resolvedTowedVehicle)
|
||||
dumpTowState("performDetachTowBar post-reconcile towing", resolvedTowingVehicle)
|
||||
dumpTowState("performDetachTowBar post-reconcile towed", resolvedTowedVehicle)
|
||||
end
|
||||
|
||||
TowBarMod.Hook.performDetachTowBar = performDetachWrapper
|
||||
TowBarMod.Hook.performDeattachTowBar = performDetachWrapper
|
||||
TowBarMod.Hook._landtrainPerformDetachWrapper = performDetachWrapper
|
||||
ltLog("installLandtrainTowbarPatch patched TowBarMod.Hook.performDeattachTowBar")
|
||||
ltLog("installLandtrainTowbarPatch patched TowBarMod.Hook.performDetachTowBar")
|
||||
end
|
||||
|
||||
-- If vanilla detach sneaks into the radial menu, redirect it to Towbar timed detach.
|
||||
@@ -1592,9 +1629,9 @@ local function installLandtrainTowbarPatch()
|
||||
end
|
||||
|
||||
local towbarDetachTarget = getTowbarDetachTargetVehicle(vehicleToCheck)
|
||||
if playerObj ~= nil and towbarDetachTarget ~= nil
|
||||
and TowBarMod and TowBarMod.Hook and TowBarMod.Hook.deattachTowBarAction then
|
||||
TowBarMod.Hook.deattachTowBarAction(playerObj, towbarDetachTarget)
|
||||
local detachAction = getTowbarDetachAction()
|
||||
if playerObj ~= nil and towbarDetachTarget ~= nil and detachAction ~= nil then
|
||||
detachAction(playerObj, towbarDetachTarget)
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user