2016-12-15 20:40:07 +08:00
|
|
|
local isInVehicle = false
|
|
|
|
local isEnteringVehicle = false
|
|
|
|
local currentVehicle = 0
|
|
|
|
local currentSeat = 0
|
|
|
|
|
|
|
|
Citizen.CreateThread(function()
|
|
|
|
while true do
|
|
|
|
Citizen.Wait(0)
|
|
|
|
|
|
|
|
local ped = PlayerPedId()
|
|
|
|
|
|
|
|
if not isInVehicle and not IsPlayerDead(PlayerId()) then
|
|
|
|
if DoesEntityExist(GetVehiclePedIsTryingToEnter(ped)) and not isEnteringVehicle then
|
|
|
|
-- trying to enter a vehicle!
|
|
|
|
local vehicle = GetVehiclePedIsTryingToEnter(ped)
|
|
|
|
local seat = GetSeatPedIsTryingToEnter(ped)
|
2018-10-06 20:10:44 +08:00
|
|
|
local netId = VehToNet(vehicle)
|
2016-12-15 20:40:07 +08:00
|
|
|
isEnteringVehicle = true
|
2018-10-06 20:10:44 +08:00
|
|
|
TriggerServerEvent('baseevents:enteringVehicle', vehicle, seat, GetDisplayNameFromVehicleModel(GetEntityModel(vehicle)), netId)
|
2016-12-15 20:40:07 +08:00
|
|
|
elseif not DoesEntityExist(GetVehiclePedIsTryingToEnter(ped)) and not IsPedInAnyVehicle(ped, true) and isEnteringVehicle then
|
|
|
|
-- vehicle entering aborted
|
|
|
|
TriggerServerEvent('baseevents:enteringAborted')
|
|
|
|
isEnteringVehicle = false
|
|
|
|
elseif IsPedInAnyVehicle(ped, false) then
|
|
|
|
-- suddenly appeared in a vehicle, possible teleport
|
|
|
|
isEnteringVehicle = false
|
|
|
|
isInVehicle = true
|
|
|
|
currentVehicle = GetVehiclePedIsUsing(ped)
|
|
|
|
currentSeat = GetPedVehicleSeat(ped)
|
|
|
|
local model = GetEntityModel(currentVehicle)
|
|
|
|
local name = GetDisplayNameFromVehicleModel()
|
2018-10-06 20:10:44 +08:00
|
|
|
local netId = VehToNet(currentVehicle)
|
|
|
|
TriggerServerEvent('baseevents:enteredVehicle', currentVehicle, currentSeat, GetDisplayNameFromVehicleModel(GetEntityModel(currentVehicle)), netId)
|
2016-12-15 20:40:07 +08:00
|
|
|
end
|
|
|
|
elseif isInVehicle then
|
|
|
|
if not IsPedInAnyVehicle(ped, false) or IsPlayerDead(PlayerId()) then
|
|
|
|
-- bye, vehicle
|
|
|
|
local model = GetEntityModel(currentVehicle)
|
|
|
|
local name = GetDisplayNameFromVehicleModel()
|
2018-10-06 20:10:44 +08:00
|
|
|
local netId = VehToNet(currentVehicle)
|
|
|
|
TriggerServerEvent('baseevents:leftVehicle', currentVehicle, currentSeat, GetDisplayNameFromVehicleModel(GetEntityModel(currentVehicle)), netId)
|
2016-12-15 20:40:07 +08:00
|
|
|
isInVehicle = false
|
|
|
|
currentVehicle = 0
|
|
|
|
currentSeat = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Citizen.Wait(50)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
function GetPedVehicleSeat(ped)
|
|
|
|
local vehicle = GetVehiclePedIsIn(ped, false)
|
|
|
|
for i=-2,GetVehicleMaxNumberOfPassengers(vehicle) do
|
|
|
|
if(GetPedInVehicleSeat(vehicle, i) == ped) then return i end
|
|
|
|
end
|
|
|
|
return -2
|
2018-10-06 20:10:44 +08:00
|
|
|
end
|