forked from itsJarrett/FiveM-seat_seater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cl_seatseater.lua
44 lines (41 loc) · 1.45 KB
/
cl_seatseater.lua
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
local doors = {
{"seat_dside_f", -1},
{"seat_pside_f", 0},
{"seat_dside_r", 1},
{"seat_pside_r", 2}
}
function VehicleInFront(ped)
local pos = GetEntityCoords(ped)
local entityWorld = GetOffsetFromEntityInWorldCoords(ped, 0.0, 5.0, 0.0)
local rayHandle = CastRayPointToPoint(pos.x, pos.y, pos.z, entityWorld.x, entityWorld.y, entityWorld.z, 10, ped, 0)
local _, _, _, _, result = GetRaycastResult(rayHandle)
return result
end
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local ped = GetPlayerPed(-1)
if IsControlJustReleased(0, 23) and running ~= true and GetVehiclePedIsIn(ped, false) == 0 then
local vehicle = VehicleInFront(ped)
running = true
if vehicle ~= nil then
local plyCoords = GetEntityCoords(ped, false)
local doorDistances = {}
for k, door in pairs(doors) do
local doorBone = GetEntityBoneIndexByName(vehicle, door[1])
local doorPos = GetWorldPositionOfEntityBone(vehicle, doorBone)
local distance = Vdist(plyCoords.x, plyCoords.y, plyCoords.z, doorPos.x, doorPos.y, doorPos.z)
table.insert(doorDistances, distance)
end
local key, min = 1, doorDistances[1]
for k, v in ipairs(doorDistances) do
if doorDistances[k] < min then
key, min = k, v
end
end
TaskEnterVehicle(ped, vehicle, -1, doors[key][2], 1.5, 1, 0)
end
running = false
end
end
end)