Working yet too close
This commit is contained in:
@@ -4,6 +4,27 @@ if not TowBarMod.Hook then TowBarMod.Hook = {} end
|
|||||||
local TowBarTowMass = 200
|
local TowBarTowMass = 200
|
||||||
local AutoReattachCooldownHours = 1 / 7200 -- 0.5 seconds
|
local AutoReattachCooldownHours = 1 / 7200 -- 0.5 seconds
|
||||||
TowBarMod.Hook.lastAutoReattachAtByVehicle = TowBarMod.Hook.lastAutoReattachAtByVehicle or {}
|
TowBarMod.Hook.lastAutoReattachAtByVehicle = TowBarMod.Hook.lastAutoReattachAtByVehicle or {}
|
||||||
|
local AutoReattachPlayerCooldownHours = 1 / 14400 -- 0.25 seconds
|
||||||
|
TowBarMod.Hook.lastAutoReattachAtByPlayer = TowBarMod.Hook.lastAutoReattachAtByPlayer or {}
|
||||||
|
|
||||||
|
local function isTowBarTowPair(towingVehicle, towedVehicle)
|
||||||
|
if not towingVehicle or not towedVehicle then return false end
|
||||||
|
|
||||||
|
local towingModData = towingVehicle:getModData()
|
||||||
|
local towedModData = towedVehicle:getModData()
|
||||||
|
if not towingModData or not towedModData then return false end
|
||||||
|
|
||||||
|
if towingModData["isTowingByTowBar"] and towedModData["isTowingByTowBar"] and towedModData["towed"] then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Rejoin fallback: original towbar state on the towed vehicle is enough to reapply rigid spacing.
|
||||||
|
if towedModData.towBarOriginalScriptName ~= nil then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
local function getTowBarItem(playerObj)
|
local function getTowBarItem(playerObj)
|
||||||
if not playerObj then return nil end
|
if not playerObj then return nil end
|
||||||
@@ -144,8 +165,7 @@ function TowBarMod.Hook.reattachTowBarFromDriverSeat(playerObj, towingVehicle)
|
|||||||
local towingModData = towingVehicle:getModData()
|
local towingModData = towingVehicle:getModData()
|
||||||
local towedModData = towedVehicle:getModData()
|
local towedModData = towedVehicle:getModData()
|
||||||
if not towingModData or not towedModData then return end
|
if not towingModData or not towedModData then return end
|
||||||
if not towingModData["isTowingByTowBar"] then return end
|
if not isTowBarTowPair(towingVehicle, towedVehicle) then return end
|
||||||
if not towedModData["isTowingByTowBar"] or not towedModData["towed"] then return end
|
|
||||||
|
|
||||||
local attachmentA = towingVehicle:getTowAttachmentSelf() or "trailer"
|
local attachmentA = towingVehicle:getTowAttachmentSelf() or "trailer"
|
||||||
local attachmentB = towingVehicle:getTowAttachmentOther() or "trailerfront"
|
local attachmentB = towingVehicle:getTowAttachmentOther() or "trailerfront"
|
||||||
@@ -192,21 +212,27 @@ local function tryAutoReattachFromCharacter(character)
|
|||||||
if not character or not instanceof(character, "IsoPlayer") or not character:isLocalPlayer() then return end
|
if not character or not instanceof(character, "IsoPlayer") or not character:isLocalPlayer() then return end
|
||||||
|
|
||||||
local playerObj = character
|
local playerObj = character
|
||||||
|
local nowHours = getGameTime() and getGameTime():getWorldAgeHours() or 0
|
||||||
|
local playerNum = playerObj:getPlayerNum()
|
||||||
|
local lastPlayerHours = TowBarMod.Hook.lastAutoReattachAtByPlayer[playerNum]
|
||||||
|
if lastPlayerHours and (nowHours - lastPlayerHours) < AutoReattachPlayerCooldownHours then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local towingVehicle = playerObj:getVehicle()
|
local towingVehicle = playerObj:getVehicle()
|
||||||
if not towingVehicle then return end
|
if not towingVehicle then return end
|
||||||
if not towingVehicle:isDriver(playerObj) then return end
|
if not towingVehicle:isDriver(playerObj) then return end
|
||||||
if not towingVehicle:getVehicleTowing() then return end
|
local towedVehicle = towingVehicle:getVehicleTowing()
|
||||||
|
if not towedVehicle then return end
|
||||||
local modData = towingVehicle:getModData()
|
if not isTowBarTowPair(towingVehicle, towedVehicle) then return end
|
||||||
if not modData or not modData["isTowingByTowBar"] then return end
|
|
||||||
|
|
||||||
local vehicleId = towingVehicle:getId()
|
local vehicleId = towingVehicle:getId()
|
||||||
local nowHours = getGameTime() and getGameTime():getWorldAgeHours() or 0
|
|
||||||
local lastHours = TowBarMod.Hook.lastAutoReattachAtByVehicle[vehicleId]
|
local lastHours = TowBarMod.Hook.lastAutoReattachAtByVehicle[vehicleId]
|
||||||
if lastHours and (nowHours - lastHours) < AutoReattachCooldownHours then
|
if lastHours and (nowHours - lastHours) < AutoReattachCooldownHours then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
TowBarMod.Hook.lastAutoReattachAtByPlayer[playerNum] = nowHours
|
||||||
TowBarMod.Hook.lastAutoReattachAtByVehicle[vehicleId] = nowHours
|
TowBarMod.Hook.lastAutoReattachAtByVehicle[vehicleId] = nowHours
|
||||||
TowBarMod.Hook.reattachTowBarFromDriverSeat(playerObj, towingVehicle)
|
TowBarMod.Hook.reattachTowBarFromDriverSeat(playerObj, towingVehicle)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -126,23 +126,6 @@ function TowBarMod.UI.addUnhookOptionToMenu(playerObj, vehicle)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function TowBarMod.UI.addDriverReattachOptionToMenu(playerObj, towingVehicle)
|
|
||||||
local menu = getPlayerRadialMenu(playerObj:getPlayerNum())
|
|
||||||
if menu == nil then return end
|
|
||||||
if not towingVehicle then return end
|
|
||||||
if not towingVehicle:isDriver(playerObj) then return end
|
|
||||||
if not towingVehicle:getVehicleTowing() then return end
|
|
||||||
if not towingVehicle:getModData()["isTowingByTowBar"] then return end
|
|
||||||
|
|
||||||
menu:addSlice(
|
|
||||||
"Reattach Towbar (Debug)",
|
|
||||||
getTexture("media/textures/tow_bar_attach.png"),
|
|
||||||
TowBarMod.Hook.reattachTowBarFromDriverSeat,
|
|
||||||
playerObj,
|
|
||||||
towingVehicle
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
--- Mod compability
|
--- Mod compability
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
@@ -163,17 +146,9 @@ end
|
|||||||
function ISVehicleMenu.showRadialMenu(playerObj)
|
function ISVehicleMenu.showRadialMenu(playerObj)
|
||||||
TowBarMod.UI.defaultShowRadialMenu(playerObj)
|
TowBarMod.UI.defaultShowRadialMenu(playerObj)
|
||||||
|
|
||||||
local vehicle = playerObj:getVehicle()
|
if playerObj:getVehicle() then return end
|
||||||
if vehicle then
|
|
||||||
if vehicle:isDriver(playerObj) and vehicle:getVehicleTowing() and vehicle:getModData()["isTowingByTowBar"] then
|
|
||||||
TowBarMod.UI.removeDefaultDetachOption(playerObj)
|
|
||||||
TowBarMod.UI.addUnhookOptionToMenu(playerObj, vehicle)
|
|
||||||
TowBarMod.UI.addDriverReattachOptionToMenu(playerObj, vehicle)
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
vehicle = ISVehicleMenu.getVehicleToInteractWith(playerObj)
|
local vehicle = ISVehicleMenu.getVehicleToInteractWith(playerObj)
|
||||||
if vehicle == nil then return end
|
if vehicle == nil then return end
|
||||||
|
|
||||||
if vehicle:getModData()["isTowingByTowBar"] then
|
if vehicle:getModData()["isTowingByTowBar"] then
|
||||||
|
|||||||
Reference in New Issue
Block a user