-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.lua
More file actions
135 lines (117 loc) · 4.82 KB
/
Copy pathclient.lua
File metadata and controls
135 lines (117 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
--------- ATTACH Ehh -------------
local QBCore = exports['qb-core']:GetCoreObject()
local attachedCarModel = "npolvette"
-- Variable to keep track of the attached car
local attachedCar = nil
-- Attach the car to the helicopter
function attachCarToHelicopter(playerPed, helicopter)
-- Check if a car is already attached and still exists
if attachedCar ~= nil and DoesEntityExist(attachedCar) then
TriggerEvent("chat:addMessage", {
color = {255, 0, 0},
multiline = true,
args = {"System", "A car is already attached!"}
})
return
end
local heliCoords = GetEntityCoords(helicopter)
local heliForwardVector = GetEntityForwardVector(helicopter)
local carSpawnCoords = heliCoords + heliForwardVector * 5.0 -- Adjust the distance between helicopter and car
-- Spawn the car model at the specified coordinates
attachedCar = CreateVehicle(GetHashKey(attachedCarModel), carSpawnCoords.x, carSpawnCoords.y, carSpawnCoords.z, GetEntityHeading(helicopter), true, false)
if DoesEntityExist(attachedCar) then
-- Attach the car to the helicopter
AttachEntityToEntity(attachedCar, helicopter, GetEntityBoneIndexByName(helicopter, "chassis"), 0.0, 0.0, -1.8, 0.0, 0.0, 0.0, false, false, false, false, 2, true)
TriggerEvent("chat:addMessage", {
color = {255, 0, 0},
multiline = true,
args = {"System", "Car attached to helicopter!"}
})
end
end
RegisterNetEvent("detachcar", function(source, args)
if DoesEntityExist(attachedCar) then
DetachEntity(attachedCar, true, true)
attachedCar = nil
TriggerEvent("chat:addMessage", {
color = {255, 0, 0},
multiline = true,
args = {"System", "Car detached from helicopter!"}
})
else
TriggerEvent("chat:addMessage", {
color = {255, 0, 0},
multiline = true,
args = {"System", "No car is attached to the helicopter!"}
})
end
end)
-- Attach the nearest car to the helicopter
function attachNearestCarToHelicopter(playerPed, helicopter)
-- Check if a car is already attached and still exists
if attachedCar ~= nil and DoesEntityExist(attachedCar) then
TriggerEvent("chat:addMessage", {
color = {255, 0, 0},
multiline = true,
args = {"System", "A car is already attached!"}
})
return
end
local playerCoords = GetEntityCoords(playerPed)
local closestVehicle = GetClosestVehicle(playerCoords.x, playerCoords.y, playerCoords.z, 5.0, 0, 127)
if DoesEntityExist(closestVehicle) then
-- Attach the car to the helicopter
AttachEntityToEntity(closestVehicle, helicopter, GetEntityBoneIndexByName(helicopter, "chassis"), 0.0, 0.0, -1.8, 0.0, 0.0, 0.0, false, false, false, false, 2, true)
attachedCar = closestVehicle
TriggerEvent("chat:addMessage", {
color = {255, 0, 0},
multiline = true,
args = {"System", "Car attached to helicopter!"}
})
else
TriggerEvent("chat:addMessage", {
color = {255, 0, 0},
multiline = true,
args = {"System", "No nearby cars found!"}
})
end
end
-- Command to attach the nearest car to the helicopter
RegisterNetEvent("attachncar", function(source, args)
local playerPed = GetPlayerPed(-1)
local vehicle = GetVehiclePedIsIn(playerPed, false)
-- Check if the player is in a helicopter
if IsVehicleModel(vehicle, GetHashKey("polmav")) then -- Change the vehicle model to the helicopter model you want to use
QBCore.Functions.Progressbar("attach_car", "Attaching car", 3000, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
animDict = "missheistdockssetup1clipboard@idle_a",
anim = "idle_a",
flags = 49,
}, {}, {}, function() -- Done
attachNearestCarToHelicopter(playerPed, vehicle)
end, function() -- Cancel
TriggerEvent("chat:addMessage", {
color = {255, 0, 0},
multiline = true,
args = {"System", "Failed to attach the car!"}
})
end)
else
TriggerEvent("chat:addMessage", {
color = {255, 0, 0},
multiline = true,
args = {"System", "You must be in a helicopter to use this item!"}
})
end
end)
RegisterNetEvent("attachncaritem", function()
if DoesEntityExist(attachedCar) then
TriggerEvent("detachcar")
else
TriggerEvent("attachncar")
end
end)