forked from Simnation/Main
Update main.lua
This commit is contained in:
parent
1a535451da
commit
5f71e16d4a
1 changed files with 98 additions and 5 deletions
|
@ -14,30 +14,33 @@ 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, 1.5, 0.3) -- Angepasste Werte für yftrailer
|
return vector3(0.0, 0.5, 0.3) -- Adjusted values for boattrailer6 (moved forward toward hitch)
|
||||||
else
|
else
|
||||||
return vector3(0.0, 1.8, 0.0) -- Original boattrailer Werte
|
return vector3(0.0, 1.8, 0.0) -- Original boattrailer values
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getBoatAttachmentOffset(trailer)
|
local function getBoatAttachmentOffset(trailer)
|
||||||
local model = GetEntityModel(trailer)
|
local model = GetEntityModel(trailer)
|
||||||
if model == `boattrailer6` then
|
if model == `boattrailer6` then
|
||||||
return vector3(0.0, -1.0, 0.25) -- Angepasste Werte für yftrailer
|
return vector3(0.0, -1.0, 0.25) -- Adjusted values for boattrailer6
|
||||||
else
|
else
|
||||||
return vector3(0.0, -1.02, 0.3) -- Original boattrailer Werte
|
return vector3(0.0, -1.02, 0.3) -- Original boattrailer values
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function isSupportedBoat(closest)
|
local function isSupportedBoat(closest)
|
||||||
|
if not closest then return false end
|
||||||
for _, model in pairs(Config.SupportedBoats) do
|
for _, model in pairs(Config.SupportedBoats) do
|
||||||
if GetEntityModel(closest) == model then
|
if GetEntityModel(closest) == model then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local function isTrailer(vehicle)
|
local function isTrailer(vehicle)
|
||||||
|
if not vehicle then return false end
|
||||||
local model = GetEntityModel(vehicle)
|
local model = GetEntityModel(vehicle)
|
||||||
return model == `boattrailer` or model == `boattrailer6`
|
return model == `boattrailer` or model == `boattrailer6`
|
||||||
end
|
end
|
||||||
|
@ -68,6 +71,34 @@ local function notify(text)
|
||||||
DrawNotification(true, false)
|
DrawNotification(true, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Function to check if boat is positioned over trailer
|
||||||
|
local function IsBoatOverTrailer(boat)
|
||||||
|
if not boat or not isSupportedBoat(boat) then return false end
|
||||||
|
|
||||||
|
local boatCoords = GetEntityCoords(boat)
|
||||||
|
local vehicles = GetGamePool('CVehicle')
|
||||||
|
local foundTrailer = nil
|
||||||
|
|
||||||
|
for i = 1, #vehicles do
|
||||||
|
local vehicle = vehicles[i]
|
||||||
|
if isTrailer(vehicle) then
|
||||||
|
local trailerCoords = GetEntityCoords(vehicle)
|
||||||
|
local distance = #(boatCoords - trailerCoords)
|
||||||
|
if distance < 3.0 then
|
||||||
|
-- Additional check for proper alignment
|
||||||
|
local trailerHeading = GetEntityHeading(vehicle)
|
||||||
|
local boatHeading = GetEntityHeading(boat)
|
||||||
|
local headingDiff = math.abs(trailerHeading - boatHeading)
|
||||||
|
if headingDiff < 30.0 or headingDiff > 330.0 then
|
||||||
|
foundTrailer = vehicle
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return foundTrailer
|
||||||
|
end
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
Wait(1000)
|
Wait(1000)
|
||||||
|
@ -169,6 +200,19 @@ CreateThread(function()
|
||||||
end
|
end
|
||||||
return not hasTakenRope and hookedToBoat and createdRope
|
return not hasTakenRope and hookedToBoat and createdRope
|
||||||
end
|
end
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "client",
|
||||||
|
event = "re_boat_winch:client:selfDockBoat",
|
||||||
|
icon = 'fas fa-anchor',
|
||||||
|
label = "Secure boat to trailer",
|
||||||
|
canInteract = function(entity)
|
||||||
|
if not isSupportedBoat(entity) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local trailer = IsBoatOverTrailer(entity)
|
||||||
|
return trailer ~= nil
|
||||||
|
end
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
distance = 2.5
|
distance = 2.5
|
||||||
|
@ -252,6 +296,20 @@ CreateThread(function()
|
||||||
end
|
end
|
||||||
return not hasTakenRope and hookedToBoat and createdRope
|
return not hasTakenRope and hookedToBoat and createdRope
|
||||||
end
|
end
|
||||||
|
},
|
||||||
|
{
|
||||||
|
event = "re_boat_winch:client:selfDockBoat",
|
||||||
|
icon = 'fas fa-anchor',
|
||||||
|
label = "Secure boat to trailer",
|
||||||
|
name = "re_boat_winch:client:selfDockBoat",
|
||||||
|
distance = 2.5,
|
||||||
|
canInteract = function(entity)
|
||||||
|
if not isSupportedBoat(entity) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local trailer = IsBoatOverTrailer(entity)
|
||||||
|
return trailer ~= nil
|
||||||
|
end
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -269,6 +327,7 @@ AddEventHandler('onResourceStop', function(resourceName)
|
||||||
exports['qb-target']:RemoveGlobalVehicle("Boot vom Anhänger lösen")
|
exports['qb-target']:RemoveGlobalVehicle("Boot vom Anhänger lösen")
|
||||||
exports['qb-target']:RemoveGlobalVehicle("Seil einhängen")
|
exports['qb-target']:RemoveGlobalVehicle("Seil einhängen")
|
||||||
exports['qb-target']:RemoveGlobalVehicle("Seil aushängen")
|
exports['qb-target']:RemoveGlobalVehicle("Seil aushängen")
|
||||||
|
exports['qb-target']:RemoveGlobalVehicle("Boot am Anhänger befestigen")
|
||||||
else
|
else
|
||||||
exports.ox_target:removeGlobalVehicle("re_boat_winch:client:takeRope")
|
exports.ox_target:removeGlobalVehicle("re_boat_winch:client:takeRope")
|
||||||
exports.ox_target:removeGlobalVehicle("re_boat_winch:client:returnRope")
|
exports.ox_target:removeGlobalVehicle("re_boat_winch:client:returnRope")
|
||||||
|
@ -276,6 +335,7 @@ AddEventHandler('onResourceStop', function(resourceName)
|
||||||
exports.ox_target:removeGlobalVehicle("re_boat_winch:client:detachBoat")
|
exports.ox_target:removeGlobalVehicle("re_boat_winch:client:detachBoat")
|
||||||
exports.ox_target:removeGlobalVehicle("re_boat_winch:client:hookUpRope")
|
exports.ox_target:removeGlobalVehicle("re_boat_winch:client:hookUpRope")
|
||||||
exports.ox_target:removeGlobalVehicle("re_boat_winch:client:unHookRope")
|
exports.ox_target:removeGlobalVehicle("re_boat_winch:client:unHookRope")
|
||||||
|
exports.ox_target:removeGlobalVehicle("re_boat_winch:client:selfDockBoat")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -333,6 +393,10 @@ RegisterNetEvent('re_boat_winch:client:returnRope', function()
|
||||||
|
|
||||||
DeleteEntity(colObj)
|
DeleteEntity(colObj)
|
||||||
DeleteRope(createdRope)
|
DeleteRope(createdRope)
|
||||||
|
|
||||||
|
-- Unfreeze the trailer when returning the rope
|
||||||
|
FreezeEntityPosition(closestTrailer, false)
|
||||||
|
SetEntityInvincible(closestTrailer, false)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('re_boat_winch:client:detachBoat', function()
|
RegisterNetEvent('re_boat_winch:client:detachBoat', function()
|
||||||
|
@ -395,6 +459,36 @@ RegisterNetEvent('re_boat_winch:client:controlRope', function()
|
||||||
notify("Du kontrollierst die Winde")
|
notify("Du kontrollierst die Winde")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- New event for self-docking boats
|
||||||
|
RegisterNetEvent('re_boat_winch:client:selfDockBoat', function()
|
||||||
|
local playerPed = PlayerPedId()
|
||||||
|
local boat = GetVehiclePedIsIn(playerPed, false)
|
||||||
|
|
||||||
|
if not boat or not isSupportedBoat(boat) then
|
||||||
|
notify("Du musst in einem unterstützten Boot sein")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local trailer = IsBoatOverTrailer(boat)
|
||||||
|
if not trailer then
|
||||||
|
notify("Kein Anhänger in der Nähe gefunden")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Exit the boat
|
||||||
|
TaskLeaveVehicle(playerPed, boat, 0)
|
||||||
|
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)
|
||||||
|
|
||||||
local function attachBoatToTrailer()
|
local function attachBoatToTrailer()
|
||||||
if not DoesEntityExist(closestTrailer) or not DoesEntityExist(closestBoat) then
|
if not DoesEntityExist(closestTrailer) or not DoesEntityExist(closestBoat) then
|
||||||
return
|
return
|
||||||
|
@ -484,4 +578,3 @@ CreateThread(function()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue