253 lines
7.3 KiB
Lua
253 lines
7.3 KiB
Lua
-- DMV School
|
|
-- Tech Development - https://discord.gg/tHAbhd94vS
|
|
local ESX = exports.es_extended:getSharedObject()
|
|
|
|
postNUI = function(data)
|
|
SendNUIMessage(data)
|
|
end
|
|
|
|
OpenDMV = function()
|
|
ESX.TriggerServerCallback('ricky-dmv:getData', function(licenses, money, bank)
|
|
postNUI({
|
|
type = "SET_CONFIG",
|
|
config = Config
|
|
})
|
|
postNUI({
|
|
type = "SET_MONEY",
|
|
contanti = bank,
|
|
banca = bank
|
|
})
|
|
postNUI({
|
|
type = "OPEN",
|
|
licenses = licenses,
|
|
license = Config.License
|
|
})
|
|
SetNuiFocus(true, true)
|
|
TriggerScreenblurFadeIn(500)
|
|
end)
|
|
end
|
|
|
|
RegisterNUICallback('close', function()
|
|
SetNuiFocus(false, false)
|
|
TriggerScreenblurFadeOut(500)
|
|
end)
|
|
|
|
RegisterNUICallback('removeMoney', function(data)
|
|
local account = data.account
|
|
local amount = tonumber(data.amount)
|
|
TriggerServerEvent('ricky-dmv:removeMoney', account, amount)
|
|
end)
|
|
|
|
RegisterNetEvent('ricky-dmv:updateLicense')
|
|
AddEventHandler('ricky-dmv:updateLicense', function()
|
|
ESX.TriggerServerCallback('ricky-dmv:getData', function(licenses)
|
|
postNUI({
|
|
type = "UPDATE_LICENSE",
|
|
licenses = licenses,
|
|
})
|
|
end)
|
|
end)
|
|
|
|
RegisterNUICallback('theoryOk', function(data)
|
|
local license = data.license
|
|
onCompleteTheory(license)
|
|
end)
|
|
|
|
RegisterNUICallback('practiceOk', function(data)
|
|
local license = data.license
|
|
onCompletePractice(license)
|
|
end)
|
|
|
|
|
|
local step = 0
|
|
local maxSpeed = nil
|
|
local sleep = 1000
|
|
local error = 0
|
|
local currentRouteIndex = nil
|
|
local currentBlip = nil
|
|
local practiceActive = false
|
|
|
|
local function removeCurrentBlip()
|
|
if currentBlip and DoesBlipExist(currentBlip) then
|
|
RemoveBlip(currentBlip)
|
|
currentBlip = nil
|
|
end
|
|
end
|
|
|
|
local function createMissionBlip(coords)
|
|
if not coords then return end
|
|
removeCurrentBlip()
|
|
local blip = AddBlipForCoord(coords.x, coords.y, coords.z)
|
|
SetBlipSprite(blip, 1)
|
|
SetBlipColour(blip, 5)
|
|
SetBlipScale(blip, 1.2)
|
|
SetBlipRoute(blip, true)
|
|
SetBlipRouteColour(blip, 5)
|
|
BeginTextCommandSetBlipName("STRING")
|
|
AddTextComponentString("Prüfungspunkt")
|
|
EndTextCommandSetBlipName(blip)
|
|
currentBlip = blip
|
|
end
|
|
|
|
local function spawnAtDMV()
|
|
local dmvCoords = Config.DMVSchool[1]
|
|
RequestCollisionAtCoord(dmvCoords.x, dmvCoords.y, dmvCoords.z)
|
|
SetEntityCoords(PlayerPedId(), dmvCoords.x, dmvCoords.y, dmvCoords.z, false, false, false, true)
|
|
end
|
|
|
|
local function endPractice(aborted)
|
|
if not practiceActive then return end
|
|
practiceActive = false
|
|
|
|
removeCurrentBlip()
|
|
ClearGpsPlayerWaypoint()
|
|
currentRouteIndex = nil
|
|
|
|
local veh = GetVehiclePedIsIn(PlayerPedId(), false)
|
|
if veh and veh ~= 0 then
|
|
ESX.Game.DeleteVehicle(veh)
|
|
end
|
|
|
|
-- Spieler zur Fahrschule teleportieren
|
|
spawnAtDMV()
|
|
|
|
local errori = error
|
|
step = 0
|
|
sleep = 1000
|
|
error = 0
|
|
|
|
if aborted then
|
|
-- Prüfung abgebrochen wegen zu vieler Fehler
|
|
ESX.ShowNotification(Config.Lang[Config.Language]["practice_error"])
|
|
postNUI({ type = "DISPLAY_RISULTATO", errori = errori, failed = true })
|
|
else
|
|
postNUI({ type = "DISPLAY_RISULTATO", errori = errori })
|
|
end
|
|
|
|
SetNuiFocus(true, true)
|
|
TriggerScreenblurFadeIn(500)
|
|
end
|
|
|
|
SetUpMarker = function()
|
|
if not practiceActive then return end
|
|
|
|
step = step + 1
|
|
if currentRouteIndex == nil then
|
|
currentRouteIndex = math.random(1, #Config.PracticeCoords)
|
|
end
|
|
local coords = Config.PracticeCoords[currentRouteIndex]
|
|
coords = coords[step]
|
|
|
|
if coords == nil then
|
|
endPractice(false)
|
|
return
|
|
end
|
|
|
|
maxSpeed = coords.speedLimit or nil
|
|
coords = coords.coordinate
|
|
|
|
if not coords then
|
|
endPractice(false)
|
|
return
|
|
end
|
|
|
|
createMissionBlip(coords)
|
|
sleep = 0
|
|
|
|
Citizen.CreateThread(function()
|
|
while practiceActive do
|
|
Citizen.Wait(sleep)
|
|
|
|
local playerPed = PlayerPedId()
|
|
local vehicle = GetVehiclePedIsIn(playerPed, false)
|
|
local myCoords = GetEntityCoords(playerPed)
|
|
local distance = GetDistanceBetweenCoords(coords.x, coords.y, coords.z, myCoords, true)
|
|
|
|
-- Gelber Bodenmarker am Zielpunkt
|
|
DrawMarker(27, coords.x, coords.y, coords.z, 0, 0, 0, 0, 0, 0, 3.0, 3.0, 1.0, 255, 200, 0, 180, false, true, 2, false, false, false, false)
|
|
|
|
if vehicle and vehicle ~= 0 then
|
|
local speed = GetEntitySpeed(vehicle) * Config.SpeedMultiplier
|
|
|
|
-- Geschwindigkeitsfehler prüfen
|
|
if maxSpeed ~= nil and speed > maxSpeed then
|
|
sleep = 1000
|
|
error = error + 1
|
|
ESX.ShowNotification("~r~Fehler " .. error .. "/" .. Config.MaxErrors .. ": ~w~" .. Config.Lang[Config.Language]["speed_error"])
|
|
|
|
-- Prüfung abbrechen bei zu vielen Fehlern
|
|
if error >= Config.MaxErrors then
|
|
ESX.ShowNotification("~r~Prüfung abgebrochen! ~w~Zu viele Fehler.")
|
|
endPractice(true)
|
|
break
|
|
end
|
|
else
|
|
sleep = 0
|
|
end
|
|
|
|
-- Auf 50 km/h begrenzen direkt am Checkpoint
|
|
if distance < 8.0 then
|
|
SetVehicleMaxSpeed(vehicle, 50.0 / 3.6)
|
|
else
|
|
SetVehicleMaxSpeed(vehicle, 0.0)
|
|
end
|
|
end
|
|
|
|
-- Checkpoint erreicht
|
|
if distance < 2.5 then
|
|
if vehicle and vehicle ~= 0 then
|
|
SetVehicleMaxSpeed(vehicle, 0.0)
|
|
end
|
|
SetUpMarker()
|
|
break
|
|
end
|
|
end
|
|
end)
|
|
end
|
|
|
|
|
|
RegisterNUICallback('startPractice', function(data)
|
|
local license = data.license
|
|
practiceActive = true
|
|
error = 0
|
|
step = 0
|
|
currentRouteIndex = nil
|
|
for k,v in pairs(Config.License) do
|
|
if v.id == license then
|
|
local vehicle = v.vehicle
|
|
ESX.Game.SpawnVehicle(vehicle.model, vehicle.coords, vehicle.heading, function(veh)
|
|
SetVehicleNumberPlateText(veh, vehicle.plate)
|
|
SetPedIntoVehicle(PlayerPedId(), veh, -1)
|
|
Citizen.CreateThread(function()
|
|
Wait(500)
|
|
-- VEHICLES KEYS INTEGRATION
|
|
TriggerServerEvent("vehicles_keys:selfGiveCurrentVehicleKeys")
|
|
end)
|
|
end)
|
|
end
|
|
end
|
|
SetUpMarker()
|
|
end)
|
|
|
|
|
|
local sleep2 = 1000
|
|
Citizen.CreateThread(function()
|
|
while true do
|
|
Citizen.Wait(sleep2)
|
|
for k,v in pairs(Config.DMVSchool) do
|
|
DrawMarker(Config.MarkerSettings.type, v.x, v.y, v.z, 0, 0, 0, 0, 0, 0, Config.MarkerSettings.size, Config.MarkerSettings.color, 100, Config.MarkerSettings.bump, true, 2, Config.MarkerSettings.rotate, false, false, false)
|
|
|
|
local distance = GetDistanceBetweenCoords(v.x, v.y, v.z, GetEntityCoords(PlayerPedId()), true)
|
|
if distance < 5.5 then
|
|
sleep2 = 0
|
|
ESX.ShowHelpNotification(Config.Lang[Config.Language]["open_dmv"])
|
|
if IsControlJustReleased(0, 38) then
|
|
OpenDMV()
|
|
end
|
|
else
|
|
sleep2 = 1000
|
|
end
|
|
end
|
|
end
|
|
end)
|