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 AutoReattachCooldownHours = 1 / 7200 -- 0.5 seconds
|
||||
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)
|
||||
if not playerObj then return nil end
|
||||
@@ -144,8 +165,7 @@ function TowBarMod.Hook.reattachTowBarFromDriverSeat(playerObj, towingVehicle)
|
||||
local towingModData = towingVehicle:getModData()
|
||||
local towedModData = towedVehicle:getModData()
|
||||
if not towingModData or not towedModData then return end
|
||||
if not towingModData["isTowingByTowBar"] then return end
|
||||
if not towedModData["isTowingByTowBar"] or not towedModData["towed"] then return end
|
||||
if not isTowBarTowPair(towingVehicle, towedVehicle) then return end
|
||||
|
||||
local attachmentA = towingVehicle:getTowAttachmentSelf() or "trailer"
|
||||
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
|
||||
|
||||
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()
|
||||
if not towingVehicle then return end
|
||||
if not towingVehicle:isDriver(playerObj) then return end
|
||||
if not towingVehicle:getVehicleTowing() then return end
|
||||
|
||||
local modData = towingVehicle:getModData()
|
||||
if not modData or not modData["isTowingByTowBar"] then return end
|
||||
local towedVehicle = towingVehicle:getVehicleTowing()
|
||||
if not towedVehicle then return end
|
||||
if not isTowBarTowPair(towingVehicle, towedVehicle) then return end
|
||||
|
||||
local vehicleId = towingVehicle:getId()
|
||||
local nowHours = getGameTime() and getGameTime():getWorldAgeHours() or 0
|
||||
local lastHours = TowBarMod.Hook.lastAutoReattachAtByVehicle[vehicleId]
|
||||
if lastHours and (nowHours - lastHours) < AutoReattachCooldownHours then
|
||||
return
|
||||
end
|
||||
|
||||
TowBarMod.Hook.lastAutoReattachAtByPlayer[playerNum] = nowHours
|
||||
TowBarMod.Hook.lastAutoReattachAtByVehicle[vehicleId] = nowHours
|
||||
TowBarMod.Hook.reattachTowBarFromDriverSeat(playerObj, towingVehicle)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user