Skip to content

Commit

Permalink
Use canSwapItem() test
Browse files Browse the repository at this point in the history
  • Loading branch information
ElPumpo committed Jan 15, 2020
1 parent a35a3b8 commit 5d924d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
34 changes: 18 additions & 16 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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')
Expand Down

0 comments on commit 5d924d4

Please sign in to comment.