Use canSwapItem() test

This commit is contained in:
ElPumpo
2020-01-15 21:48:13 +01:00
parent a35a3b8b84
commit 5d924d4b8a
2 changed files with 19 additions and 17 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ start esx_drugs
### License
esx_drugs - drugs job
Copyright (C) 2015-2018 Jérémie N'gadi
Copyright (C) 2015-2020 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.
+18 -16
View File
@@ -76,28 +76,30 @@ AddEventHandler('esx_drugs:processCannabis', function()
local xPlayer = ESX.GetPlayerFromId(_source)
local xCannabis = xPlayer.getInventoryItem('cannabis')
if not xPlayer.canCarryItem('marijuana', 1) then
xPlayer.showNotification(_U('weed_processingfull'))
elseif xCannabis.count < 3 then
xPlayer.showNotification(_U('weed_processingenough'))
if xCannabis.count > 3 then
if xPlayer.canSwapItem('cannabis', 3, 'marijuana', 1) then
xPlayer.removeInventoryItem('cannabis', 3)
xPlayer.addInventoryItem('marijuana', 1)
xPlayer.showNotification(_U('weed_processed'))
else
xPlayer.showNotification(_U('weed_processingfull'))
playersProcessingCannabis[_source] = nil
end
else
xPlayer.removeInventoryItem('cannabis', 3)
xPlayer.addInventoryItem('marijuana', 1)
xPlayer.showNotification(_U('weed_processed'))
xPlayer.showNotification(_U('weed_processingenough'))
playersProcessingCannabis[_source] = nil
end
playersProcessingCannabis[_source] = nil
end)
else
print(('esx_drugs: %s attempted to exploit weed processing!'):format(GetPlayerIdentifiers(source)[1]))
end
end)
function CancelProcessing(playerID)
if playersProcessingCannabis[playerID] then
ESX.ClearTimeout(playersProcessingCannabis[playerID])
playersProcessingCannabis[playerID] = nil
function CancelProcessing(playerId)
if playersProcessingCannabis[playerId] then
ESX.ClearTimeout(playersProcessingCannabis[playerId])
playersProcessingCannabis[playerId] = nil
end
end
@@ -106,8 +108,8 @@ AddEventHandler('esx_drugs:cancelProcessing', function()
CancelProcessing(source)
end)
AddEventHandler('esx:playerDropped', function(playerID, reason)
CancelProcessing(playerID)
AddEventHandler('esx:playerDropped', function(playerId, reason)
CancelProcessing(playerId)
end)
RegisterServerEvent('esx:onPlayerDeath')