From 3c3b623d20e17081ff6836f75a0c2b9711c2c41e Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Wed, 2 Jul 2025 06:50:59 +0200 Subject: [PATCH] Update main.lua --- resources/[carscripts]/re_boat_winch/main.lua | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/resources/[carscripts]/re_boat_winch/main.lua b/resources/[carscripts]/re_boat_winch/main.lua index fd5156113..a84454fef 100644 --- a/resources/[carscripts]/re_boat_winch/main.lua +++ b/resources/[carscripts]/re_boat_winch/main.lua @@ -14,7 +14,7 @@ local boatOnTrailer = false local function getTrailerOffset(trailer) local model = GetEntityModel(trailer) if model == `boattrailer6` then - return vector3(0.0, 4.0, 0.3) -- Adjusted values for boattrailer6 (moved forward toward hitch) + return vector3(0.0, 6.0, 0.3) -- Adjusted values for boattrailer6 (moved forward toward hitch) else return vector3(0.0, 1.8, 0.0) -- Original boattrailer values end @@ -71,7 +71,7 @@ local function notify(text) DrawNotification(true, false) end --- Function to check if boat is positioned over trailer +-- Replace the IsBoatOverTrailer function with this improved version local function IsBoatOverTrailer(boat) if not boat or not isSupportedBoat(boat) then return false end @@ -99,32 +99,54 @@ local function IsBoatOverTrailer(boat) return foundTrailer end +-- Add this new thread to handle E key press for securing boat CreateThread(function() while true do - Wait(1000) - + Wait(0) + local playerPed = PlayerPedId() - local playerCoords = GetEntityCoords(playerPed) - local closestVehicle, closestCoords = getClosestVehicle(playerCoords, 3.0) - - if closestVehicle ~= nil and #(playerCoords - closestCoords) < 3.0 then - if not enteredCloseVehicle then - local isBoat = isSupportedBoat(closestVehicle) + + -- Only check if player is in a vehicle + if IsPedInAnyVehicle(playerPed, false) then + local boat = GetVehiclePedIsIn(playerPed, false) + + -- Check if it's a supported boat + if isSupportedBoat(boat) then + -- Check if boat is over a trailer + local trailer = IsBoatOverTrailer(boat) - if isTrailer(closestVehicle) then - closestTrailer = closestVehicle - elseif isBoat then - closestBoat = closestVehicle + if trailer then + -- Display help text + BeginTextCommandDisplayHelp("STRING") + AddTextComponentSubstringPlayerName("Press ~INPUT_CONTEXT~ to secure boat to trailer") + EndTextCommandDisplayHelp(0, false, true, -1) + + -- Check for E key press + if IsControlJustReleased(0, 38) then -- 38 is E key + -- Exit the boat + TaskLeaveVehicle(playerPed, boat, 0) + + -- Wait for player to exit + Wait(1500) + + -- Attach boat to trailer + local attachOffset = getBoatAttachmentOffset(trailer) + AttachEntityToEntity(boat, trailer, 0, attachOffset.x, attachOffset.y, attachOffset.z, 0.0, 0.0, 0.0, false, false, false, false, 2, true) + + closestBoat = boat + closestTrailer = trailer + boatOnTrailer = true + notify("Boot am Anhänger befestigt") + end end end - - enteredCloseVehicle = true else - enteredCloseVehicle = false + Wait(1000) -- Wait longer if not in a vehicle end end end) + CreateThread(function() if GetResourceState('qb-target') == 'started' then exports['qb-target']:AddGlobalVehicle({