Skip to content

Commit

Permalink
Merge pull request #45 from esx-framework/CommanderBALA/main
Browse files Browse the repository at this point in the history
Better Speeding check system (Fix Gellipapa)
  • Loading branch information
Gellipapa authored Sep 28, 2024
2 parents 3e570c3 + 7840cb1 commit a348a37
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 31 deletions.
66 changes: 35 additions & 31 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ local CurrentCheckPoint, DriveErrors = 0, 0
local LastCheckPoint = -1
local CurrentBlip = nil
local CurrentZoneType = nil
local IsAboveSpeedLimit = false
local LastVehicleHealth = nil
local failedTest = false

function DrawMissionText(msg, time)
ClearPrints()
Expand Down Expand Up @@ -61,6 +61,7 @@ function StartDriveTest(type)
IsAboveSpeedLimit = false
CurrentVehicle = vehicle
LastVehicleHealth = GetEntityHealth(vehicle)
failedTest = false

local playerPed = PlayerPedId()
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
Expand All @@ -73,6 +74,7 @@ function StopDriveTest(success)
if success then
TriggerServerEvent('esx_dmvschool:addLicense', CurrentTestType)
ESX.ShowNotification(TranslateCap('passed_test'))
ESX.ShowNotification(TranslateCap('driving_test_complete'))
else
ESX.ShowNotification(TranslateCap('failed_test'))
end
Expand Down Expand Up @@ -246,14 +248,7 @@ CreateThread(function()
end

CurrentTest = nil

ESX.ShowNotification(TranslateCap('driving_test_complete'))

if DriveErrors < Config.MaxErrors then
StopDriveTest(true)
else
StopDriveTest(false)
end
StopDriveTest(DriveErrors < Config.MaxErrors)
else
if CurrentCheckPoint ~= LastCheckPoint then
if DoesBlipExist(CurrentBlip) then
Expand Down Expand Up @@ -316,53 +311,62 @@ CreateThread(function()
end
end)


function TestFailedGoToLastCheckPoint()
CurrentCheckPoint = #Config.CheckPoints - 1
failedTest = true
end

-- Speed / Damage control
CreateThread(function()
while true do
local sleep = 1500

if CurrentTest == 'drive' then
sleep = 0
local playerPed = PlayerPedId()

if IsPedInAnyVehicle(playerPed, false) then
local vehicle = GetVehiclePedIsIn(playerPed, false)
local speed = GetEntitySpeed(vehicle) * Config.SpeedMultiplier
local health = GetEntityHealth(vehicle)

local vehicle = GetVehiclePedIsIn(playerPed, false)
local speed = GetEntitySpeed(vehicle) * Config.SpeedMultiplier
local tooMuchSpeed = false
-- Speed check
for k, v in pairs(Config.SpeedLimits) do

for k,v in pairs(Config.SpeedLimits) do
if CurrentZoneType == k and speed > v then
tooMuchSpeed = true

if not IsAboveSpeedLimit then
DriveErrors += 1
IsAboveSpeedLimit = true
DriveErrors += 1

if DriveErrors <= Config.MaxErrors then
ESX.ShowNotification(TranslateCap('driving_too_fast', v))
ESX.ShowNotification(TranslateCap('errors', DriveErrors, Config.MaxErrors))
end
end
end

if not tooMuchSpeed then
IsAboveSpeedLimit = false
sleep = (Config.SpeedingErrorDelay < 5000) and 5000 or Config.SpeedingErrorDelay
end
end

local health = GetEntityHealth(vehicle)
-- Vehicle damage check
if health < LastVehicleHealth then

DriveErrors += 1

ESX.ShowNotification(TranslateCap('you_damaged_veh'))
ESX.ShowNotification(TranslateCap('errors', DriveErrors, Config.MaxErrors))

-- avoid stacking faults
if DriveErrors <= Config.MaxErrors then
ESX.ShowNotification(TranslateCap('you_damaged_veh'))
ESX.ShowNotification(TranslateCap('errors', DriveErrors, Config.MaxErrors))
end

LastVehicleHealth = health
sleep = 1500
end

if DriveErrors > Config.MaxErrors then
ESX.ShowNotification(TranslateCap('test_failed_go_to_start_point'))
if not failedTest then
TestFailedGoToLastCheckPoint()
end
sleep = 5000
end
end
end
Wait(sleep)
end
end)

1 change: 1 addition & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Config = {}
Config.DrawDistance = 10.0
Config.MaxErrors = 5
Config.SpeedMultiplier = 3.6
Config.SpeedingErrorDelay = 5000 --Min: 5000ms
Config.Locale = GetConvar('esx:locale', 'en')

Config.Prices = {
Expand Down
1 change: 1 addition & 0 deletions locales/de.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Locales['de'] = {
['driving_school_blip'] = 'Fahrschule',
['driving_test_complete'] = 'Führerschein Test beendet!',
['driving_too_fast'] = '~r~Du bist zu Schnell Das derzeitige Geschwindigkeitslimit beträgt: %s km/h!',
['test_failed_go_to_start_point'] = '~r~Go to the starting point, because you failed the test!',
['errors'] = 'Fehler: ~r~%s/%s',
['you_damaged_veh'] = 'Du hast das Fahrzeug beschädigt!',
['not_enough_money'] = 'Du hast nicht genug Geld!',
Expand Down
1 change: 1 addition & 0 deletions locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Locales['en'] = {
['driving_school_blip'] = 'driving School',
['driving_test_complete'] = 'driving test completed',
['driving_too_fast'] = '~r~You\'re driving too fast, the current speed limit is: %s km/h!',
['test_failed_go_to_start_point'] = '~r~Go to the starting point, because you failed the test!',
['errors'] = 'mistakes: ~r~%s/%s',
['you_damaged_veh'] = 'you damaged the vehicle',
['not_enough_money'] = 'You don\'t have enough money',
Expand Down
1 change: 1 addition & 0 deletions locales/es.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Locales['es'] = {
['driving_school_blip'] = 'Autoescuela',
['driving_test_complete'] = 'Examen de conducir finalizado',
['driving_too_fast'] = '¡~r~Estás conduciendo muy rápido, el límite de velocidad actual es: %s km/h!',
['test_failed_go_to_start_point'] = '~r~Go to the starting point, because you failed the test!',
['errors'] = 'Fallos: ~r~%s / %s',
['you_damaged_veh'] = '¡Has dañado el vehículo!',
['not_enough_money'] = 'No tienes suficiente dinero'
Expand Down
1 change: 1 addition & 0 deletions locales/fi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Locales['fi'] = {
['driving_school_blip'] = 'Autokoulu',
['driving_test_complete'] = 'ajokoe suoritettu',
['driving_too_fast'] = '~r~Ajat liian nopeaa! Hidasta! Nopeusrajoitus: %s km/h!',
['test_failed_go_to_start_point'] = '~r~Go to the starting point, because you failed the test!',
['errors'] = 'mistakes: ~r~%s/%s',
['you_damaged_veh'] = 'Vahingoitit ajoneuvoa. Aja varovaisemmin...',
['not_enough_money'] = 'Sinulla ei ole tarpeeksi rahaa'
Expand Down
1 change: 1 addition & 0 deletions locales/fr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Locales['fr'] = {
['driving_school_blip'] = 'auto-école',
['driving_test_complete'] = 'Test de conduite terminé',
['driving_too_fast'] = 'Vous roulez trop vite, vitesse limite: %s km/h!',
['test_failed_go_to_start_point'] = '~r~Go to the starting point, because you failed the test!',
['errors'] = 'erreurs: ~r~%s/%s',
['you_damaged_veh'] = 'Vous avez endommagé votre véhicule',
['not_enough_money'] = 'Tu n\'as pas assez d\'argent'
Expand Down
1 change: 1 addition & 0 deletions locales/hu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Locales['hu'] = {
['driving_school_blip'] = 'Autósiskola',
['driving_test_complete'] = 'A vizsga sikeres volt',
['driving_too_fast'] = '~r~Túl gyorsan hajtasz,a végén még megállít a rendőr. A sebesség határ: %s km/h!',
['test_failed_go_to_start_point'] = '~r~Menj a kezdőpontra mert a elbuktad a vizsgát!',
['errors'] = 'Hibapontok: ~r~%s/%s',
['you_damaged_veh'] = 'Összetörted az autót, ez drága lesz.',
['not_enough_money'] = 'Nincs elég pénzed!',
Expand Down
1 change: 1 addition & 0 deletions locales/it.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Locales['it'] = {
['driving_school_blip'] = 'scuola guida',
['driving_test_complete'] = 'test di guida completato',
['driving_too_fast'] = '~r~stai guidando troppo veloce, il limite di velocità attuale è: %s km/h!',
['test_failed_go_to_start_point'] = '~r~Go to the starting point, because you failed the test!',
['errors'] = 'errori: ~r~%s/%s',
['you_damaged_veh'] = 'hai danneggiato il veicolo',
['not_enough_money'] = 'non hai abbastanza soldi',
Expand Down
1 change: 1 addition & 0 deletions locales/nl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Locales['nl'] = {
['driving_school_blip'] = 'CBR',
['driving_test_complete'] = 'Praktijk examen gedaan',
['driving_too_fast'] = '~r~Je rijd te snel! De snelheids limiet is: %s km/h!',
['test_failed_go_to_start_point'] = '~r~Go to the starting point, because you failed the test!',
['errors'] = 'Fouten: ~r~%s/%s',
['you_damaged_veh'] = 'Je hebt het voertuig beschadigd',
['not_enough_money'] = 'Je hebt niet genoeg geld',
Expand Down
1 change: 1 addition & 0 deletions locales/pl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Locales['pl'] = {
['driving_school_blip'] = 'ośrodek egzaminacyjny',
['driving_test_complete'] = 'test praktyczny zakończony',
['driving_too_fast'] = '~r~Przekroczenie prędkości! , limit prędkości to: %s km/h!',
['test_failed_go_to_start_point'] = '~r~Go to the starting point, because you failed the test!',
['errors'] = 'błędy: ~r~%s/%s',
['you_damaged_veh'] = 'uszkodziłeś auto',
['not_enough_money'] = 'Nie masz wystarczająco dużo pieniędzy'
Expand Down
1 change: 1 addition & 0 deletions locales/sr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Locales['sr'] = {
['driving_school_blip'] = 'AutoŠkola',
['driving_test_complete'] = 'Polaganje vožnje završeno',
['driving_too_fast'] = '~r~Vozite prebrzo, trenutno ograničenje brzine: %s km/h!',
['test_failed_go_to_start_point'] = '~r~Go to the starting point, because you failed the test!',
['errors'] = 'Greške: ~r~%s/%s',
['you_damaged_veh'] = 'Oštetili ste vozilo',
['not_enough_money'] = 'Nemate dovoljno novca',
Expand Down
1 change: 1 addition & 0 deletions locales/sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Locales['sv'] = {
['driving_school_blip'] = 'Körskola',
['driving_test_complete'] = 'Körprov avklarat',
['driving_too_fast'] = '~r~Du kör för fort, tillåtna hastighet är: %s km/h!',
['test_failed_go_to_start_point'] = '~r~Go to the starting point, because you failed the test!',
['errors'] = 'Misstag: ~r~%s/%s',
['you_damaged_veh'] = 'Du skadade fordonet',
['not_enough_money'] = 'Du har inte tillräckligt med pengar',
Expand Down
1 change: 1 addition & 0 deletions locales/tr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Locales['tr'] = {
['driving_school_blip'] = 'Sürücü Okulu',
['driving_test_complete'] = 'Sürüş testi tamamlandı',
['driving_too_fast'] = '~r~Çok hızlı sürüyorsunuz, mevcut hız sınırı: %s km/sa!',
['test_failed_go_to_start_point'] = '~r~Go to the starting point, because you failed the test!',
['errors'] = 'Hatalar: ~r~%s/%s',
['you_damaged_veh'] = 'Araç hasar gördü',
['not_enough_money'] = 'Yeterli paranız yok',
Expand Down
1 change: 1 addition & 0 deletions locales/zh-cn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Locales['zh-cn'] = {
['driving_school_blip'] = '驾校',
['driving_test_complete'] = '驾驶考试完成',
['driving_too_fast'] = '驾驶载具速度过快, 注意限速: %s km/h!',
['test_failed_go_to_start_point'] = '~r~Go to the starting point, because you failed the test!',
['errors'] = '失误: ~r~%s~s~/~g~%s~s~',
['you_damaged_veh'] = '载具出现受损!',
['not_enough_money'] = '您暂无足够现金',
Expand Down

0 comments on commit a348a37

Please sign in to comment.