Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ESX = nil
- local playersProcessingCannabis = {}
- local playersProcessingCocaPlant = {}
- 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
- TriggerClientEvent('esx:showNotification', source, _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)
- TriggerClientEvent('esx:showNotification', source, _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 == nil then
- print(('esx_drugs: %s attempted to buy an invalid license!'):format(xPlayer.identifier))
- cb(false)
- end
- if xPlayer.getMoney() >= license.price then
- xPlayer.removeMoney(license.price)
- TriggerEvent('esx_license:addLicense', source, licenseName, function()
- cb(true)
- end)
- else
- cb(false)
- end
- end)
- RegisterServerEvent('esx_drugs:pickedUpCannabis')
- AddEventHandler('esx_drugs:pickedUpCannabis', function()
- local xPlayer = ESX.GetPlayerFromId(source)
- local xItem = xPlayer.getInventoryItem('cannabis')
- if xItem.limit ~= -1 and (xItem.count + 1) > xItem.limit then
- TriggerClientEvent('esx:showNotification', _source, _U('weed_inventoryfull'))
- else
- xPlayer.addInventoryItem(xItem.name, 1)
- end
- end)
- RegisterServerEvent('esx_drugs:pickedUpCocaPlant')
- AddEventHandler('esx_drugs:pickedUpCocaPlant', function()
- local xPlayer = ESX.GetPlayerFromId(source)
- local xItem = xPlayer.getInventoryItem('cocaplant')
- if xItem.limit ~= -1 and (xItem.count + 1) > xItem.limit then
- TriggerClientEvent('esx:showNotification', _source, _U('coke_inventoryfull'))
- else
- xPlayer.addInventoryItem(xItem.name, 1)
- end
- end)
- RegisterServerEvent('esx_drugs:pickedUpMeth')
- AddEventHandler('esx_drugs:pickedUpMeth', function()
- local xPlayer = ESX.GetPlayerFromId(source)
- local xItem = xPlayer.getInventoryItem('ephedra')
- if xItem.limit ~= -1 and (xItem.count + 1) > xItem.limit then
- TriggerClientEvent('esx:showNotification', _source, _U('meth_inventoryfull'))
- else
- xPlayer.addInventoryItem(xItem.name, 1)
- end
- end)
- ESX.RegisterServerCallback('esx_drugs:canPickUp', function(source, cb, item)
- local xPlayer = ESX.GetPlayerFromId(source)
- local xItem = xPlayer.getInventoryItem(item)
- if xItem.limit ~= -1 and xItem.count >= xItem.limit then
- cb(false)
- else
- cb(true)
- end
- 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, xMarijuana = xPlayer.getInventoryItem('cannabis'), xPlayer.getInventoryItem('marijuana')
- if xMarijuana.limit ~= -1 and (xMarijuana.count + 1) >= xMarijuana.limit then
- TriggerClientEvent('esx:showNotification', _source, _U('weed_processingfull'))
- elseif xCannabis.count < 3 then
- TriggerClientEvent('esx:showNotification', _source, _U('weed_processingenough'))
- else
- xPlayer.removeInventoryItem('cannabis', 3)
- xPlayer.addInventoryItem('marijuana', 1)
- TriggerClientEvent('esx:showNotification', _source, _U('weed_processed'))
- end
- playersProcessingCannabis[_source] = nil
- end)
- else
- print(('esx_drugs: %s attempted to exploit weed processing!'):format(GetPlayerIdentifiers(source)[1]))
- end
- end)
- RegisterServerEvent('esx_drugs:processCocaPlant')
- AddEventHandler('esx_drugs:processCocaPlant', function()
- if not playersProcessingCocaPlant[source] then
- local _source = source
- playersProcessingCocaPlant[_source] = ESX.SetTimeout(Config.Delays.CokeProcessing, function()
- local xPlayer = ESX.GetPlayerFromId(_source)
- local xCocaPlant, xCocaine = xPlayer.getInventoryItem('cocaplant'), xPlayer.getInventoryItem('cocaine')
- if xCocaine.limit ~= -1 and (xCocaine.count + 1) >= xCocaine.limit then
- TriggerClientEvent('esx:showNotification', _source, _U('coke_processingfull'))
- elseif xCocaPlant.count < 3 then
- TriggerClientEvent('esx:showNotification', _source, _U('coke_processingenough'))
- else
- xPlayer.removeInventoryItem('cocaplant', 3)
- xPlayer.addInventoryItem('cocaine', 1)
- TriggerClientEvent('esx:showNotification', _source, _U('coke_processed'))
- end
- playersProcessingCocaPlant[_source] = nil
- end)
- else
- print(('esx_drugs: %s attempted to exploit coke processing!'):format(GetPlayerIdentifiers(source)[1]))
- end
- end)
- RegisterServerEvent('esx_drugs:processMeth')
- AddEventHandler('esx_drugs:processMeth', function()
- if not playersProcessingCocaPlant[source] then
- local _source = source
- playersProcessingMeth[_source] = ESX.SetTimeout(Config.Delays.MethProcessing, function()
- local xPlayer = ESX.GetPlayerFromId(_source)
- local xMeth, xMethCrystal = xPlayer.getInventoryItem('ephedra'), xPlayer.getInventoryItem('crystal_meth')
- if xMethCrystal.limit ~= -1 and (xMethCrystal.count + 1) >= xMethCrystal.limit then
- TriggerClientEvent('esx:showNotification', _source, _U('meth_processingfull'))
- elseif xMeth.count < 3 then
- TriggerClientEvent('esx:showNotification', _source, _U('meth_processingenough'))
- else
- xPlayer.removeInventoryItem('ephedra', 3)
- xPlayer.addInventoryItem('crystal_meth', 1)
- TriggerClientEvent('esx:showNotification', _source, _U('meth_processed'))
- end
- playersProcessingMeth[_source] = nil
- end)
- else
- print(('esx_drugs: %s attempted to exploit coke processing!'):format(GetPlayerIdentifiers(source)[1]))
- end
- end)
- function CancelProcessing(playerID)
- if playersProcessingCannabis[playerID] then
- ESX.ClearTimeout(playersProcessingCannabis[playerID])
- playersProcessingCannabis[playerID] = nil
- end
- end
- function CancelProcessing(playerID)
- if playersProcessingCocaPlant[playerID] then
- ESX.ClearTimeout(playersProcessingCocaPlant[playerID])
- playersProcessingCocaPlant[playerID] = nil
- end
- end
- function CancelProcessing(playerID)
- if playersProcessingMeth[playerID] then
- ESX.ClearTimeout(playersProcessingMeth[playerID])
- playersProcessingMeth[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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement