From 99144215fcccf436ff50f8d858174cc461f3dc0c Mon Sep 17 00:00:00 2001 From: Djamuras Date: Thu, 28 May 2020 21:54:46 +0300 Subject: [PATCH] Check if you have enough money --- server/main.lua | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) 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)