forked from Simnation/Main
Update main.lua
This commit is contained in:
parent
3a7652100b
commit
3c3b623d20
1 changed files with 39 additions and 17 deletions
|
@ -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)
|
|
||||||
|
|
||||||
if closestVehicle ~= nil and #(playerCoords - closestCoords) < 3.0 then
|
-- Only check if player is in a vehicle
|
||||||
if not enteredCloseVehicle then
|
if IsPedInAnyVehicle(playerPed, false) then
|
||||||
local isBoat = isSupportedBoat(closestVehicle)
|
local boat = GetVehiclePedIsIn(playerPed, false)
|
||||||
|
|
||||||
if isTrailer(closestVehicle) then
|
-- Check if it's a supported boat
|
||||||
closestTrailer = closestVehicle
|
if isSupportedBoat(boat) then
|
||||||
elseif isBoat then
|
-- Check if boat is over a trailer
|
||||||
closestBoat = closestVehicle
|
local trailer = IsBoatOverTrailer(boat)
|
||||||
|
|
||||||
|
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
|
||||||
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({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue