From 6e70e5d806fa1745f677f8f41a532f54bf841f22 Mon Sep 17 00:00:00 2001 From: CommanderBALA <76389159+CommanderBALA@users.noreply.github.com> Date: Mon, 1 Jan 2024 10:29:48 +0100 Subject: [PATCH 1/5] Better Speeding check Better Speeding check system Configuration file changes in the next commit --- client/main.lua | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/client/main.lua b/client/main.lua index b28fc3a..61e49fb 100644 --- a/client/main.lua +++ b/client/main.lua @@ -9,7 +9,6 @@ local CurrentCheckPoint, DriveErrors = 0, 0 local LastCheckPoint = -1 local CurrentBlip = nil local CurrentZoneType = nil -local IsAboveSpeedLimit = false local LastVehicleHealth = nil function DrawMissionText(msg, time) @@ -320,46 +319,43 @@ end) 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 tooMuchSpeed = false - 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 - - ESX.ShowNotification(TranslateCap('driving_too_fast', v)) - ESX.ShowNotification(TranslateCap('errors', DriveErrors, Config.MaxErrors)) - end + DriveErrors += 1 + ESX.ShowNotification(TranslateCap('driving_too_fast', v)) + ESX.ShowNotification(TranslateCap('errors', DriveErrors, Config.MaxErrors)) + sleep = Config.SpeedingErrorDelay; end end + end + end + Wait(sleep) + end +end) - if not tooMuchSpeed then - IsAboveSpeedLimit = false - end - +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 health = GetEntityHealth(vehicle) if health < LastVehicleHealth then - DriveErrors += 1 - ESX.ShowNotification(TranslateCap('you_damaged_veh')) ESX.ShowNotification(TranslateCap('errors', DriveErrors, Config.MaxErrors)) -- avoid stacking faults LastVehicleHealth = health - sleep = 1500 + sleep = 1500; end end end From e0e69e6aee24fa14b9355aea5e943f7377d6076f Mon Sep 17 00:00:00 2001 From: CommanderBALA <76389159+CommanderBALA@users.noreply.github.com> Date: Mon, 1 Jan 2024 10:30:43 +0100 Subject: [PATCH 2/5] Better Speeding system config config.lua changes --- config.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/config.lua b/config.lua index 06c64ed..bcc7057 100644 --- a/config.lua +++ b/config.lua @@ -2,6 +2,7 @@ Config = {} Config.DrawDistance = 10.0 Config.MaxErrors = 5 Config.SpeedMultiplier = 3.6 +Config.SpeedingErrorDelay = 5000 Config.Locale = GetConvar('esx:locale', 'en') Config.Prices = { From 3deb78c11224a512893eadc4e59f1c5404768e7a Mon Sep 17 00:00:00 2001 From: CommanderBALA <76389159+CommanderBALA@users.noreply.github.com> Date: Sat, 17 Feb 2024 18:34:59 +0100 Subject: [PATCH 3/5] Update config.lua --- config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.lua b/config.lua index bcc7057..0a8c6c7 100644 --- a/config.lua +++ b/config.lua @@ -2,7 +2,7 @@ Config = {} Config.DrawDistance = 10.0 Config.MaxErrors = 5 Config.SpeedMultiplier = 3.6 -Config.SpeedingErrorDelay = 5000 +Config.SpeedingErrorDelay = 5000 --Min: 5000ms Config.Locale = GetConvar('esx:locale', 'en') Config.Prices = { From 916f8c4ffd226408bbbf03d427894a2688e01df8 Mon Sep 17 00:00:00 2001 From: CommanderBALA <76389159+CommanderBALA@users.noreply.github.com> Date: Sat, 17 Feb 2024 18:40:14 +0100 Subject: [PATCH 4/5] Update main.lua --- client/main.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/main.lua b/client/main.lua index 61e49fb..c675d7b 100644 --- a/client/main.lua +++ b/client/main.lua @@ -330,7 +330,7 @@ CreateThread(function() DriveErrors += 1 ESX.ShowNotification(TranslateCap('driving_too_fast', v)) ESX.ShowNotification(TranslateCap('errors', DriveErrors, Config.MaxErrors)) - sleep = Config.SpeedingErrorDelay; + sleep = (Config.SpeedingErrorDelay < 5000) and 5000 or Config.SpeedingErrorDelay end end end @@ -355,7 +355,7 @@ CreateThread(function() -- avoid stacking faults LastVehicleHealth = health - sleep = 1500; + sleep = 1500 end end end From 7840cb17ab73363c9f7f6ac123ee5bf6ac148e0b Mon Sep 17 00:00:00 2001 From: Gellipapa Date: Sat, 28 Sep 2024 16:48:59 +0200 Subject: [PATCH 5/5] :ambulance: Fix some errors, and refactor code --- client/main.lua | 70 ++++++++++++++++++++++++++--------------------- locales/de.lua | 1 + locales/en.lua | 1 + locales/es.lua | 1 + locales/fi.lua | 1 + locales/fr.lua | 1 + locales/hu.lua | 1 + locales/it.lua | 1 + locales/nl.lua | 1 + locales/pl.lua | 1 + locales/sr.lua | 1 + locales/sv.lua | 1 + locales/tr.lua | 1 + locales/zh-cn.lua | 1 + 14 files changed, 52 insertions(+), 31 deletions(-) diff --git a/client/main.lua b/client/main.lua index c675d7b..719cce1 100644 --- a/client/main.lua +++ b/client/main.lua @@ -10,6 +10,7 @@ local LastCheckPoint = -1 local CurrentBlip = nil local CurrentZoneType = nil local LastVehicleHealth = nil +local failedTest = false function DrawMissionText(msg, time) ClearPrints() @@ -60,6 +61,7 @@ function StartDriveTest(type) IsAboveSpeedLimit = false CurrentVehicle = vehicle LastVehicleHealth = GetEntityHealth(vehicle) + failedTest = false local playerPed = PlayerPedId() TaskWarpPedIntoVehicle(playerPed, vehicle, -1) @@ -72,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 @@ -245,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 @@ -315,6 +311,12 @@ CreateThread(function() end end) + +function TestFailedGoToLastCheckPoint() + CurrentCheckPoint = #Config.CheckPoints - 1 + failedTest = true +end + -- Speed / Damage control CreateThread(function() while true do @@ -322,43 +324,49 @@ CreateThread(function() 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 - for k,v in pairs(Config.SpeedLimits) do + local vehicle = GetVehiclePedIsIn(playerPed, false) + local speed = GetEntitySpeed(vehicle) * Config.SpeedMultiplier + local health = GetEntityHealth(vehicle) + + -- Speed check + for k, v in pairs(Config.SpeedLimits) do + if CurrentZoneType == k and speed > v then DriveErrors += 1 - ESX.ShowNotification(TranslateCap('driving_too_fast', v)) - ESX.ShowNotification(TranslateCap('errors', DriveErrors, Config.MaxErrors)) + + if DriveErrors <= Config.MaxErrors then + ESX.ShowNotification(TranslateCap('driving_too_fast', v)) + ESX.ShowNotification(TranslateCap('errors', DriveErrors, Config.MaxErrors)) + end + sleep = (Config.SpeedingErrorDelay < 5000) and 5000 or Config.SpeedingErrorDelay end end - end - end - Wait(sleep) - end -end) -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 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) + diff --git a/locales/de.lua b/locales/de.lua index 0ace2ae..ad705cc 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -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!', diff --git a/locales/en.lua b/locales/en.lua index 7258cb4..935fa83 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -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', diff --git a/locales/es.lua b/locales/es.lua index 1d67c11..999b674 100644 --- a/locales/es.lua +++ b/locales/es.lua @@ -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' diff --git a/locales/fi.lua b/locales/fi.lua index 88e3ab9..eea7d74 100644 --- a/locales/fi.lua +++ b/locales/fi.lua @@ -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' diff --git a/locales/fr.lua b/locales/fr.lua index e3db097..1759807 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -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' diff --git a/locales/hu.lua b/locales/hu.lua index 933ae7a..560b362 100644 --- a/locales/hu.lua +++ b/locales/hu.lua @@ -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!', diff --git a/locales/it.lua b/locales/it.lua index 3407982..11dcbd0 100644 --- a/locales/it.lua +++ b/locales/it.lua @@ -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', diff --git a/locales/nl.lua b/locales/nl.lua index c06ce9a..0ab6029 100644 --- a/locales/nl.lua +++ b/locales/nl.lua @@ -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', diff --git a/locales/pl.lua b/locales/pl.lua index b1527fc..f5ea6bc 100644 --- a/locales/pl.lua +++ b/locales/pl.lua @@ -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' diff --git a/locales/sr.lua b/locales/sr.lua index 4386aa6..e3507a5 100644 --- a/locales/sr.lua +++ b/locales/sr.lua @@ -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', diff --git a/locales/sv.lua b/locales/sv.lua index 11c98c4..9a72f05 100644 --- a/locales/sv.lua +++ b/locales/sv.lua @@ -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', diff --git a/locales/tr.lua b/locales/tr.lua index 615a333..924f7fb 100644 --- a/locales/tr.lua +++ b/locales/tr.lua @@ -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', diff --git a/locales/zh-cn.lua b/locales/zh-cn.lua index 4271222..549077b 100644 --- a/locales/zh-cn.lua +++ b/locales/zh-cn.lua @@ -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'] = '您暂无足够现金',