mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 18:28:52 +00:00
105 lines
3.2 KiB
Lua
105 lines
3.2 KiB
Lua
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)
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
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)
|