I’m developing my personal carthief script based on loffe_carthief, but i have a strange problem.
I make the ped enter the vehicle, do the mechanic animation for a certain amount of time keeping the vehicle off, and then the vehicle starts and player can use it, the problem is that sometimes after the animation ends the player gets out of the vehicle for no reason. Someone knows how to fix this?
Here’s the code of the problematic part:
Summary
if GetDistanceBetweenCoords(coords, Config.PickPoints[pickup].x, Config.PickPoints[pickup].y, Config.PickPoints[pickup].z, true) < 50 and stop ~= 1 then
if spawned_cars == nil then
spawned_cars = CreateVehicle(vehicleModel, Config.PickPoints[pickup].x, Config.PickPoints[pickup].y, Config.PickPoints[pickup].z, Config.PickPoints[pickup].h, true, false)
if spawned_cars ~= nil then
print("Car spawned at x: " … Config.PickPoints[pickup].x … " y: " … Config.PickPoints[pickup].y … " z: " … Config.PickPoints[pickup].z)
end
end
–while ped gets on board triggers the lockpicking
while not IsPedInVehicle(player, spawned_cars, false) and stop ~= 1 do
Citizen.Wait(100)
end
if stop ~= 1 then
local vehicle = GetVehiclePedIsIn(player, false)
local vehicleLabel = GetDisplayNameFromVehicleModel(Config.carModels[carNum])
local streetName = GetLabelText((GetNameOfZone(coords.x, coords.y, coords.z)))
TriggerServerEvent(‘esx_outlawalert:carthiefInProgress’, coords, streetName, vehicleLabel)
TriggerServerEvent(‘ProjectX_CondorThief:updateThefts’)
RequestAnimDict(‘anim@amb@clubhouse@tutorial@bkr_tut_ig3@’)
while not HasAnimDictLoaded(‘anim@amb@clubhouse@tutorial@bkr_tut_ig3@’) do
Citizen.Wait(0)
end
–turn off engine and then turn it on after waiting lockpicking amount
–thread for keeping vehicle engine off while lockpicking
local vehOff = true
Citizen.CreateThread(function ()
while vehOff do
Citizen.Wait(0)
SetVehicleEngineOn(vehicle, false, false, false)
SetVehicleUndriveable(vehicle, false, false, false)
end
end)
Citizen.Wait(1000)
TaskPlayAnim(player, ‘anim@amb@clubhouse@tutorial@bkr_tut_ig3@’ , ‘machinic_loop_mechandplayer’, 8.0, 8.0, Config.lockpickingTime, 17, 0, false, false, false )
SetVehicleAlarm(vehicle, true)
SetVehicleAlarmTimeLeft(vehicle, Config.lockpickingTime)
Citizen.Wait(Config.lockpickingTime)
vehOff = false