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
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 40 ~= -1 and (xItem.count + 1) > 40 then
TriggerClientEvent('esx:showNotification', _source, _U('weed_inventoryfull'))
TriggerEvent('disc-inventoryhud:yenile')
else
if xPlayer.canCarryItem(xItem.name, 1) then
xPlayer.addInventoryItem(xItem.name, 1)
else
TriggerClientEvent('mythic_notify:client:SendAlert', xPlayer.source, {type = 'error', text = 'Daha fazla taşıyamazsın!' })
end
end
end)
ESX.RegisterServerCallback('esx_drugs:canPickUp', function(source, cb, item)
local xPlayer = ESX.GetPlayerFromId(source)
local xItem = xPlayer.getInventoryItem(item)
if 40 ~= -1 and xItem.count >= 40 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 xCannabis.count < 2 then
TriggerClientEvent('esx:showNotification', _source, _U('weed_processingenough'))
else
if xPlayer.canCarryItem('marijuana', 1) then
xPlayer.removeInventoryItem('cannabis', 2)
xPlayer.addInventoryItem('marijuana', 1)
TriggerClientEvent('esx:showNotification', _source, _U('weed_processed'))
else
TriggerClientEvent('mythic_notify:client:SendAlert', xPlayer.source, {type = 'error', text = 'Daha fazla taşıyamazsın!' })
end
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
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)
AddEventHandler('hasan:itemsil3', function(source)
local xPlayer = ESX.GetPlayerFromID(_source)
xPlayer.removeInventoryItem('cannabis', 1)
end)