mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-02 19:28:52 +00:00
561 lines
17 KiB
Lua
561 lines
17 KiB
Lua
ESX = nil
|
|
local CopsConnected = 0
|
|
local PlayersHarvestingCoke = {}
|
|
local PlayersTransformingCoke = {}
|
|
local PlayersSellingCoke = {}
|
|
local PlayersHarvestingMeth = {}
|
|
local PlayersTransformingMeth = {}
|
|
local PlayersSellingMeth = {}
|
|
local PlayersHarvestingWeed = {}
|
|
local PlayersTransformingWeed = {}
|
|
local PlayersSellingWeed = {}
|
|
|
|
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
|
|
|
function CountCops()
|
|
|
|
local xPlayers = ESX.GetPlayers()
|
|
|
|
CopsConnected = 0
|
|
|
|
for k,v in pairs(xPlayers) do
|
|
if v.job.name == 'police' then
|
|
CopsConnected = CopsConnected + 1
|
|
end
|
|
end
|
|
|
|
SetTimeout(5000, CountCops)
|
|
|
|
end
|
|
|
|
CountCops()
|
|
|
|
local function HarvestCoke(source)
|
|
|
|
if CopsConnected < Config.RequiredCopsCoke then
|
|
TriggerClientEvent('esx:showNotification', source, 'Action ~r~impossible~s~, ~b~policiers~s~: ' .. CopsConnected .. '/' .. Config.RequiredCopsCoke)
|
|
return
|
|
end
|
|
|
|
SetTimeout(5000, function()
|
|
|
|
if PlayersHarvestingCoke[source] == true then
|
|
|
|
local xPlayer = ESX.GetPlayerFromId(source)
|
|
|
|
local coke = xPlayer.getInventoryItem('coke')
|
|
|
|
if coke.limit ~= -1 and coke.count >= coke.limit then
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous ne pouvez plus ramasser de Cocaine, votre inventaire est ~r~plein~s~')
|
|
else
|
|
xPlayer.addInventoryItem('coke', 1)
|
|
HarvestCoke(source)
|
|
end
|
|
|
|
end
|
|
end)
|
|
end
|
|
|
|
RegisterServerEvent('esx_drugs:startHarvestCoke')
|
|
AddEventHandler('esx_drugs:startHarvestCoke', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersHarvestingCoke[_source] = true
|
|
|
|
TriggerClientEvent('esx:showNotification', _source, '~y~Ramassage en cours~s~...')
|
|
|
|
HarvestCoke(source)
|
|
|
|
end)
|
|
|
|
RegisterServerEvent('esx_drugs:stopHarvestCoke')
|
|
AddEventHandler('esx_drugs:stopHarvestCoke', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersHarvestingCoke[_source] = false
|
|
|
|
end)
|
|
|
|
local function TransformCoke(source)
|
|
|
|
if CopsConnected < Config.RequiredCopsCoke then
|
|
TriggerClientEvent('esx:showNotification', source, 'Action ~r~impossible~s~, ~b~policiers~s~: ' .. CopsConnected .. '/' .. Config.RequiredCopsCoke)
|
|
return
|
|
end
|
|
|
|
SetTimeout(10000, function()
|
|
|
|
if PlayersTransformingCoke[source] == true then
|
|
|
|
local xPlayer = ESX.GetPlayerFromId(source)
|
|
|
|
local cokeQuantity = xPlayer.getInventoryItem('coke').count
|
|
local poochQuantity = xPlayer.getInventoryItem('coke_pooch').count
|
|
|
|
if poochQuantity > 35 then
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez trop de pochons')
|
|
elseif cokeQuantity < 5 then
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous n\'avez pas assez de feuille de coca à ~r~conditionner~s~')
|
|
else
|
|
xPlayer.removeInventoryItem('coke', 5)
|
|
xPlayer.addInventoryItem('coke_pooch', 1)
|
|
|
|
TransformCoke(source)
|
|
end
|
|
|
|
end
|
|
end)
|
|
end
|
|
|
|
RegisterServerEvent('esx_drugs:startTransformCoke')
|
|
AddEventHandler('esx_drugs:startTransformCoke', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersTransformingCoke[_source] = true
|
|
|
|
TriggerClientEvent('esx:showNotification', _source, '~y~Conditonnement en cours~s~...')
|
|
|
|
TransformCoke(source)
|
|
|
|
end)
|
|
|
|
RegisterServerEvent('esx_drugs:stopTransformCoke')
|
|
AddEventHandler('esx_drugs:stopTransformCoke', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersTransformingCoke[_source] = false
|
|
|
|
end)
|
|
|
|
local function SellCoke(source)
|
|
|
|
if CopsConnected < Config.RequiredCopsCoke then
|
|
TriggerClientEvent('esx:showNotification', source, 'Action ~r~impossible~s~, ~b~policiers~s~: ' .. CopsConnected .. '/' .. Config.RequiredCopsCoke)
|
|
return
|
|
end
|
|
|
|
SetTimeout(7500, function()
|
|
|
|
if PlayersSellingCoke[source] == true then
|
|
|
|
local xPlayer = ESX.GetPlayerFromId(source)
|
|
|
|
local poochQuantity = xPlayer.getInventoryItem('coke_pooch').count
|
|
|
|
if poochQuantity == 0 then
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous n\'avez plus de pochons à ~r~vendre~s~')
|
|
else
|
|
xPlayer.removeInventoryItem('coke_pooch', 1)
|
|
if CopsConnected == 0 then
|
|
xPlayer.addAccountMoney('black_money', 198)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de coke~s~')
|
|
elseif CopsConnected == 1 then
|
|
xPlayer.addAccountMoney('black_money', 258)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de coke~s~')
|
|
elseif CopsConnected == 2 then
|
|
xPlayer.addAccountMoney('black_money', 308)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de coke~s~')
|
|
elseif CopsConnected == 3 then
|
|
xPlayer.addAccountMoney('black_money', 358)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de coke~s~')
|
|
elseif CopsConnected == 4 then
|
|
xPlayer.addAccountMoney('black_money', 396)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de coke~s~')
|
|
elseif CopsConnected >= 5 then
|
|
xPlayer.addAccountMoney('black_money', 428)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de coke~s~')
|
|
end
|
|
|
|
SellCoke(source)
|
|
end
|
|
|
|
end
|
|
end)
|
|
end
|
|
|
|
RegisterServerEvent('esx_drugs:startSellCoke')
|
|
AddEventHandler('esx_drugs:startSellCoke', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersSellingCoke[_source] = true
|
|
|
|
TriggerClientEvent('esx:showNotification', _source, '~g~Vente en cours~s~...')
|
|
|
|
SellCoke(source)
|
|
|
|
end)
|
|
|
|
RegisterServerEvent('esx_drugs:stopSellCoke')
|
|
AddEventHandler('esx_drugs:stopSellCoke', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersSellingCoke[_source] = false
|
|
|
|
end)
|
|
|
|
local function HarvestMeth(source)
|
|
|
|
if CopsConnected < Config.RequiredCopsMeth then
|
|
TriggerClientEvent('esx:showNotification', source, 'Action ~r~impossible~s~, ~b~policiers~s~: ' .. CopsConnected .. '/' .. Config.RequiredCopsMeth)
|
|
return
|
|
end
|
|
|
|
SetTimeout(5000, function()
|
|
|
|
if PlayersHarvestingMeth[source] == true then
|
|
|
|
local xPlayer = ESX.GetPlayerFromId(source)
|
|
|
|
local meth = xPlayer.getInventoryItem('meth')
|
|
|
|
if meth.limit ~= -1 and meth.count >= meth.limit then
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous ne pouvez plus ramasser de Meth, votre inventaire est ~r~plein~s~')
|
|
else
|
|
xPlayer.addInventoryItem('meth', 1)
|
|
HarvestMeth(source)
|
|
end
|
|
|
|
end
|
|
end)
|
|
end
|
|
|
|
RegisterServerEvent('esx_drugs:startHarvestMeth')
|
|
AddEventHandler('esx_drugs:startHarvestMeth', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersHarvestingMeth[_source] = true
|
|
|
|
TriggerClientEvent('esx:showNotification', _source, '~y~Ramassage en cours~s~...')
|
|
|
|
HarvestMeth(source)
|
|
|
|
end)
|
|
|
|
RegisterServerEvent('esx_drugs:stopHarvestMeth')
|
|
AddEventHandler('esx_drugs:stopHarvestMeth', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersHarvestingMeth[_source] = false
|
|
|
|
end)
|
|
|
|
local function TransformMeth(source)
|
|
|
|
if CopsConnected < Config.RequiredCopsMeth then
|
|
TriggerClientEvent('esx:showNotification', source, 'Action ~r~impossible~s~, ~b~policiers~s~: ' .. CopsConnected .. '/' .. Config.RequiredCopsMeth)
|
|
return
|
|
end
|
|
|
|
SetTimeout(12000, function()
|
|
|
|
if PlayersTransformingMeth[source] == true then
|
|
|
|
local xPlayer = ESX.GetPlayerFromId(source)
|
|
|
|
local methQuantity = xPlayer.getInventoryItem('meth').count
|
|
local pochonQuantity = xPlayer.getInventoryItem('meth_pooch').count
|
|
|
|
if pochonQuantity > 35 then
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez trop de pochons')
|
|
elseif methQuantity < 5 then
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous n\'avez pas assez de Meth à ~r~conditionner~s~')
|
|
else
|
|
xPlayer.removeInventoryItem('meth', 5)
|
|
xPlayer.addInventoryItem('meth_pochon', 1)
|
|
|
|
TransformMeth(source)
|
|
end
|
|
|
|
end
|
|
end)
|
|
end
|
|
|
|
RegisterServerEvent('esx_drugs:startTransformMeth')
|
|
AddEventHandler('esx_drugs:startTransformMeth', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersTransformingMeth[_source] = true
|
|
|
|
TriggerClientEvent('esx:showNotification', _source, '~y~Conditonnement en cours~s~...')
|
|
|
|
TransformMeth(source)
|
|
|
|
end)
|
|
|
|
RegisterServerEvent('esx_drugs:stopTransformMeth')
|
|
AddEventHandler('esx_drugs:stopTransformMeth', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersTransformingMeth[_source] = false
|
|
|
|
end)
|
|
|
|
local function SellMeth(source)
|
|
|
|
if CopsConnected < Config.RequiredCopsMeth then
|
|
TriggerClientEvent('esx:showNotification', source, 'Action ~r~impossible~s~, ~b~policiers~s~: ' .. CopsConnected .. '/' .. Config.RequiredCopsMeth)
|
|
return
|
|
end
|
|
|
|
SetTimeout(7500, function()
|
|
|
|
if PlayersSellingMeth[source] == true then
|
|
|
|
local xPlayer = ESX.GetPlayerFromId(source)
|
|
|
|
local pochonQuantity = xPlayer.getInventoryItem('meth_pooch').count
|
|
|
|
if pochonQuantity == 0 then
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous n\'avez plus de pochons à ~r~vendre~s~')
|
|
else
|
|
xPlayer.removeInventoryItem('meth_pochon', 1)
|
|
if CopsConnected == 0 then
|
|
xPlayer.addAccountMoney('black_money', 276)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de meth~s~')
|
|
elseif CopsConnected == 1 then
|
|
xPlayer.addAccountMoney('black_money', 374)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de meth~s~')
|
|
elseif CopsConnected == 2 then
|
|
xPlayer.addAccountMoney('black_money', 474)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de meth~s~')
|
|
elseif CopsConnected == 3 then
|
|
xPlayer.addAccountMoney('black_money', 552)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de meth~s~')
|
|
elseif CopsConnected == 4 then
|
|
xPlayer.addAccountMoney('black_money', 616)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de meth~s~')
|
|
elseif CopsConnected == 5 then
|
|
xPlayer.addAccountMoney('black_money', 654)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de meth~s~')
|
|
elseif CopsConnected >= 6 then
|
|
xPlayer.addAccountMoney('black_money', 686)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de meth~s~')
|
|
end
|
|
|
|
SellMeth(source)
|
|
end
|
|
|
|
end
|
|
end)
|
|
end
|
|
|
|
RegisterServerEvent('esx_drugs:startSellMeth')
|
|
AddEventHandler('esx_drugs:startSellMeth', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersSellingMeth[_source] = true
|
|
|
|
TriggerClientEvent('esx:showNotification', _source, '~g~Vente en cours~s~...')
|
|
|
|
SellMeth(source)
|
|
|
|
end)
|
|
|
|
RegisterServerEvent('esx_drugs:stopSellMeth')
|
|
AddEventHandler('esx_drugs:stopSellMeth', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersSellingMeth[_source] = false
|
|
|
|
end)
|
|
|
|
local function HarvestWeed(source)
|
|
|
|
if CopsConnected < Config.RequiredCopsWeed then
|
|
TriggerClientEvent('esx:showNotification', source, 'Action ~r~impossible~s~, ~b~policiers~s~: ' .. CopsConnected .. '/' .. Config.RequiredCopsWeed)
|
|
return
|
|
end
|
|
|
|
SetTimeout(5000, function()
|
|
|
|
if PlayersHarvestingWeed[source] == true then
|
|
|
|
local xPlayer = ESX.GetPlayerFromId(source)
|
|
|
|
local weed = xPlayer.getInventoryItem('weed')
|
|
|
|
if weed.limit ~= -1 and weed.count >= weed.limit then
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous ne pouvez plus ramasser de weed, votre inventaire est ~r~plein~s~')
|
|
else
|
|
xPlayer.addInventoryItem('weed', 1)
|
|
HarvestWeed(source)
|
|
end
|
|
|
|
end
|
|
end)
|
|
end
|
|
|
|
RegisterServerEvent('esx_drugs:startHarvestWeed')
|
|
AddEventHandler('esx_drugs:startHarvestWeed', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersHarvestingWeed[_source] = true
|
|
|
|
TriggerClientEvent('esx:showNotification', _source, '~y~Ramassage en cours~s~...')
|
|
|
|
HarvestWeed(source)
|
|
|
|
end)
|
|
|
|
RegisterServerEvent('esx_drugs:stopHarvestWeed')
|
|
AddEventHandler('esx_drugs:stopHarvestWeed', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersHarvestingWeed[_source] = false
|
|
|
|
end)
|
|
|
|
local function TransformWeed(source)
|
|
|
|
if CopsConnected < Config.RequiredCopsWeed then
|
|
TriggerClientEvent('esx:showNotification', source, 'Action ~r~impossible~s~, ~b~policiers~s~: ' .. CopsConnected .. '/' .. Config.RequiredCopsWeed)
|
|
return
|
|
end
|
|
|
|
SetTimeout(7500, function()
|
|
|
|
if PlayersTransformingWeed[source] == true then
|
|
|
|
local xPlayer = ESX.GetPlayerFromId(source)
|
|
|
|
local weedQuantity = xPlayer.getInventoryItem('weed').count
|
|
local poochQuantity = xPlayer.getInventoryItem('weed_pooch').count
|
|
|
|
if poochQuantity > 35 then
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez trop de pochons')
|
|
elseif weedQuantity < 5 then
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous n\'avez pas assez de weed à ~r~conditionner~s~')
|
|
else
|
|
xPlayer.removeInventoryItem('weed', 5)
|
|
xPlayer.addInventoryItem('weed_pooch', 1)
|
|
|
|
TransformWeed(source)
|
|
end
|
|
|
|
end
|
|
end)
|
|
end
|
|
|
|
RegisterServerEvent('esx_drugs:startTransformWeed')
|
|
AddEventHandler('esx_drugs:startTransformWeed', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersTransformingWeed[_source] = true
|
|
|
|
TriggerClientEvent('esx:showNotification', _source, '~y~Conditonnement en cours~s~...')
|
|
|
|
TransformWeed(source)
|
|
|
|
end)
|
|
|
|
RegisterServerEvent('esx_drugs:stopTransformWeed')
|
|
AddEventHandler('esx_drugs:stopTransformWeed', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersTransformingWeed[_source] = false
|
|
|
|
end)
|
|
|
|
local function SellWeed(source)
|
|
|
|
if CopsConnected < Config.RequiredCopsWeed then
|
|
TriggerClientEvent('esx_weedjob:showNotification', source, 'Action ~r~impossible~s~, ~b~policiers~s~: ' .. CopsConnected .. '/' .. Config.RequiredCopsWeed)
|
|
return
|
|
end
|
|
|
|
SetTimeout(7500, function()
|
|
|
|
if PlayersSellingWeed[source] == true then
|
|
|
|
local xPlayer = ESX.GetPlayerFromId(source)
|
|
|
|
local poochQuantity = xPlayer.getInventoryItem('weed_pooch').count
|
|
|
|
if poochQuantity == 0 then
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous n\'avez plus de pochons à ~r~vendre~s~')
|
|
else
|
|
xPlayer:removeInventoryItem('weed_pooch', 1)
|
|
if CopsConnected == 0 then
|
|
xPlayer.addAccountMoney('black_money', 108)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de weed~s~')
|
|
elseif CopsConnected == 1 then
|
|
xPlayer.addAccountMoney('black_money', 128)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de weed~s~')
|
|
elseif CopsConnected == 2 then
|
|
xPlayer.addAccountMoney('black_money', 152)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de weed~s~')
|
|
elseif CopsConnected == 3 then
|
|
xPlayer.addAccountMoney('black_money', 165)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de weed~s~')
|
|
elseif CopsConnected >= 4 then
|
|
xPlayer.addAccountMoney('black_money', 180)
|
|
TriggerClientEvent('esx:showNotification', source, 'Vous avez vendu ~g~x1 Pochon de weed~s~')
|
|
end
|
|
|
|
SellWeed(source)
|
|
end
|
|
|
|
end
|
|
end)
|
|
end
|
|
|
|
RegisterServerEvent('esx_drugs:startSellWeed')
|
|
AddEventHandler('esx_drugs:startSellWeed', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersSellingWeed[_source] = true
|
|
|
|
TriggerClientEvent('esx:showNotification', _source, '~g~Vente en cours~s~...')
|
|
|
|
SellWeed(source)
|
|
|
|
end)
|
|
|
|
RegisterServerEvent('esx_drugs:stopSellWeed')
|
|
AddEventHandler('esx_drugs:stopSellWeed', function()
|
|
|
|
local _source = source
|
|
|
|
PlayersSellingWeed[_source] = false
|
|
|
|
end)
|
|
|
|
-- RETURN INVENTORY TO CLIENT
|
|
RegisterServerEvent('esx_drugs:GetUserInventory')
|
|
AddEventHandler('esx_drugs:GetUserInventory', function(currentZone)
|
|
local _source = source
|
|
local xPlayer = ESX.GetPlayerFromId(_source)
|
|
TriggerClientEvent('esx_drugs:ReturnInventory', _source, xPlayer.getInventoryItem('coke').count, xPlayer.getInventoryItem('coke_pooch').count,
|
|
xPlayer.getInventoryItem('meth').count, xPlayer.getInventoryItem('meth_pooch').count,
|
|
xPlayer.getInventoryItem('weed').count, xPlayer.getInventoryItem('weed_pooch').count, xPlayer.job.name, currentZone)
|
|
end)
|
|
|
|
-- Register Usable Item
|
|
ESX.RegisterUsableItem('weed', function(source)
|
|
|
|
local _source = source
|
|
local xPlayer = ESX.GetPlayerFromId(source)
|
|
|
|
xPlayer.removeInventoryItem('weed', 1)
|
|
|
|
TriggerClientEvent('esx_drugs:onPot', _source)
|
|
TriggerClientEvent('esx:showNotification', _source, 'Vous avez utilisé 1 de ~b~Weed')
|
|
|
|
end) |