1
0
Fork 0
forked from Simnation/Main

Update main.lua

This commit is contained in:
Nordi98 2025-07-02 06:50:59 +02:00
parent 3a7652100b
commit 3c3b623d20

View file

@ -14,7 +14,7 @@ local boatOnTrailer = false
local function getTrailerOffset(trailer) local function getTrailerOffset(trailer)
local model = GetEntityModel(trailer) local model = GetEntityModel(trailer)
if model == `boattrailer6` then 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 else
return vector3(0.0, 1.8, 0.0) -- Original boattrailer values return vector3(0.0, 1.8, 0.0) -- Original boattrailer values
end end
@ -71,7 +71,7 @@ local function notify(text)
DrawNotification(true, false) DrawNotification(true, false)
end end
-- Function to check if boat is positioned over trailer -- Replace the IsBoatOverTrailer function with this improved version
local function IsBoatOverTrailer(boat) local function IsBoatOverTrailer(boat)
if not boat or not isSupportedBoat(boat) then return false end if not boat or not isSupportedBoat(boat) then return false end
@ -99,32 +99,54 @@ local function IsBoatOverTrailer(boat)
return foundTrailer return foundTrailer
end end
-- Add this new thread to handle E key press for securing boat
CreateThread(function() CreateThread(function()
while true do while true do
Wait(1000) Wait(0)
local playerPed = PlayerPedId() local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local closestVehicle, closestCoords = getClosestVehicle(playerCoords, 3.0) -- Only check if player is in a vehicle
if IsPedInAnyVehicle(playerPed, false) then
if closestVehicle ~= nil and #(playerCoords - closestCoords) < 3.0 then local boat = GetVehiclePedIsIn(playerPed, false)
if not enteredCloseVehicle then
local isBoat = isSupportedBoat(closestVehicle) -- 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 if trailer then
closestTrailer = closestVehicle -- Display help text
elseif isBoat then BeginTextCommandDisplayHelp("STRING")
closestBoat = closestVehicle 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
end end
enteredCloseVehicle = true
else else
enteredCloseVehicle = false Wait(1000) -- Wait longer if not in a vehicle
end end
end end
end) end)
CreateThread(function() CreateThread(function()
if GetResourceState('qb-target') == 'started' then if GetResourceState('qb-target') == 'started' then
exports['qb-target']:AddGlobalVehicle({ exports['qb-target']:AddGlobalVehicle({