Modified for qb-radialmenu
Replace the start and stop autopilot functions in client.lua with
AddEventHandler('Bucko_autopilot:client:StartAutoPilot', function()
print("autopilot fired")
if isAutopilotActive then
TriggerEvent('chat:addMessage', { args = { "^3Autopilot", "Already active!" } })
return
end
local playerPed = PlayerPedId()
blip = GetFirstBlipInfoId(8)
if not DoesBlipExist(blip) then
TriggerEvent('chat:addMessage', { args = { "^1Error", "Set a waypoint first." } })
return
end
local dest = GetBlipInfoIdCoord(blip)
isAutopilotActive = true
if IsPedInAnyVehicle(playerPed, false) then
if not BuckoConfig.EnableDrivingAutopilot then
TriggerEvent('chat:addMessage', { args = { "^1Autopilot", "Driving autopilot is disabled on this server." } })
isAutopilotActive = false
return
end
local vehicle = GetVehiclePedIsIn(playerPed, false)
TaskVehicleDriveToCoordLongrange(playerPed, vehicle, dest.x, dest.y, dest.z, 30.0, 786603, 10.0)
TriggerEvent('chat:addMessage', { args = { "^2Autopilot", "Driving to waypoint..." } })
DriveToWaypoint(playerPed, vehicle, dest)
else
if not BuckoConfig.EnableWalkingAutopilot then
TriggerEvent('chat:addMessage', { args = { "^1Autopilot", "Walking autopilot is disabled on this server." } })
isAutopilotActive = false
return
end
TriggerEvent('chat:addMessage', { args = { "^2Autopilot", "Walking to waypoint..." } })
WalkToWaypointSafely(playerPed, dest)
end
end)
AddEventHandler('Bucko_autopilot:client:StopAutoPilot', function()
print("autopilot fired")
local playerPed = PlayerPedId()
if IsPedInAnyVehicle(playerPed, false) then
local vehicle = GetVehiclePedIsIn(playerPed, false)
ClearPedTasks(playerPed)
SetVehicleHandbrake(vehicle, false)
SetDriveTaskCruiseSpeed(playerPed, 0.0)
SetEntityVelocity(vehicle, 0.0, 0.0, 0.0)
Wait(100)
else
ClearPedTasks(playerPed)
end
isAutopilotActive = false
blip = nil
TriggerEvent('chat:addMessage', { args = { "^3Autopilot", "Autopilot deactivated. You now have full control." } })
end)
in your qb-radialmenu config add a new menu item with the following:
{
id = 'autopilot',
title = 'Autopilot(Car/Foot)',
icon = 'plane',
items = {
{
id = 'startap',
title = 'Start Autopilot',
icon = 'plane',
type = 'client',
event = 'Bucko_autopilot:client:StartAutoPilot',
shouldClose = true
}, {
id = 'stopap',
title = 'Stop Autopilot',
icon = 'plane',
type = 'client',
event = 'Bucko_autopilot:client:StopAutoPilot',
shouldClose = true
}
}
},