diff --git a/client/main.lua b/client/main.lua index cd7012a2..41e48b14 100644 --- a/client/main.lua +++ b/client/main.lua @@ -38,7 +38,7 @@ function StartTheoryTest() SetNuiFocus(true, true) end) - TriggerServerEvent('esx_dmvschool:pay', Config.Prices['dmv']) + end function StopTheoryTest(success) @@ -75,8 +75,6 @@ function StartDriveTest(type) SetVehicleFuelLevel(vehicle, 100.0) DecorSetFloat(vehicle, "_FUEL_LEVEL", GetVehicleFuelLevel(vehicle)) end) - - TriggerServerEvent('esx_dmvschool:pay', Config.Prices[type]) end function StopDriveTest(success) @@ -146,9 +144,22 @@ function OpenDMVSchoolMenu() }, function(data, menu) if data.current.value == 'theory_test' then menu.close() - StartTheoryTest() + ESX.TriggerServerCallback('esx_dmvschool:canYouPay', function(haveMoney) + if haveMoney then + StartTheoryTest() + else + ESX.ShowNotification(_U('not_enough_money')) + end + end, 'dmv') elseif data.current.value == 'drive_test' then - StartDriveTest(data.current.type) + menu.close() + ESX.TriggerServerCallback('esx_dmvschool:canYouPay', function(haveMoney) + if haveMoney then + StartDriveTest(data.current.type) + else + ESX.ShowNotification(_U('not_enough_money')) + end + end, data.current.type) end end, function(data, menu) menu.close() diff --git a/locales/en.lua b/locales/en.lua index 55c3c945..72adab8e 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -25,4 +25,5 @@ Locales['en'] = { ['driving_too_fast'] = '~r~You\'re driving too fast,~s~ the current speed limit is: ~y~%s~s~ km/h!', ['errors'] = 'mistakes: ~r~%s~s~/%s', ['you_damaged_veh'] = 'you damaged the vehicle', + ['not_enough_money'] = 'You don\'t have enough money', } diff --git a/server/main.lua b/server/main.lua index 6b7133b0..6eb493b1 100644 --- a/server/main.lua +++ b/server/main.lua @@ -2,6 +2,19 @@ ESX = nil TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) +ESX.RegisterServerCallback('esx_dmvschool:canYouPay', function(source, cb, type) + local xPlayer = ESX.GetPlayerFromId(source) + + if xPlayer.getMoney() >= Config.Prices[type] then + xPlayer.removeMoney(Config.Prices[type]) + TriggerClientEvent('esx:showNotification', source, _U('you_paid', Config.Prices[type])) + cb(true) + else + cb(false) + end +end) + + AddEventHandler('esx:playerLoaded', function(source) TriggerEvent('esx_license:getLicenses', source, function(licenses) TriggerClientEvent('esx_dmvschool:loadLicenses', source, licenses) @@ -19,11 +32,3 @@ AddEventHandler('esx_dmvschool:addLicense', function(type) end) end) -RegisterNetEvent('esx_dmvschool:pay') -AddEventHandler('esx_dmvschool:pay', function(price) - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) - - xPlayer.removeMoney(price) - TriggerClientEvent('esx:showNotification', _source, _U('you_paid', ESX.Math.GroupDigits(price))) -end)