Closed ShortWlf closed 3 years ago
bump
Original Source - script: esx_policejob
RegisterNetEvent('esx_policejob:confiscatePlayerItem')
AddEventHandler('esx_policejob:confiscatePlayerItem', function(target, itemType, itemName, amount)
local _source = source
local sourceXPlayer = ESX.GetPlayerFromId(_source)
local targetXPlayer = ESX.GetPlayerFromId(target)
if sourceXPlayer.job.name ~= 'police' then
print(('esx_policejob: %s attempted to confiscate!'):format(xPlayer.identifier))
return
end
if itemType == 'item_standard' then
local targetItem = targetXPlayer.getInventoryItem(itemName)
local sourceItem = sourceXPlayer.getInventoryItem(itemName)
-- does the target player have enough in their inventory?
if targetItem.count > 0 and targetItem.count <= amount then
-- can the player carry the said amount of x item?
if sourceXPlayer.canCarryItem(itemName, sourceItem.count) then
targetXPlayer.removeInventoryItem(itemName, amount)
sourceXPlayer.addInventoryItem (itemName, amount)
sourceXPlayer.showNotification(_U('you_confiscated', amount, sourceItem.label, targetXPlayer.name))
targetXPlayer.showNotification(_U('got_confiscated', amount, sourceItem.label, sourceXPlayer.name))
else
sourceXPlayer.showNotification(_U('quantity_invalid'))
end
else
sourceXPlayer.showNotification(_U('quantity_invalid'))
end
elseif itemType == 'item_account' 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))
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))
end
end)
Replaced with this, overridden invalid quantity
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
-- does the target player have enough in their inventory?
if targetItem.count > 0 and targetItem.count <= amount then
-- can the player carry the said amount of x item?
if sourceXPlayer.getInventoryItem(itemName).count < xPlayer.getInventoryItem(itemName).limit then
targetXPlayer.removeInventoryItem(itemName, amount)
sourceXPlayer.addInventoryItem (itemName, amount)
sourceXPlayer.showNotification(_U('you_confiscated', amount, sourceItem.label, targetXPlayer.name))
targetXPlayer.showNotification(_U('got_confiscated', amount, sourceItem.label, sourceXPlayer.name))
else
targetXPlayer.removeInventoryItem(itemName, amount)
sourceXPlayer.addInventoryItem (itemName, amount)
sourceXPlayer.showNotification(_U('you_confiscated', amount, sourceItem.label, targetXPlayer.name))
targetXPlayer.showNotification(_U('got_confiscated', amount, sourceItem.label, sourceXPlayer.name))
end
else
targetXPlayer.removeInventoryItem(itemName, amount)
sourceXPlayer.addInventoryItem (itemName, amount)
sourceXPlayer.showNotification(_U('you_confiscated', amount, sourceItem.label, targetXPlayer.name))
targetXPlayer.showNotification(_U('got_confiscated', amount, sourceItem.label, sourceXPlayer.name))
end
Need to fix police ability to take items from players