DRIVING SCHOOL
Fivem Driving School Script
Last updated
Fivem Driving School Script
Last updated
This command is used to check the vehicle license.
RegisterCommand('checklicense', function(src)
TriggerEvent('checkLicense', src, 'driver', function(cb) end)
end)
The active license types are:
car
motor
drive_truck
air
boat
removelicense
Command
This command is used to remove a license from a specific source.
RegisterCommand('removelicense', function(src)
TriggerEvent('es:removeLicense', src, 'driver', function(cb) end)
end)
Description: The removelicense
command takes the src
source identifier and triggers the es:removeLicense
event.
Usage: Use the /removelicense
command to remove the driver
license from a specific source.
addlicense
CommandThis command is used to add a license to a specific source.
RegisterCommand('addlicense', function(src)
TriggerEvent('es:addLicense', src, 'driver', function(cb) end)
end)
Description: The addlicense
command takes the src
source identifier and triggers the es:addLicense
event.
Usage: Use the /addlicense
command to add the driver
license to a specific source.
If you uncomment the lines, it indicates that the car needs to go to the markers listed in the table.
if class == 'car' then
license = "driver" -- licenses
model = "brioso"
time = 1 -- time to go in minutes
position = {
[1] = vector4(237.5877, -1411.54, 30.585, 324.88),
[2] = vector4(240.6085, -1414.08, 30.585, 324.88),
[3] = vector4(243.7705, -1415.82, 30.585, 324.88)
}
locations = {
{x = 255.139, y = -1400.731, z = 29.537},
-- {x = 271.874, y = -1370.574, z = 30.932},
-- {x = 234.907, y = -1345.385, z = 29.542},
-- {x = 217.821, y = -1410.520, z = 28.292},
-- {x = 178.550, y = -1401.755, z = 27.725},
-- {x = 113.160, y = -1365.276, z = 27.725},
-- {x = -73.542, y = -1364.335, z = 27.789},
-- {x = -355.143, y = -1420.282, z = 27.868},
-- {x = -439.148, y = -1417.100, z = 27.704},
-- {x = -453.790, y = -1444.726, z = 27.665},
-- {x = -463.237, y = -1592.178, z = 37.519},
-- {x = -900.647, y = -1986.28, z = 26.109},
-- {x = 1225.759, y = -1948.792, z = 38.718},
-- {x = 1163.603, y = -1841.771, z = 35.679},
-- {x = 235.283, y = -1398.329, z = 28.921},
}
-- These lines of code represent the markers the car needs to go to and collect.
-- If you uncomment the lines, it indicates that the car needs to go to the markers listed in the table.
end
1. General Configuration
The general configuration section includes the framework settings, MySQL settings, and Discord token for integration.
Config = {}
Config.Framework = "NewESX" -- QBCore or ESX or OLDQBCore -- NewESX
Config.MySQL = "oxmysql" -- mysql-async or oxmysql or ghmattimysql
Config.Discord = "discord-api" -- https://discord.com/developers/applications
Config.allowedJobs = {
['police'] = true,
}
2. Framework Integration Function
A function to integrate the script with different frameworks like ESX, NewESX, and QBCore.
function GetFramework()
local Get = nil
if Config.Framework == "ESX" then
while Get == nil do
TriggerEvent('esx:getSharedObject', function(Set) Get = Set end)
Citizen.Wait(0)
end
end
if Config.Framework == "NewESX" then
Get = exports['es_extended']:getSharedObject()
end
if Config.Framework == "QBCore" then
Get = exports["qb-core"]:GetCoreObject()
end
if Config.Framework == "OldQBCore" then
while Get == nil do
TriggerEvent('QBCore:GetObject', function(Set) Get = Set end)
Citizen.Wait(200)
end
end
return Get
end
3. Driving School Locations
Define the locations for your driving school, including coordinates, NPC details, markers, and blips.
Config.Locations = {
{
allowlist = {'car', 'motor'},
coords = vector3(240.197800, -1379.841797, 32.728149),
hash = "mp_f_deadhooker",
heading = 150.00,
marker = "Car License",
blip = {
["active"] = true,
["name"] = "Car License",
["colour"] = 4,
["id"] = 56
},
},
{
allowlist = {'boat'},
coords = vector3(-784.602, -1355.61, 4.1502),
hash = "mp_f_deadhooker",
heading = 250.00,
marker = "Boat License",
blip = {
["active"] = true,
["name"] = "Boat License",
["colour"] = 16,
["id"] = 427
},
},
{
allowlist = {'air'},
coords = vector3(-950.17, -3010.01, 12.95),
hash = "s_m_m_pilot_01",
heading = 67.00,
marker = "Air License",
blip = {
["active"] = true,
["name"] = "Air License",
["colour"] = 16,
["id"] = 307
},
},
{
allowlist = {'truck'},
coords = vec3(842.81, -3069.45, 4.90),
hash = "s_m_m_trucker_01",
heading = 5.00,
marker = "Truck License",
blip = {
["active"] = true,
["name"] = "Truck License",
["colour"] = 16,
["id"] = 477,
},
},
}
4. License Position and Path
Define the positions and paths for each type of vehicle license, including vehicle model and time required for the test.
function Config.Position(class)
local position = nil
local locations = {}
local model = nil
if class == 'car' then
license = "driver" -- licenses
model = "brioso"
time = 1 -- you have to go in minutes.
position = {
[1] = vector4(237.5877, -1411.54, 30.585, 324.88),
[2] = vector4(240.6085, -1414.08, 30.585, 324.88),
[3] = vector4(243.7705, -1415.82, 30.585, 324.88)
}
locations = {
{x = 255.139, y = -1400.731, z = 29.537},
}
elseif class == 'motor' then
license = "drive_bike" -- licenses
model = "bf400"
time = 5 -- you have to go in minutes.
position = {
[1] = vector4(249.2097, -1408.50, 30.587, 100.5),
[2] = vector4(255.0357, -1401.72, 30.539, 100.5),
[3] = vector4(258.5333, -1399.33, 30.558, 100.5)
}
locations = {
{x = 255.139, y = -1400.731, z = 29.537},
{x = 271.874, y = -1370.574, z = 30.932},
{x = 234.907, y = -1345.385, z = 29.542},
{x = 217.821, y = -1410.520, z = 28.292},
{x = 178.550, y = -1401.755, z = 27.725},
{x = 113.160, y = -1365.276, z = 27.725},
{x = -73.542, y = -1364.335, z = 27.789},
{x = -355.143, y = -1420.282, z = 27.868},
{x = -439.148, y = -1417.100, z = 27.704},
{x = -453.790, y = -1444.726, z = 27.665},
{x = -463.237, y = -1592.178, z = 37.519},
{x = -900.647, y = -1986.28, z = 26.109},
{x = 1225.759, y = -1948.792, z = 38.718},
{x = 1163.603, y = -1841.771, z = 35.679},
{x = 235.283, y = -1398.329, z = 28.921},
}
elseif class == 'truck' then
license = "drive_truck" -- licenses
model = "tiptruck"
time = 15 -- you have to go in minutes.
position = {
[1] = vector4(811.78, -3050.33, 5.40, 359.99),
[2] = vector4(821.96, -3051.12, 5.41, 358.62),
[3] = vector4(829.96, -3050.40, 5.40, 359.78)
}
locations = {
{x = 806.09, y = -3043.05, z = 5.37},
{x = 779.83, y = -3027.33, z = 5.43},
{x = 744.45, y = -2892.91, z = 5.60},
{x = 743.42, y = -2817.75, z = 5.90},
{x = 742.74, y = -2767.72, z = 6.13},
{x = 741.22, y = -2592.61, z = 18.12},
{x = 768.20, y = -2268.96, z = 28.80},
{x = 772.66, y = -2076.78, z = 28.87},
}
elseif class == 'air' then
license = "air" -- licenses
model = "alphaz1"
time = 5 -- you have to go in minutes.
position = {
[1] = vector4(-978.00, -2996.83, 13.95, 60.83),
[2] = vector4(-988.07, -3014.03, 13.95, 56.44),
[3] = vector4(-967.80, -2980.53, 13.95, 58.20) ,
[4] = vector4(-958.88, -2967.23, 13.95, 53.60)
}
locations = {
{x = -1003.82, y = -2961.89, z = 13.71},
{x = -1058.60, y = -2929.94, z = 13.70},
{x = -1647.26, y = -3152.89, z = 13.99},
}
elseif class == 'boat' then
license = "boat" -- licenses
model = "suntrap"
time = 5 -- you have to go in minutes.
position = {
[1] = vector4(-753.524, -1363.46, 0.1195, 224.66),
[2] = vector4(-760.795, -1370.82, 0.1166, 224.66),
[3] = vector4(-767.027, -1379.37, 0.1274, 224.66),
[4] = vector4(-773.739, -1385.71, 0.1197, 224.66)
}
locations = {
{x = -796.262, y = -1432.34, z = 0.1112},
{x = -818.469, y = -1475.32, z = 0.1299},
{x = -867.933, y = -1551.02, z = 0.3263},
{x = -855.373, y = -1537.29, z = 0.4390},
{x = -899.997, y = -1584.91, z = 0.5197},
{x = -998.130, y = -1684.87, z = 0.2055},
{x = -1102.28, y = -1791.69, z = 0.3885},
{x = -1236.08, y = -1924.76, z = 0.5133},
{x = -1359.57, y = -1990.16, z = 0.2446},
{x = -1489.53, y = -2007.00, z = -0.076}
}
end
return position, locations, model, license, time
end
5. Blip Creation Function
A function to create blips on the map for each driving school location.
EYES = {}
EYES.Functions = {
CreateBlips = function()
for _, location in ipairs(Config.Locations) do
if location.blip.active then
local blip = AddBlipForCoord(location.coords)
SetBlipSprite(blip, location.blip.id)
SetBlipScale(blip, 0.5)
SetBlipAsShortRange(blip, true)
SetBlipColour(blip, location.blip.colour)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(location.blip.name)
EndTextCommandSetBlipName(blip)
end
end
end
}
6. Discord Integration Functions
Functions for making HTTP requests to the Discord API to retrieve user avatars and other data.
function DiscordRequest(method, endpoint, jsondata, callback)
PerformHttpRequest("https://discord.com/api/"..endpoint, function(errorCode, resultData, resultHeaders)
if errorCode == 200 then
local data = json.decode(resultData)
callback(data, nil)
else
callback(nil, errorCode)
end
end, method, #jsondata > 0 and json.encode(jsondata) or "", {["Content-Type"] = "application/json", ["Authorization"] = "Bot " .. Config.Discord})
end
function GetDiscordAvatar(userID, callback)
DiscordRequest("GET", "users/"..userID, {}, function(data, error)
if not error and data and data.avatar then
local avatarURL = string.format("https://cdn.discordapp.com/avatars/%s/%s.png", userID, data.avatar)
callback(avatarURL)
else
callback(nil)
end
end)
end
function HttpGet(url, callback)
PerformHttpRequest(url, function(err, result, headers)
if err == 200 then
local data = json.decode(result)
callback(data, nil)
else
callback(nil, err)
end
end, 'GET')
end
This guide helps you configure a driving school in your FiveM server by providing detailed examples for general configuration, location setup, vehicle licenses, and Discord integration. Customize each section to fit your server's needs and integrate these configurations into your GitBook documentation for clear and comprehensive instructions for your users.