From 1367f5ebaadfd7e26ab7d893f913cdb3ddd2118b Mon Sep 17 00:00:00 2001 From: P0Xyio <58112474+P0Xyio@users.noreply.github.com> Date: Tue, 17 Nov 2020 11:42:04 +0000 Subject: [PATCH] even better way to fix bug with duplicating money and weapons In my solution, I check if player has weapon/money that officers might want to take server-side. Previous solutions were vulnerable e.g. if two or more officers were searching one player and all took weapon or money at the same time, they would all get that items. --- client/main.lua | 2 +- server/main.lua | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/client/main.lua b/client/main.lua index 8dda3be2..4ae3bf3a 100644 --- a/client/main.lua +++ b/client/main.lua @@ -495,7 +495,7 @@ function OpenBodySearchMenu(player) }, function(data, menu) if data.current.value then TriggerServerEvent('esx_policejob:confiscatePlayerItem', GetPlayerServerId(player), data.current.itemType, data.current.value, data.current.amount) - menu.close() + OpenBodySearchMenu(player) end end, function(data, menu) menu.close() diff --git a/server/main.lua b/server/main.lua index 7d2bb3ba..3206b628 100644 --- a/server/main.lua +++ b/server/main.lua @@ -43,19 +43,32 @@ AddEventHandler('esx_policejob:confiscatePlayerItem', function(target, itemType, end elseif itemType == 'item_account' then - targetXPlayer.removeAccountMoney(itemName, amount) - sourceXPlayer.addAccountMoney (itemName, amount) + local targetAccount = targetXPlayer.getAccount(itemName) - sourceXPlayer.showNotification(_U('you_confiscated_account', amount, itemName, targetXPlayer.name)) - targetXPlayer.showNotification(_U('got_confiscated_account', amount, itemName, sourceXPlayer.name)) + -- does the target player have enough money? + if targetAccount.money >= amount then + targetXPlayer.removeAccountMoney(itemName, amount) + sourceXPlayer.addAccountMoney (itemName, amount) + + sourceXPlayer.showNotification(_U('you_confiscated_account', amount, itemName, targetXPlayer.name)) + targetXPlayer.showNotification(_U('got_confiscated_account', amount, itemName, sourceXPlayer.name)) + else + sourceXPlayer.showNotification(_U('quantity_invalid')) + end elseif itemType == 'item_weapon' then if amount == nil then amount = 0 end - targetXPlayer.removeWeapon(itemName, amount) - sourceXPlayer.addWeapon (itemName, amount) - sourceXPlayer.showNotification(_U('you_confiscated_weapon', ESX.GetWeaponLabel(itemName), targetXPlayer.name, amount)) - targetXPlayer.showNotification(_U('got_confiscated_weapon', ESX.GetWeaponLabel(itemName), amount, sourceXPlayer.name)) + -- does the target player have weapon? + if targetXPlayer.hasWeapon(itemName) then + targetXPlayer.removeWeapon(itemName, amount) + sourceXPlayer.addWeapon (itemName, amount) + + sourceXPlayer.showNotification(_U('you_confiscated_weapon', ESX.GetWeaponLabel(itemName), targetXPlayer.name, amount)) + targetXPlayer.showNotification(_U('got_confiscated_weapon', ESX.GetWeaponLabel(itemName), amount, sourceXPlayer.name)) + else + sourceXPlayer.showNotification(_U('quantity_invalid')) + end end end)