From 5e8b248e0a51ece35de2d43440e998651ff9c167 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Sat, 7 Dec 2019 12:44:36 +0100 Subject: [PATCH] Completed server-sided code, and fixed serious caution flaws --- README.md | 2 +- __resource.lua | 25 +++- client/main.lua | 49 ++++--- config.lua | 2 + {client/jobs => jobs}/fisherman.lua | 4 +- {client/jobs => jobs}/fueler.lua | 8 +- {client/jobs => jobs}/lumberjack.lua | 8 +- {client/jobs => jobs}/miner.lua | 14 +- {client/jobs => jobs}/reporter.lua | 0 {client/jobs => jobs}/slaughterer.lua | 8 +- {client/jobs => jobs}/tailor.lua | 8 +- locales/br.lua | 1 + locales/en.lua | 1 + locales/fi.lua | 1 + locales/fr.lua | 1 + locales/sv.lua | 1 + server/main.lua | 180 +++++++++++++++----------- 17 files changed, 181 insertions(+), 132 deletions(-) rename {client/jobs => jobs}/fisherman.lua (98%) rename {client/jobs => jobs}/fueler.lua (98%) rename {client/jobs => jobs}/lumberjack.lua (97%) rename {client/jobs => jobs}/miner.lua (97%) rename {client/jobs => jobs}/reporter.lua (100%) rename {client/jobs => jobs}/slaughterer.lua (97%) rename {client/jobs => jobs}/tailor.lua (98%) diff --git a/README.md b/README.md index 893f0492..9b58d298 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ start esx_jobs ### License esx_jobs - jobs -Copyright (C) 2015-2018 Jérémie N'gadi +Copyright (C) 2015-2019 Jérémie N'gadi This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version. diff --git a/__resource.lua b/__resource.lua index 5abaf658..2cf3ecb0 100644 --- a/__resource.lua +++ b/__resource.lua @@ -12,6 +12,15 @@ server_scripts { 'locales/fr.lua', 'locales/sv.lua', 'config.lua', + + 'jobs/fisherman.lua', + 'jobs/fueler.lua', + 'jobs/lumberjack.lua', + 'jobs/miner.lua', + 'jobs/reporter.lua', + 'jobs/slaughterer.lua', + 'jobs/tailor.lua', + 'server/main.lua' } @@ -23,13 +32,15 @@ client_scripts { 'locales/fr.lua', 'locales/sv.lua', 'config.lua', - 'client/jobs/fisherman.lua', - 'client/jobs/fueler.lua', - 'client/jobs/lumberjack.lua', - 'client/jobs/miner.lua', - 'client/jobs/reporter.lua', - 'client/jobs/slaughterer.lua', - 'client/jobs/tailor.lua', + + 'jobs/fisherman.lua', + 'jobs/fueler.lua', + 'jobs/lumberjack.lua', + 'jobs/miner.lua', + 'jobs/reporter.lua', + 'jobs/slaughterer.lua', + 'jobs/tailor.lua', + 'client/main.lua' } diff --git a/client/main.lua b/client/main.lua index 1db333c1..492c0a81 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,5 +1,5 @@ -local menuIsShowed, hintIsShowed, hintToDisplay, hasAlreadyEnteredMarker, isInMarker, onDuty, vehicleObjInCaseofDrop, vehicleInCaseofDrop, vehicleMaxHealth -local PlayerData, Blips, JobBlips, myPlate, spawner = {}, {}, {}, {}, 0 +local menuIsShowed, hintIsShowed, hintToDisplay, hasAlreadyEnteredMarker, isInMarker, vehicleObjInCaseofDrop, vehicleInCaseofDrop, vehicleMaxHealth +local PlayerData, Blips, JobBlips, myPlate, onDuty, spawner = {}, {}, {}, {}, false, 0 ESX = nil @@ -55,7 +55,7 @@ function OpenMenu() end) end -AddEventHandler('esx_jobs:action', function(job, zone) +AddEventHandler('esx_jobs:action', function(job, zone, zoneIndex) menuIsShowed = true if zone.Type == 'cloakroom' then OpenMenu() @@ -65,7 +65,7 @@ AddEventHandler('esx_jobs:action', function(job, zone) local playerPed = PlayerPedId() if IsPedOnFoot(playerPed) then - TriggerServerEvent('esx_jobs:startWork', zone.Item) + TriggerServerEvent('esx_jobs:startWork', zoneIndex) else ESX.ShowNotification(_U('foot_work')) end @@ -150,7 +150,7 @@ AddEventHandler('esx_jobs:action', function(job, zone) hintToDisplay = nil hintIsShowed = false - TriggerServerEvent('esx_jobs:startWork', zone.Item) + TriggerServerEvent('esx_jobs:startWork', zoneIndex) end --nextStep(zone.GPS) @@ -195,28 +195,25 @@ function deleteBlips() end function refreshBlips() - local zones = {} - local blipInfo = {} - if PlayerData.job then - for jobKey,jobValues in pairs(Config.Jobs) do + local jobObject = Config.Jobs[PlayerData.job.name] - if jobKey == PlayerData.job.name then - for zoneKey,zoneValues in pairs(jobValues.Zones) do + if jobObject then + for k,v in pairs(jobObject.Zones) do + if v.Blip then + local blip = AddBlipForCoord(v.Pos.x, v.Pos.y, v.Pos.z) - if zoneValues.Blip then - local blip = AddBlipForCoord(zoneValues.Pos.x, zoneValues.Pos.y, zoneValues.Pos.z) - SetBlipSprite (blip, jobValues.BlipInfos.Sprite) - SetBlipScale (blip, 1.2) - SetBlipCategory(blip, 3) - SetBlipColour (blip, jobValues.BlipInfos.Color) - SetBlipAsShortRange(blip, true) + SetBlipSprite (blip, jobObject.BlipInfos.Sprite) + SetBlipScale (blip, 1.2) + SetBlipCategory(blip, 3) + SetBlipColour (blip, jobObject.BlipInfos.Color) + SetBlipAsShortRange(blip, true) - BeginTextCommandSetBlipName('STRING') - AddTextComponentSubstringPlayerName(zoneValues.Name) - EndTextCommandSetBlipName(blip) - table.insert(JobBlips, blip) - end + BeginTextCommandSetBlipName('STRING') + AddTextComponentSubstringPlayerName(v.Name) + EndTextCommandSetBlipName(blip) + + table.insert(JobBlips, blip) end end end @@ -273,7 +270,7 @@ end) Citizen.CreateThread(function() while true do Citizen.Wait(0) - local zones, currentZone, isInMarker = {} + local zones, currentZone, currentZoneIndex, isInMarker = {} local letSleep, playerPed = true, PlayerPedId() local playerCoords = GetEntityCoords(playerPed) @@ -293,14 +290,14 @@ Citizen.CreateThread(function() end if distance < v.Size.x then - letSleep, isInMarker, currentZone = false, true, v + letSleep, isInMarker, currentZone, currentZoneIndex = false, true, v, k break end end if IsControlJustReleased(0, 38) and not menuIsShowed and isInMarker then if onDuty or currentZone.Type == 'cloakroom' or PlayerData.job.name == 'reporter' then - TriggerEvent('esx_jobs:action', PlayerData.job.name, currentZone) + TriggerEvent('esx_jobs:action', PlayerData.job.name, currentZone, currentZoneIndex) end end diff --git a/config.lua b/config.lua index 334f1357..676570e8 100644 --- a/config.lua +++ b/config.lua @@ -3,6 +3,8 @@ Config.DrawDistance = 100.0 Config.Locale = 'fr' Config.Jobs = {} +Config.MaxCaution = 10000 -- the max caution allowed + Config.PublicZones = { EnterBuilding = { diff --git a/client/jobs/fisherman.lua b/jobs/fisherman.lua similarity index 98% rename from client/jobs/fisherman.lua rename to jobs/fisherman.lua index 207bc146..f86e332d 100644 --- a/client/jobs/fisherman.lua +++ b/jobs/fisherman.lua @@ -51,7 +51,7 @@ Config.Jobs.fisherman = { { name = _U('fm_fish'), db_name= 'fish', - time = 2000, + time = 2, max = 100, add = 1, remove = 1, @@ -160,7 +160,7 @@ Config.Jobs.fisherman = { Item = { { name = _U('delivery'), - time = 500, + time = 0.5, remove = 1, max = 100, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua price = 11, diff --git a/client/jobs/fueler.lua b/jobs/fueler.lua similarity index 98% rename from client/jobs/fueler.lua rename to jobs/fueler.lua index f34922c5..8b6edeb6 100644 --- a/client/jobs/fueler.lua +++ b/jobs/fueler.lua @@ -42,7 +42,7 @@ Config.Jobs.fueler = { { name = _U('f_fuel'), db_name = 'petrol', - time = 5000, + time = 5, max = 24, add = 1, remove = 1, @@ -67,7 +67,7 @@ Config.Jobs.fueler = { { name = _U('f_fuel_refine'), db_name = 'petrol_raffin', - time = 5000, + time = 5, max = 24, add = 1, remove = 2, @@ -92,7 +92,7 @@ Config.Jobs.fueler = { { name = _U('f_gas'), db_name = 'essence', - time = 5000, + time = 5, max = 24, add = 2, remove = 1, @@ -158,7 +158,7 @@ Config.Jobs.fueler = { Item = { { name = _U('delivery'), - time = 500, + time = 0.5, remove = 1, max = 100, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua price = 61, diff --git a/client/jobs/lumberjack.lua b/jobs/lumberjack.lua similarity index 97% rename from client/jobs/lumberjack.lua rename to jobs/lumberjack.lua index e6892c27..5eca3b24 100644 --- a/client/jobs/lumberjack.lua +++ b/jobs/lumberjack.lua @@ -41,7 +41,7 @@ Config.Jobs.lumberjack = { { name = _U('lj_wood'), db_name = 'wood', - time = 3000, + time = 3, max = 20, add = 1, remove = 1, @@ -65,7 +65,7 @@ Config.Jobs.lumberjack = { { name = _U('lj_cutwood'), db_name = 'cutted_wood', - time = 5000, + time = 5, max = 20, add = 1, remove = 1, @@ -89,7 +89,7 @@ Config.Jobs.lumberjack = { { name = _U('lj_planks'), db_name = 'packaged_plank', - time = 4000, + time = 4, max = 100, add = 5, remove = 1, @@ -152,7 +152,7 @@ Config.Jobs.lumberjack = { Item = { { name = _U('delivery'), - time = 500, + time = 0.5, remove = 1, max = 100, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua price = 13, diff --git a/client/jobs/miner.lua b/jobs/miner.lua similarity index 97% rename from client/jobs/miner.lua rename to jobs/miner.lua index a26041fe..edbffb6d 100644 --- a/client/jobs/miner.lua +++ b/jobs/miner.lua @@ -42,7 +42,7 @@ Config.Jobs.miner = { { name = _U('m_rock'), db_name = 'stone', - time = 3000, + time = 3, max = 7, add = 1, remove = 1, @@ -67,7 +67,7 @@ Config.Jobs.miner = { { name = _U('m_washrock'), db_name = 'washed_stone', - time = 5000, + time = 5, max = 7, add = 1, remove = 1, @@ -92,7 +92,7 @@ Config.Jobs.miner = { { name = _U('m_copper'), db_name = 'copper', - time = 4000, + time = 4, max = 56, add = 8, remove = 1, @@ -179,7 +179,7 @@ Config.Jobs.miner = { Item = { { name = _U('delivery'), - time = 500, + time = 0.5, remove = 1, max = 56, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua price = 5, @@ -205,7 +205,7 @@ Config.Jobs.miner = { Item = { { name = _U('delivery'), - time = 500, + time = 0.5, remove = 1, max = 42, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua price = 9, @@ -231,7 +231,7 @@ Config.Jobs.miner = { Item = { { name = _U('delivery'), - time = 500, + time = 0.5, remove = 1, max = 21, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua price = 25, @@ -257,7 +257,7 @@ Config.Jobs.miner = { Item = { { name = _U('delivery'), - time = 500, + time = 0.5, remove = 1, max = 50, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua price = 250, diff --git a/client/jobs/reporter.lua b/jobs/reporter.lua similarity index 100% rename from client/jobs/reporter.lua rename to jobs/reporter.lua diff --git a/client/jobs/slaughterer.lua b/jobs/slaughterer.lua similarity index 97% rename from client/jobs/slaughterer.lua rename to jobs/slaughterer.lua index 1f7c26f2..d07077c6 100644 --- a/client/jobs/slaughterer.lua +++ b/jobs/slaughterer.lua @@ -40,7 +40,7 @@ Config.Jobs.slaughterer = { { name = _U('s_alive_chicken'), db_name = 'alive_chicken', - time = 3000, + time = 3, max = 20, add = 1, remove = 1, @@ -64,7 +64,7 @@ Config.Jobs.slaughterer = { { name = _U('s_slaughtered_chicken'), db_name = 'slaughtered_chicken', - time = 5000, + time = 5, max = 20, add = 1, remove = 1, @@ -88,7 +88,7 @@ Config.Jobs.slaughterer = { { name = _U('s_packagechicken'), db_name = 'packaged_chicken', - time = 4000, + time = 4, max = 100, add = 5, remove = 1, @@ -151,7 +151,7 @@ Config.Jobs.slaughterer = { Item = { { name = _U('delivery'), - time = 500, + time = 0.5, remove = 1, max = 100, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua price = 23, diff --git a/client/jobs/tailor.lua b/jobs/tailor.lua similarity index 98% rename from client/jobs/tailor.lua rename to jobs/tailor.lua index 2d805c7e..bac08078 100644 --- a/client/jobs/tailor.lua +++ b/jobs/tailor.lua @@ -42,7 +42,7 @@ Config.Jobs.tailor = { { name = _U('dd_wool'), db_name = 'wool', - time = 3000, + time = 3, max = 40, add = 1, remove = 1, @@ -67,7 +67,7 @@ Config.Jobs.tailor = { { name = _U('dd_fabric'), db_name = 'fabric', - time = 5000, + time = 5, max = 80, add = 2, remove = 1, @@ -92,7 +92,7 @@ Config.Jobs.tailor = { { name = _U('dd_clothing'), db_name = 'clothe', - time = 4000, + time = 4, max = 40, add = 1, remove = 2, @@ -158,7 +158,7 @@ Config.Jobs.tailor = { Item = { { name = _U('delivery'), - time = 500, + time = 0.5, remove = 1, max = 100, -- if not present, probably an error at itemQtty >= item.max in esx_jobs_sv.lua price = 40, diff --git a/locales/br.lua b/locales/br.lua index feff893a..013c4d1d 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -6,6 +6,7 @@ Locales['br'] = { ['job_wear'] = 'colocar uniforme', ['bank_deposit_returned'] = 'um depósito de segurança de ~g~$%s~s~ foi devolvido a você.', ['bank_deposit_taken'] = 'um depósito de segurança de ~g~$%s~s~ foi tirado de você.', + ['caution_afford'] = 'you cannot afford the caution of ~g~$%s~s~', ['foot_work'] = 'você deve estar a pé para poder trabalhar.', ['next_point'] = 'vá para o próximo passo depois de completar este.', ['not_your_vehicle'] = 'este não é o seu veículo ou você deve ser um motorista.', diff --git a/locales/en.lua b/locales/en.lua index 98cc6e61..5d04ac4b 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -6,6 +6,7 @@ Locales['en'] = { ['job_wear'] = 'workers clothes', ['bank_deposit_returned'] = 'a security deposit of ~g~$%s~s~ was returned to you.', ['bank_deposit_taken'] = 'a security deposit of ~r~$%s~s~ was taken from you.', + ['caution_afford'] = 'you cannot afford the caution of ~g~$%s~s~', ['foot_work'] = 'you have to be on foot to be able to work.', ['next_point'] = 'go to the next step after completing this one.', ['not_your_vehicle'] = 'you are not the driver of this vehicle.', diff --git a/locales/fi.lua b/locales/fi.lua index 2d84df38..51236475 100644 --- a/locales/fi.lua +++ b/locales/fi.lua @@ -6,6 +6,7 @@ Locales['fi'] = { ['job_wear'] = 'työvaatteet', ['bank_deposit_returned'] = 'vakuuden summa ~g~€%s~s~ palautettiin sinulle.', ['bank_deposit_taken'] = 'vakuuden summa ~r~€%s~s~ otettiin sinulta.', + ['caution_afford'] = 'you cannot afford the caution of ~g~$%s~s~', ['foot_work'] = 'sinun täytyy olla jalan, jotta voit työskennellä', ['next_point'] = 'mene seuraavaan pisteeseen kun olet valmis täällä', ['not_your_vehicle'] = 'tämä ei ole sinun ajoneuvo tai et ole sen kuski', diff --git a/locales/fr.lua b/locales/fr.lua index 55ebe0ed..7ec5fd24 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -6,6 +6,7 @@ Locales['fr'] = { ['job_wear'] = 'tenue de travail', ['bank_deposit_returned'] = 'une caution de ~g~$%s~s~ vous a été rendue.', ['bank_deposit_taken'] = 'une caution de ~g~$%s~s~ vous a été prélevée.', + ['caution_afford'] = 'you cannot afford the caution of ~g~$%s~s~', ['foot_work'] = 'vous devez être à pied pour pouvoir travailler.', ['next_point'] = 'rendez-vous à la prochaine étape après avoir complété celle-ci.', ['not_your_vehicle'] = 'ce n\'est pas votre véhicule ou vous devez être conducteur.', diff --git a/locales/sv.lua b/locales/sv.lua index 2d0c451f..49a99e88 100644 --- a/locales/sv.lua +++ b/locales/sv.lua @@ -6,6 +6,7 @@ Locales['sv'] = { ['job_wear'] = 'arbetskläder', ['bank_deposit_returned'] = 'en deposition på ~g~%s SEK~s~ har återvänts till dig.', ['bank_deposit_taken'] = 'en deposition på ~r~%s SEK~s~ togs från dig.', + ['caution_afford'] = 'you cannot afford the caution of ~g~$%s~s~', ['foot_work'] = 'du måste vara till fots för att kunna arbeta.', ['next_point'] = 'gå till nästa steg efter att du har avslutat här.', ['not_your_vehicle'] = 'det här är inte ditt fordon eller så måste du vara föraren.', diff --git a/server/main.lua b/server/main.lua index 6463a136..2541f01c 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,105 +1,139 @@ -local PlayersWorking = {} +local playersWorking = {} + ESX = nil TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) -local function Work(source, item) +Citizen.CreateThread(function() + while true do + Citizen.Wait(1000) + local timeNow = os.clock() - SetTimeout(item[1].time, function() + for playerId,data in pairs(playersWorking) do + Citizen.Wait(10) + local xPlayer = ESX.GetPlayerFromId(playerId) - if PlayersWorking[source] == true then + -- is player still online? + if xPlayer then + local distance = #(xPlayer.getCoords(true) - data.zoneCoords) - local xPlayer = ESX.GetPlayerFromId(source) - if xPlayer == nil then - return - end + -- player still within zone limits? + if distance <= data.zoneMaxDistance then + -- calculate the elapsed time + local timeElapsed = timeNow - data.time - for i=1, #item, 1 do - local itemQtty = 0 - if item[i].name ~= _U('delivery') then - itemQtty = xPlayer.getInventoryItem(item[i].db_name).count - end + if timeElapsed > data.jobItem[1].time then + data.time = os.clock() - local requiredItemQtty = 0 - if item[1].requires ~= 'nothing' then - requiredItemQtty = xPlayer.getInventoryItem(item[1].requires).count - end + for k,v in ipairs(data.jobItem) do + local itemQtty, requiredItemQtty = 0, 0 - if item[i].name ~= _U('delivery') and itemQtty >= item[i].max then - xPlayer.showNotification(_U('max_limit', item[i].name)) - elseif item[i].requires ~= 'nothing' and requiredItemQtty <= 0 then - xPlayer.showNotification(_U('not_enough', item[1].requires_name)) - else - if item[i].name ~= _U('delivery') then - -- Chances to drop the item - if item[i].drop == 100 then - xPlayer.addInventoryItem(item[i].db_name, item[i].add) - else - local chanceToDrop = math.random(100) - if chanceToDrop <= item[i].drop then - xPlayer.addInventoryItem(item[i].db_name, item[i].add) + if v.name ~= _U('delivery') then + itemQtty = xPlayer.getInventoryItem(v.db_name).count + end + + if data.jobItem[1].requires ~= 'nothing' then + requiredItemQtty = xPlayer.getInventoryItem(data.jobItem[1].requires).count + end + + if v.name ~= _U('delivery') and itemQtty >= v.max then + xPlayer.showNotification(_U('max_limit', v.name)) + playersWorking[playerId] = nil + elseif v.requires ~= 'nothing' and requiredItemQtty <= 0 then + xPlayer.showNotification(_U('not_enough', data.jobItem[1].requires_name)) + playersWorking[playerId] = nil + else + if v.name ~= _U('delivery') then + -- chances to drop the item + if v.drop == 100 then + xPlayer.addInventoryItem(v.db_name, v.add) + else + local chanceToDrop = math.random(100) + if chanceToDrop <= v.drop then + xPlayer.addInventoryItem(v.db_name, v.add) + end + end + else + xPlayer.addMoney(v.price) + end + end + end + + if data.jobItem[1].requires ~= 'nothing' then + local itemToRemoveQtty = xPlayer.getInventoryItem(data.jobItem[1].requires).count + if itemToRemoveQtty > 0 then + xPlayer.removeInventoryItem(data.jobItem[1].requires, data.jobItem[1].remove) end end - else - xPlayer.addMoney(item[i].price) end + else + playersWorking[playerId] = nil end + else + playersWorking[playerId] = nil end - - if item[1].requires ~= 'nothing' then - local itemToRemoveQtty = xPlayer.getInventoryItem(item[1].requires).count - if itemToRemoveQtty > 0 then - xPlayer.removeInventoryItem(item[1].requires, item[1].remove) - end - end - - Work(source, item) - end - end) -end + end +end) RegisterServerEvent('esx_jobs:startWork') -AddEventHandler('esx_jobs:startWork', function(item) - if not PlayersWorking[source] then - PlayersWorking[source] = true - Work(source, item) - else - print(('esx_jobs: %s attempted to exploit the marker!'):format(GetPlayerIdentifiers(source)[1])) +AddEventHandler('esx_jobs:startWork', function(zoneIndex) + if not playersWorking[source] then + local xPlayer = ESX.GetPlayerFromId(source) + + if xPlayer then + local jobObject = Config.Jobs[xPlayer.job.name] + + if jobObject then + local jobZone = jobObject.Zones[zoneIndex] + + if jobZone and jobZone.Item then + playersWorking[source] = { + jobItem = jobZone.Item, + zoneCoords = vector3(jobZone.Pos.x, jobZone.Pos.y, jobZone.Pos.z), + zoneMaxDistance = jobZone.Size.x, + time = os.clock() + } + end + end + end end end) RegisterServerEvent('esx_jobs:stopWork') AddEventHandler('esx_jobs:stopWork', function() - PlayersWorking[source] = false + if playersWorking[source] then + playersWorking[source] = nil + end end) -RegisterServerEvent('esx_jobs:caution') +RegisterNetEvent('esx_jobs:caution') AddEventHandler('esx_jobs:caution', function(cautionType, cautionAmount, spawnPoint, vehicle) local xPlayer = ESX.GetPlayerFromId(source) if cautionType == 'take' then - TriggerEvent('esx_addonaccount:getAccount', 'caution', xPlayer.identifier, function(account) - xPlayer.removeAccountMoney('bank', cautionAmount) - account.addMoney(cautionAmount) - end) - - xPlayer.showNotification(_U('bank_deposit_taken', ESX.Math.GroupDigits(cautionAmount))) - TriggerClientEvent('esx_jobs:spawnJobVehicle', source, spawnPoint, vehicle) - elseif cautionType == 'give_back' then - - if cautionAmount > 1 then - print(('esx_jobs: %s is using cheat engine!'):format(xPlayer.identifier)) - return + if cautionAmount <= Config.MaxCaution and cautionAmount > 0 then + TriggerEvent('esx_addonaccount:getAccount', 'caution', xPlayer.identifier, function(account) + if xPlayer.getAccount('bank').money >= cautionAmount then + xPlayer.removeAccountMoney('bank', cautionAmount) + account.addMoney(cautionAmount) + xPlayer.showNotification(_U('bank_deposit_taken', ESX.Math.GroupDigits(cautionAmount))) + TriggerClientEvent('esx_jobs:spawnJobVehicle', xPlayer.source, spawnPoint, vehicle) + else + xPlayer.showNotification(_U('caution_afford', ESX.Math.GroupDigits(cautionAmount))) + end + end) + end + elseif cautionType == 'give_back' then + if cautionAmount <= 1 and cautionAmount > 0 then + TriggerEvent('esx_addonaccount:getAccount', 'caution', xPlayer.identifier, function(account) + local caution = account.money + local toGive = ESX.Math.Round(caution * cautionAmount) + + xPlayer.addAccountMoney('bank', toGive) + account.removeMoney(toGive) + TriggerClientEvent('esx:showNotification', source, _U('bank_deposit_returned', ESX.Math.GroupDigits(toGive))) + end) end - - TriggerEvent('esx_addonaccount:getAccount', 'caution', xPlayer.identifier, function(account) - local caution = account.money - local toGive = ESX.Math.Round(caution * cautionAmount) - - xPlayer.addAccountMoney('bank', toGive) - account.removeMoney(toGive) - xPlayer.showNotification(_U('bank_deposit_returned', ESX.Math.GroupDigits(toGive))) - end) end end)