Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. RegisterServerEvent('esx_policejob:confiscatePlayerItem')
  2. AddEventHandler('esx_policejob:confiscatePlayerItem', function(target, itemType, itemName, amount)
  3. local _source = source
  4. local sourceXPlayer = ESX.GetPlayerFromId(_source)
  5. local targetXPlayer = ESX.GetPlayerFromId(target)
  6.  
  7. if itemType == 'item_standard' then
  8. local targetItem = targetXPlayer.getInventoryItem(itemName)
  9. local sourceItem = sourceXPlayer.getInventoryItem(itemName)
  10.  
  11. -- does the target player have enough in their inventory?
  12. if targetItem.count > 0 and targetItem.count <= amount then
  13.  
  14. -- can the player carry the said amount of x item?
  15. if sourceItem.limit ~= -1 and (sourceItem.count + amount) > sourceItem.limit then
  16. TriggerClientEvent('esx:showNotification', _source, _U('quantity_invalid'))
  17. else
  18. targetXPlayer.removeInventoryItem(itemName, amount)
  19. sourceXPlayer.addInventoryItem (itemName, amount)
  20. TriggerClientEvent('esx:showNotification', _source, _U('you_confiscated', amount, sourceItem.label, targetXPlayer.name))
  21. TriggerClientEvent('esx:showNotification', target, _U('got_confiscated', amount, sourceItem.label, sourceXPlayer.name))
  22. end
  23. else
  24. TriggerClientEvent('esx:showNotification', _source, _U('quantity_invalid'))
  25. end
  26.  
  27. elseif itemType == 'item_account' then
  28. targetXPlayer.removeAccountMoney(itemName, amount)
  29. sourceXPlayer.addAccountMoney (itemName, amount)
  30.  
  31. TriggerClientEvent('esx:showNotification', _source, _U('you_confiscated_account', amount, itemName, targetXPlayer.name))
  32. TriggerClientEvent('esx:showNotification', target, _U('got_confiscated_account', amount, itemName, sourceXPlayer.name))
  33.  
  34. elseif itemType == 'item_weapon' then
  35. if amount == nil then amount = 0 end
  36. targetXPlayer.removeWeapon(itemName, amount)
  37. sourceXPlayer.addWeapon (itemName, amount)
  38.  
  39. TriggerClientEvent('esx:showNotification', _source, _U('you_confiscated_weapon', ESX.GetWeaponLabel(itemName), targetXPlayer.name, amount))
  40. TriggerClientEvent('esx:showNotification', target, _U('got_confiscated_weapon', ESX.GetWeaponLabel(itemName), amount, sourceXPlayer.name))
  41. end
  42. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement