ESX = nil local playersProcessingCannabis = {} TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) RegisterServerEvent('esx_drugs:sellDrug') AddEventHandler('esx_drugs:sellDrug', function(itemName, amount) local xPlayer = ESX.GetPlayerFromId(source) local price = Config.DrugDealerItems[itemName] local xItem = xPlayer.getInventoryItem(itemName) if not price then print(('esx_drugs: %s attempted to sell an invalid drug!'):format(xPlayer.identifier)) return end if xItem.count < amount then xPlayer.showNotification(_U('dealer_notenough')) return end price = ESX.Math.Round(price * amount) if Config.GiveBlack then xPlayer.addAccountMoney('black_money', price) else xPlayer.addMoney(price) end xPlayer.removeInventoryItem(xItem.name, amount) xPlayer.showNotification(_U('dealer_sold', amount, xItem.label, ESX.Math.GroupDigits(price))) end) ESX.RegisterServerCallback('esx_drugs:buyLicense', function(source, cb, licenseName) local xPlayer = ESX.GetPlayerFromId(source) local license = Config.LicensePrices[licenseName] if license then if xPlayer.getMoney() >= license.price then xPlayer.removeMoney(license.price) TriggerEvent('esx_license:addLicense', source, licenseName, function() cb(true) end) else cb(false) end else print(('esx_drugs: %s attempted to buy an invalid license!'):format(xPlayer.identifier)) cb(false) end end) RegisterServerEvent('esx_drugs:pickedUpCannabis') AddEventHandler('esx_drugs:pickedUpCannabis', function() local xPlayer = ESX.GetPlayerFromId(source) if xPlayer.canCarryItem('cannabis', 1) then xPlayer.addInventoryItem('cannabis', 1) else xPlayer.showNotification(_U('weed_inventoryfull')) end end) ESX.RegisterServerCallback('esx_drugs:canPickUp', function(source, cb, item) local xPlayer = ESX.GetPlayerFromId(source) cb(xPlayer.canCarryItem(item, 1)) end) RegisterServerEvent('esx_drugs:processCannabis') AddEventHandler('esx_drugs:processCannabis', function() if not playersProcessingCannabis[source] then local _source = source playersProcessingCannabis[_source] = ESX.SetTimeout(Config.Delays.WeedProcessing, function() local xPlayer = ESX.GetPlayerFromId(_source) local xCannabis = xPlayer.getInventoryItem('cannabis') 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.showNotification(_U('weed_processingenough')) playersProcessingCannabis[_source] = nil end 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 end end RegisterServerEvent('esx_drugs:cancelProcessing') AddEventHandler('esx_drugs:cancelProcessing', function() CancelProcessing(source) end) AddEventHandler('esx:playerDropped', function(playerId, reason) CancelProcessing(playerId) end) RegisterServerEvent('esx:onPlayerDeath') AddEventHandler('esx:onPlayerDeath', function(data) CancelProcessing(source) end)