diff --git a/__resource.lua b/__resource.lua index 70391c21..515cfa30 100644 --- a/__resource.lua +++ b/__resource.lua @@ -13,7 +13,7 @@ server_scripts { 'locales/es.lua', 'locales/sv.lua', 'locales/pl.lua', - 'server/esx_drugs_sv.lua', + 'server/main.lua', 'config.lua' } @@ -27,5 +27,5 @@ client_scripts { 'locales/sv.lua', 'locales/pl.lua', 'config.lua', - 'client/esx_drugs_cl.lua' + 'client/main.lua' } diff --git a/client/esx_drugs_cl.lua b/client/main.lua similarity index 96% rename from client/esx_drugs_cl.lua rename to client/main.lua index 3871997e..38b566c0 100644 --- a/client/esx_drugs_cl.lua +++ b/client/main.lua @@ -1,327 +1,327 @@ -local Keys = { - ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57, - ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177, - ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18, - ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182, - ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81, - ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70, - ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178, - ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173, - ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118 -} - -local cokeQTE = 0 -ESX = nil -local coke_poochQTE = 0 -local weedQTE = 0 -local weed_poochQTE = 0 -local methQTE = 0 -local meth_poochQTE = 0 -local opiumQTE = 0 -local opium_poochQTE = 0 -local myJob = nil -local HasAlreadyEnteredMarker = false -local LastZone = nil -local isInZone = false -local CurrentAction = nil -local CurrentActionMsg = '' -local CurrentActionData = {} - -Citizen.CreateThread(function() - while ESX == nil do - TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) - Citizen.Wait(0) - end -end) - -AddEventHandler('esx_drugs:hasEnteredMarker', function(zone) - if myJob == 'police' or myJob == 'ambulance' then - return - end - - ESX.UI.Menu.CloseAll() - - if zone == 'exitMarker' then - CurrentAction = zone - CurrentActionMsg = _U('exit_marker') - CurrentActionData = {} - end - - if zone == 'CokeField' then - CurrentAction = zone - CurrentActionMsg = _U('press_collect_coke') - CurrentActionData = {} - end - - if zone == 'CokeProcessing' then - if cokeQTE >= 5 then - CurrentAction = zone - CurrentActionMsg = _U('press_process_coke') - CurrentActionData = {} - end - end - - if zone == 'CokeDealer' then - if coke_poochQTE >= 1 then - CurrentAction = zone - CurrentActionMsg = _U('press_sell_coke') - CurrentActionData = {} - end - end - - if zone == 'MethField' then - CurrentAction = zone - CurrentActionMsg = _U('press_collect_meth') - CurrentActionData = {} - end - - if zone == 'MethProcessing' then - if methQTE >= 5 then - CurrentAction = zone - CurrentActionMsg = _U('press_process_meth') - CurrentActionData = {} - end - end - - if zone == 'MethDealer' then - if meth_poochQTE >= 1 then - CurrentAction = zone - CurrentActionMsg = _U('press_sell_meth') - CurrentActionData = {} - end - end - - if zone == 'WeedField' then - CurrentAction = zone - CurrentActionMsg = _U('press_collect_weed') - CurrentActionData = {} - end - - if zone == 'WeedProcessing' then - if weedQTE >= 5 then - CurrentAction = zone - CurrentActionMsg = _U('press_process_weed') - CurrentActionData = {} - end - end - - if zone == 'WeedDealer' then - if weed_poochQTE >= 1 then - CurrentAction = zone - CurrentActionMsg = _U('press_sell_weed') - CurrentActionData = {} - end - end - - if zone == 'OpiumField' then - CurrentAction = zone - CurrentActionMsg = _U('press_collect_opium') - CurrentActionData = {} - end - - if zone == 'OpiumProcessing' then - if opiumQTE >= 5 then - CurrentAction = zone - CurrentActionMsg = _U('press_process_opium') - CurrentActionData = {} - end - end - - if zone == 'OpiumDealer' then - if opium_poochQTE >= 1 then - CurrentAction = zone - CurrentActionMsg = _U('press_sell_opium') - CurrentActionData = {} - end - end -end) - -AddEventHandler('esx_drugs:hasExitedMarker', function(zone) - CurrentAction = nil - ESX.UI.Menu.CloseAll() - - TriggerServerEvent('esx_drugs:stopHarvestCoke') - TriggerServerEvent('esx_drugs:stopTransformCoke') - TriggerServerEvent('esx_drugs:stopSellCoke') - TriggerServerEvent('esx_drugs:stopHarvestMeth') - TriggerServerEvent('esx_drugs:stopTransformMeth') - TriggerServerEvent('esx_drugs:stopSellMeth') - TriggerServerEvent('esx_drugs:stopHarvestWeed') - TriggerServerEvent('esx_drugs:stopTransformWeed') - TriggerServerEvent('esx_drugs:stopSellWeed') - TriggerServerEvent('esx_drugs:stopHarvestOpium') - TriggerServerEvent('esx_drugs:stopTransformOpium') - TriggerServerEvent('esx_drugs:stopSellOpium') -end) - --- Weed Effect -RegisterNetEvent('esx_drugs:onPot') -AddEventHandler('esx_drugs:onPot', function() - RequestAnimSet("MOVE_M@DRUNK@SLIGHTLYDRUNK") - while not HasAnimSetLoaded("MOVE_M@DRUNK@SLIGHTLYDRUNK") do - Citizen.Wait(0) - end - TaskStartScenarioInPlace(GetPlayerPed(-1), "WORLD_HUMAN_SMOKING_POT", 0, true) - Citizen.Wait(5000) - DoScreenFadeOut(1000) - Citizen.Wait(1000) - ClearPedTasksImmediately(GetPlayerPed(-1)) - SetTimecycleModifier("spectator5") - SetPedMotionBlur(GetPlayerPed(-1), true) - SetPedMovementClipset(GetPlayerPed(-1), "MOVE_M@DRUNK@SLIGHTLYDRUNK", true) - SetPedIsDrunk(GetPlayerPed(-1), true) - DoScreenFadeIn(1000) - Citizen.Wait(600000) - DoScreenFadeOut(1000) - Citizen.Wait(1000) - DoScreenFadeIn(1000) - ClearTimecycleModifier() - ResetScenarioTypesEnabled() - ResetPedMovementClipset(GetPlayerPed(-1), 0) - SetPedIsDrunk(GetPlayerPed(-1), false) - SetPedMotionBlur(GetPlayerPed(-1), false) -end) - --- Render markers -Citizen.CreateThread(function() - while true do - - Citizen.Wait(0) - - local coords = GetEntityCoords(GetPlayerPed(-1)) - - for k,v in pairs(Config.Zones) do - if(GetDistanceBetweenCoords(coords, v.x, v.y, v.z, true) < Config.DrawDistance) then - DrawMarker(Config.MarkerType, v.x, v.y, v.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.ZoneSize.x, Config.ZoneSize.y, Config.ZoneSize.z, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, false, false, false) - end - end - - end -end) - -if Config.ShowBlips then - -- Create blips - Citizen.CreateThread(function() - for k,v in pairs(Config.Zones) do - local blip = AddBlipForCoord(v.x, v.y, v.z) - - SetBlipSprite (blip, v.sprite) - SetBlipDisplay(blip, 4) - SetBlipScale (blip, 0.9) - SetBlipColour (blip, v.color) - SetBlipAsShortRange(blip, true) - - BeginTextCommandSetBlipName("STRING") - AddTextComponentString(v.name) - EndTextCommandSetBlipName(blip) - end - end) -end - - --- RETURN NUMBER OF ITEMS FROM SERVER -RegisterNetEvent('esx_drugs:ReturnInventory') -AddEventHandler('esx_drugs:ReturnInventory', function(cokeNbr, cokepNbr, methNbr, methpNbr, weedNbr, weedpNbr, opiumNbr, opiumpNbr, jobName, currentZone) - cokeQTE = cokeNbr - coke_poochQTE = cokepNbr - methQTE = methNbr - meth_poochQTE = methpNbr - weedQTE = weedNbr - weed_poochQTE = weedpNbr - opiumQTE = opiumNbr - opium_poochQTE = opiumpNbr - myJob = jobName - TriggerEvent('esx_drugs:hasEnteredMarker', currentZone) -end) - --- Activate menu when player is inside marker -Citizen.CreateThread(function() - while true do - - Citizen.Wait(0) - - local coords = GetEntityCoords(GetPlayerPed(-1)) - local isInMarker = false - local currentZone = nil - - for k,v in pairs(Config.Zones) do - if(GetDistanceBetweenCoords(coords, v.x, v.y, v.z, true) < Config.ZoneSize.x / 2) then - isInMarker = true - currentZone = k - end - end - - if isInMarker and not hasAlreadyEnteredMarker then - hasAlreadyEnteredMarker = true - lastZone = currentZone - TriggerServerEvent('esx_drugs:GetUserInventory', currentZone) - end - - if not isInMarker and hasAlreadyEnteredMarker then - hasAlreadyEnteredMarker = false - TriggerEvent('esx_drugs:hasExitedMarker', lastZone) - end - - if isInMarker and isInZone then - TriggerEvent('esx_drugs:hasEnteredMarker', 'exitMarker') - end - end -end) - --- Key Controls -Citizen.CreateThread(function() - while true do - Citizen.Wait(10) - if CurrentAction ~= nil then - SetTextComponentFormat('STRING') - AddTextComponentString(CurrentActionMsg) - DisplayHelpTextFromStringLabel(0, 0, 1, -1) - if IsControlJustReleased(0, Keys['E']) then - isInZone = true -- unless we set this boolean to false, we will always freeze the user - if CurrentAction == 'exitMarker' then - isInZone = false -- do not freeze user - TriggerEvent('esx_drugs:freezePlayer', false) - TriggerEvent('esx_drugs:hasExitedMarker', lastZone) - Citizen.Wait(15000) - elseif CurrentAction == 'CokeField' then - TriggerServerEvent('esx_drugs:startHarvestCoke') - elseif CurrentAction == 'CokeProcessing' then - TriggerServerEvent('esx_drugs:startTransformCoke') - elseif CurrentAction == 'CokeDealer' then - TriggerServerEvent('esx_drugs:startSellCoke') - elseif CurrentAction == 'MethField' then - TriggerServerEvent('esx_drugs:startHarvestMeth') - elseif CurrentAction == 'MethProcessing' then - TriggerServerEvent('esx_drugs:startTransformMeth') - elseif CurrentAction == 'MethDealer' then - TriggerServerEvent('esx_drugs:startSellMeth') - elseif CurrentAction == 'WeedField' then - TriggerServerEvent('esx_drugs:startHarvestWeed') - elseif CurrentAction == 'WeedProcessing' then - TriggerServerEvent('esx_drugs:startTransformWeed') - elseif CurrentAction == 'WeedDealer' then - TriggerServerEvent('esx_drugs:startSellWeed') - elseif CurrentAction == 'OpiumField' then - TriggerServerEvent('esx_drugs:startHarvestOpium') - elseif CurrentAction == 'OpiumProcessing' then - TriggerServerEvent('esx_drugs:startTransformOpium') - elseif CurrentAction == 'OpiumDealer' then - TriggerServerEvent('esx_drugs:startSellOpium') - else - isInZone = false -- not a esx_drugs zone - end - - if isInZone then - TriggerEvent('esx_drugs:freezePlayer', true) - end - - CurrentAction = nil - end - end - end -end) - -RegisterNetEvent('esx_drugs:freezePlayer') -AddEventHandler('esx_drugs:freezePlayer', function(freeze) - FreezeEntityPosition(GetPlayerPed(-1), freeze) -end) +local Keys = { + ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57, + ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177, + ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18, + ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182, + ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81, + ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70, + ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178, + ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173, + ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118 +} + +local cokeQTE = 0 +ESX = nil +local coke_poochQTE = 0 +local weedQTE = 0 +local weed_poochQTE = 0 +local methQTE = 0 +local meth_poochQTE = 0 +local opiumQTE = 0 +local opium_poochQTE = 0 +local myJob = nil +local HasAlreadyEnteredMarker = false +local LastZone = nil +local isInZone = false +local CurrentAction = nil +local CurrentActionMsg = '' +local CurrentActionData = {} + +Citizen.CreateThread(function() + while ESX == nil do + TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) + Citizen.Wait(0) + end +end) + +AddEventHandler('esx_drugs:hasEnteredMarker', function(zone) + if myJob == 'police' or myJob == 'ambulance' then + return + end + + ESX.UI.Menu.CloseAll() + + if zone == 'exitMarker' then + CurrentAction = zone + CurrentActionMsg = _U('exit_marker') + CurrentActionData = {} + end + + if zone == 'CokeField' then + CurrentAction = zone + CurrentActionMsg = _U('press_collect_coke') + CurrentActionData = {} + end + + if zone == 'CokeProcessing' then + if cokeQTE >= 5 then + CurrentAction = zone + CurrentActionMsg = _U('press_process_coke') + CurrentActionData = {} + end + end + + if zone == 'CokeDealer' then + if coke_poochQTE >= 1 then + CurrentAction = zone + CurrentActionMsg = _U('press_sell_coke') + CurrentActionData = {} + end + end + + if zone == 'MethField' then + CurrentAction = zone + CurrentActionMsg = _U('press_collect_meth') + CurrentActionData = {} + end + + if zone == 'MethProcessing' then + if methQTE >= 5 then + CurrentAction = zone + CurrentActionMsg = _U('press_process_meth') + CurrentActionData = {} + end + end + + if zone == 'MethDealer' then + if meth_poochQTE >= 1 then + CurrentAction = zone + CurrentActionMsg = _U('press_sell_meth') + CurrentActionData = {} + end + end + + if zone == 'WeedField' then + CurrentAction = zone + CurrentActionMsg = _U('press_collect_weed') + CurrentActionData = {} + end + + if zone == 'WeedProcessing' then + if weedQTE >= 5 then + CurrentAction = zone + CurrentActionMsg = _U('press_process_weed') + CurrentActionData = {} + end + end + + if zone == 'WeedDealer' then + if weed_poochQTE >= 1 then + CurrentAction = zone + CurrentActionMsg = _U('press_sell_weed') + CurrentActionData = {} + end + end + + if zone == 'OpiumField' then + CurrentAction = zone + CurrentActionMsg = _U('press_collect_opium') + CurrentActionData = {} + end + + if zone == 'OpiumProcessing' then + if opiumQTE >= 5 then + CurrentAction = zone + CurrentActionMsg = _U('press_process_opium') + CurrentActionData = {} + end + end + + if zone == 'OpiumDealer' then + if opium_poochQTE >= 1 then + CurrentAction = zone + CurrentActionMsg = _U('press_sell_opium') + CurrentActionData = {} + end + end +end) + +AddEventHandler('esx_drugs:hasExitedMarker', function(zone) + CurrentAction = nil + ESX.UI.Menu.CloseAll() + + TriggerServerEvent('esx_drugs:stopHarvestCoke') + TriggerServerEvent('esx_drugs:stopTransformCoke') + TriggerServerEvent('esx_drugs:stopSellCoke') + TriggerServerEvent('esx_drugs:stopHarvestMeth') + TriggerServerEvent('esx_drugs:stopTransformMeth') + TriggerServerEvent('esx_drugs:stopSellMeth') + TriggerServerEvent('esx_drugs:stopHarvestWeed') + TriggerServerEvent('esx_drugs:stopTransformWeed') + TriggerServerEvent('esx_drugs:stopSellWeed') + TriggerServerEvent('esx_drugs:stopHarvestOpium') + TriggerServerEvent('esx_drugs:stopTransformOpium') + TriggerServerEvent('esx_drugs:stopSellOpium') +end) + +-- Weed Effect +RegisterNetEvent('esx_drugs:onPot') +AddEventHandler('esx_drugs:onPot', function() + RequestAnimSet("MOVE_M@DRUNK@SLIGHTLYDRUNK") + while not HasAnimSetLoaded("MOVE_M@DRUNK@SLIGHTLYDRUNK") do + Citizen.Wait(0) + end + TaskStartScenarioInPlace(GetPlayerPed(-1), "WORLD_HUMAN_SMOKING_POT", 0, true) + Citizen.Wait(5000) + DoScreenFadeOut(1000) + Citizen.Wait(1000) + ClearPedTasksImmediately(GetPlayerPed(-1)) + SetTimecycleModifier("spectator5") + SetPedMotionBlur(GetPlayerPed(-1), true) + SetPedMovementClipset(GetPlayerPed(-1), "MOVE_M@DRUNK@SLIGHTLYDRUNK", true) + SetPedIsDrunk(GetPlayerPed(-1), true) + DoScreenFadeIn(1000) + Citizen.Wait(600000) + DoScreenFadeOut(1000) + Citizen.Wait(1000) + DoScreenFadeIn(1000) + ClearTimecycleModifier() + ResetScenarioTypesEnabled() + ResetPedMovementClipset(GetPlayerPed(-1), 0) + SetPedIsDrunk(GetPlayerPed(-1), false) + SetPedMotionBlur(GetPlayerPed(-1), false) +end) + +-- Render markers +Citizen.CreateThread(function() + while true do + + Citizen.Wait(0) + + local coords = GetEntityCoords(GetPlayerPed(-1)) + + for k,v in pairs(Config.Zones) do + if(GetDistanceBetweenCoords(coords, v.x, v.y, v.z, true) < Config.DrawDistance) then + DrawMarker(Config.MarkerType, v.x, v.y, v.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.ZoneSize.x, Config.ZoneSize.y, Config.ZoneSize.z, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, false, false, false) + end + end + + end +end) + +if Config.ShowBlips then + -- Create blips + Citizen.CreateThread(function() + for k,v in pairs(Config.Zones) do + local blip = AddBlipForCoord(v.x, v.y, v.z) + + SetBlipSprite (blip, v.sprite) + SetBlipDisplay(blip, 4) + SetBlipScale (blip, 0.9) + SetBlipColour (blip, v.color) + SetBlipAsShortRange(blip, true) + + BeginTextCommandSetBlipName("STRING") + AddTextComponentString(v.name) + EndTextCommandSetBlipName(blip) + end + end) +end + + +-- RETURN NUMBER OF ITEMS FROM SERVER +RegisterNetEvent('esx_drugs:ReturnInventory') +AddEventHandler('esx_drugs:ReturnInventory', function(cokeNbr, cokepNbr, methNbr, methpNbr, weedNbr, weedpNbr, opiumNbr, opiumpNbr, jobName, currentZone) + cokeQTE = cokeNbr + coke_poochQTE = cokepNbr + methQTE = methNbr + meth_poochQTE = methpNbr + weedQTE = weedNbr + weed_poochQTE = weedpNbr + opiumQTE = opiumNbr + opium_poochQTE = opiumpNbr + myJob = jobName + TriggerEvent('esx_drugs:hasEnteredMarker', currentZone) +end) + +-- Activate menu when player is inside marker +Citizen.CreateThread(function() + while true do + + Citizen.Wait(0) + + local coords = GetEntityCoords(GetPlayerPed(-1)) + local isInMarker = false + local currentZone = nil + + for k,v in pairs(Config.Zones) do + if(GetDistanceBetweenCoords(coords, v.x, v.y, v.z, true) < Config.ZoneSize.x / 2) then + isInMarker = true + currentZone = k + end + end + + if isInMarker and not hasAlreadyEnteredMarker then + hasAlreadyEnteredMarker = true + lastZone = currentZone + TriggerServerEvent('esx_drugs:GetUserInventory', currentZone) + end + + if not isInMarker and hasAlreadyEnteredMarker then + hasAlreadyEnteredMarker = false + TriggerEvent('esx_drugs:hasExitedMarker', lastZone) + end + + if isInMarker and isInZone then + TriggerEvent('esx_drugs:hasEnteredMarker', 'exitMarker') + end + end +end) + +-- Key Controls +Citizen.CreateThread(function() + while true do + Citizen.Wait(10) + if CurrentAction ~= nil then + SetTextComponentFormat('STRING') + AddTextComponentString(CurrentActionMsg) + DisplayHelpTextFromStringLabel(0, 0, 1, -1) + if IsControlJustReleased(0, Keys['E']) then + isInZone = true -- unless we set this boolean to false, we will always freeze the user + if CurrentAction == 'exitMarker' then + isInZone = false -- do not freeze user + TriggerEvent('esx_drugs:freezePlayer', false) + TriggerEvent('esx_drugs:hasExitedMarker', lastZone) + Citizen.Wait(15000) + elseif CurrentAction == 'CokeField' then + TriggerServerEvent('esx_drugs:startHarvestCoke') + elseif CurrentAction == 'CokeProcessing' then + TriggerServerEvent('esx_drugs:startTransformCoke') + elseif CurrentAction == 'CokeDealer' then + TriggerServerEvent('esx_drugs:startSellCoke') + elseif CurrentAction == 'MethField' then + TriggerServerEvent('esx_drugs:startHarvestMeth') + elseif CurrentAction == 'MethProcessing' then + TriggerServerEvent('esx_drugs:startTransformMeth') + elseif CurrentAction == 'MethDealer' then + TriggerServerEvent('esx_drugs:startSellMeth') + elseif CurrentAction == 'WeedField' then + TriggerServerEvent('esx_drugs:startHarvestWeed') + elseif CurrentAction == 'WeedProcessing' then + TriggerServerEvent('esx_drugs:startTransformWeed') + elseif CurrentAction == 'WeedDealer' then + TriggerServerEvent('esx_drugs:startSellWeed') + elseif CurrentAction == 'OpiumField' then + TriggerServerEvent('esx_drugs:startHarvestOpium') + elseif CurrentAction == 'OpiumProcessing' then + TriggerServerEvent('esx_drugs:startTransformOpium') + elseif CurrentAction == 'OpiumDealer' then + TriggerServerEvent('esx_drugs:startSellOpium') + else + isInZone = false -- not a esx_drugs zone + end + + if isInZone then + TriggerEvent('esx_drugs:freezePlayer', true) + end + + CurrentAction = nil + end + end + end +end) + +RegisterNetEvent('esx_drugs:freezePlayer') +AddEventHandler('esx_drugs:freezePlayer', function(freeze) + FreezeEntityPosition(GetPlayerPed(-1), freeze) +end) diff --git a/server/esx_drugs_sv.lua b/server/main.lua similarity index 96% rename from server/esx_drugs_sv.lua rename to server/main.lua index 2e4401a9..9fe2394d 100644 --- a/server/esx_drugs_sv.lua +++ b/server/main.lua @@ -1,643 +1,643 @@ -ESX = nil -local CopsConnected = 0 -local PlayersHarvestingCoke = {} -local PlayersTransformingCoke = {} -local PlayersSellingCoke = {} -local PlayersHarvestingMeth = {} -local PlayersTransformingMeth = {} -local PlayersSellingMeth = {} -local PlayersHarvestingWeed = {} -local PlayersTransformingWeed = {} -local PlayersSellingWeed = {} -local PlayersHarvestingOpium = {} -local PlayersTransformingOpium = {} -local PlayersSellingOpium = {} - -TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) - -function CountCops() - local xPlayers = ESX.GetPlayers() - - CopsConnected = 0 - - for i=1, #xPlayers, 1 do - local xPlayer = ESX.GetPlayerFromId(xPlayers[i]) - if xPlayer.job.name == 'police' then - CopsConnected = CopsConnected + 1 - end - end - - SetTimeout(120 * 1000, CountCops) -end - -CountCops() - ---coke -local function HarvestCoke(source) - if CopsConnected < Config.RequiredCopsCoke then - TriggerClientEvent('esx:showNotification', source, _U('act_imp_police', CopsConnected, Config.RequiredCopsCoke)) - return - end - - SetTimeout(Config.TimeToFarm, function() - if PlayersHarvestingCoke[source] 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, _U('inv_full_coke')) - 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, _U('pickup_in_prog')) - - 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, _U('act_imp_police', CopsConnected, Config.RequiredCopsCoke)) - return - end - - SetTimeout(Config.TimeToProcess, function() - if PlayersTransformingCoke[source] then - local xPlayer = ESX.GetPlayerFromId(source) - local cokeQuantity = xPlayer.getInventoryItem('coke').count - local pooch = xPlayer.getInventoryItem('coke_pooch').count - - if pooch.limit ~= -1 and pooch.count >= pooch.limit then - TriggerClientEvent('esx:showNotification', source, _U('too_many_pouches')) - elseif cokeQuantity < 5 then - TriggerClientEvent('esx:showNotification', source, _U('not_enough_coke')) - 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, _U('packing_in_prog')) - - 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, _U('act_imp_police', CopsConnected, Config.RequiredCopsCoke)) - return - end - - SetTimeout(Config.TimeToSell, function() - if PlayersSellingCoke[source] then - local xPlayer = ESX.GetPlayerFromId(source) - local poochQuantity = xPlayer.getInventoryItem('coke_pooch').count - - if poochQuantity == 0 then - TriggerClientEvent('esx:showNotification', source, _U('no_pouches_sale')) - else - xPlayer.removeInventoryItem('coke_pooch', 1) - if CopsConnected == 0 then - xPlayer.addAccountMoney('black_money', 198) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_coke')) - elseif CopsConnected == 1 then - xPlayer.addAccountMoney('black_money', 258) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_coke')) - elseif CopsConnected == 2 then - xPlayer.addAccountMoney('black_money', 308) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_coke')) - elseif CopsConnected == 3 then - xPlayer.addAccountMoney('black_money', 358) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_coke')) - elseif CopsConnected == 4 then - xPlayer.addAccountMoney('black_money', 396) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_coke')) - elseif CopsConnected >= 5 then - xPlayer.addAccountMoney('black_money', 428) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_coke')) - 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, _U('sale_in_prog')) - - SellCoke(_source) -end) - -RegisterServerEvent('esx_drugs:stopSellCoke') -AddEventHandler('esx_drugs:stopSellCoke', function() - local _source = source - - PlayersSellingCoke[_source] = false -end) - ---meth -local function HarvestMeth(source) - if CopsConnected < Config.RequiredCopsMeth then - TriggerClientEvent('esx:showNotification', source, _U('act_imp_police', CopsConnected, Config.RequiredCopsMeth)) - return - end - - SetTimeout(Config.TimeToFarm, function() - if PlayersHarvestingMeth[source] 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, _U('inv_full_meth')) - 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, _U('pickup_in_prog')) - - 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, _U('act_imp_police', CopsConnected, Config.RequiredCopsMeth)) - return - end - - SetTimeout(Config.TimeToProcess, function() - if PlayersTransformingMeth[source] then - local xPlayer = ESX.GetPlayerFromId(source) - local methQuantity = xPlayer.getInventoryItem('meth').count - local pooch = xPlayer.getInventoryItem('meth_pooch') - - if pooch.limit ~= -1 and pooch.count >= pooch.limit then - TriggerClientEvent('esx:showNotification', source, _U('too_many_pouches')) - elseif methQuantity < 5 then - TriggerClientEvent('esx:showNotification', source, _U('not_enough_meth')) - else - xPlayer.removeInventoryItem('meth', 5) - xPlayer.addInventoryItem('meth_pooch', 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, _U('packing_in_prog')) - - 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, _U('act_imp_police', CopsConnected, Config.RequiredCopsMeth)) - return - end - - SetTimeout(Config.TimeToSell, function() - if PlayersSellingMeth[source] then - local xPlayer = ESX.GetPlayerFromId(source) - local poochQuantity = xPlayer.getInventoryItem('meth_pooch').count - - if poochQuantity == 0 then - TriggerClientEvent('esx:showNotification', source, _U('no_pouches_sale')) - else - xPlayer.removeInventoryItem('meth_pooch', 1) - if CopsConnected == 0 then - xPlayer.addAccountMoney('black_money', 276) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_meth')) - elseif CopsConnected == 1 then - xPlayer.addAccountMoney('black_money', 374) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_meth')) - elseif CopsConnected == 2 then - xPlayer.addAccountMoney('black_money', 474) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_meth')) - elseif CopsConnected == 3 then - xPlayer.addAccountMoney('black_money', 552) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_meth')) - elseif CopsConnected == 4 then - xPlayer.addAccountMoney('black_money', 616) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_meth')) - elseif CopsConnected == 5 then - xPlayer.addAccountMoney('black_money', 654) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_meth')) - elseif CopsConnected >= 6 then - xPlayer.addAccountMoney('black_money', 686) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_meth')) - 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, _U('sale_in_prog')) - - SellMeth(_source) -end) - -RegisterServerEvent('esx_drugs:stopSellMeth') -AddEventHandler('esx_drugs:stopSellMeth', function() - local _source = source - - PlayersSellingMeth[_source] = false -end) - ---weed -local function HarvestWeed(source) - if CopsConnected < Config.RequiredCopsWeed then - TriggerClientEvent('esx:showNotification', source, _U('act_imp_police', CopsConnected, Config.RequiredCopsWeed)) - return - end - - SetTimeout(Config.TimeToFarm, function() - if PlayersHarvestingWeed[source] == true then - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) - local weed = xPlayer.getInventoryItem('weed') - - if weed.limit ~= -1 and weed.count >= weed.limit then - TriggerClientEvent('esx:showNotification', source, _U('inv_full_weed')) - 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, _U('pickup_in_prog')) - - 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, _U('act_imp_police', CopsConnected, Config.RequiredCopsWeed)) - return - end - - SetTimeout(Config.TimeToProcess, function() - if PlayersTransformingWeed[source] then - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) - local weedQuantity = xPlayer.getInventoryItem('weed').count - local pooch = xPlayer.getInventoryItem('weed_pooch') - - if pooch.limit ~= -1 and pooch.count >= pooch.limit then - TriggerClientEvent('esx:showNotification', source, _U('too_many_pouches')) - elseif weedQuantity < 5 then - TriggerClientEvent('esx:showNotification', source, _U('not_enough_weed')) - 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, _U('packing_in_prog')) - - 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:showNotification', source, _U('act_imp_police', CopsConnected, Config.RequiredCopsWeed)) - return - end - - SetTimeout(Config.TimeToSell, function() - if PlayersSellingWeed[source] then - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) - local poochQuantity = xPlayer.getInventoryItem('weed_pooch').count - - if poochQuantity == 0 then - TriggerClientEvent('esx:showNotification', source, _U('no_pouches_sale')) - else - xPlayer.removeInventoryItem('weed_pooch', 1) - if CopsConnected == 0 then - xPlayer.addAccountMoney('black_money', 108) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_weed')) - elseif CopsConnected == 1 then - xPlayer.addAccountMoney('black_money', 128) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_weed')) - elseif CopsConnected == 2 then - xPlayer.addAccountMoney('black_money', 152) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_weed')) - elseif CopsConnected == 3 then - xPlayer.addAccountMoney('black_money', 165) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_weed')) - elseif CopsConnected >= 4 then - xPlayer.addAccountMoney('black_money', 180) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_weed')) - 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, _U('sale_in_prog')) - - SellWeed(_source) -end) - -RegisterServerEvent('esx_drugs:stopSellWeed') -AddEventHandler('esx_drugs:stopSellWeed', function() - local _source = source - - PlayersSellingWeed[_source] = false -end) - - ---opium - -local function HarvestOpium(source) - if CopsConnected < Config.RequiredCopsOpium then - TriggerClientEvent('esx:showNotification', source, _U('act_imp_police', CopsConnected, Config.RequiredCopsOpium)) - return - end - - SetTimeout(Config.TimeToFarm, function() - if PlayersHarvestingOpium[source] then - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) - local opium = xPlayer.getInventoryItem('opium') - - if opium.limit ~= -1 and opium.count >= opium.limit then - TriggerClientEvent('esx:showNotification', _source, _U('inv_full_opium')) - else - xPlayer.addInventoryItem('opium', 1) - HarvestOpium(_source) - end - end - end) -end - -RegisterServerEvent('esx_drugs:startHarvestOpium') -AddEventHandler('esx_drugs:startHarvestOpium', function() - local _source = source - - PlayersHarvestingOpium[_source] = true - - TriggerClientEvent('esx:showNotification', _source, _U('pickup_in_prog')) - - HarvestOpium(_source) -end) - -RegisterServerEvent('esx_drugs:stopHarvestOpium') -AddEventHandler('esx_drugs:stopHarvestOpium', function() - local _source = source - - PlayersHarvestingOpium[_source] = false -end) - -local function TransformOpium(source) - if CopsConnected < Config.RequiredCopsOpium then - TriggerClientEvent('esx:showNotification', source, _U('act_imp_police', CopsConnected, Config.RequiredCopsOpium)) - return - end - - SetTimeout(Config.TimeToProcess, function() - if PlayersTransformingOpium[source] then - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) - - local opiumQuantity = xPlayer.getInventoryItem('opium').count - local pooch = xPlayer.getInventoryItem('opium_pooch') - - if pooch.limit ~= -1 and pooch.count >= pooch.limit then - TriggerClientEvent('esx:showNotification', _source, _U('too_many_pouches')) - elseif opiumQuantity < 5 then - TriggerClientEvent('esx:showNotification', _source, _U('not_enough_opium')) - else - xPlayer.removeInventoryItem('opium', 5) - xPlayer.addInventoryItem('opium_pooch', 1) - - TransformOpium(_source) - end - end - end) -end - -RegisterServerEvent('esx_drugs:startTransformOpium') -AddEventHandler('esx_drugs:startTransformOpium', function() - local _source = source - - PlayersTransformingOpium[_source] = true - - TriggerClientEvent('esx:showNotification', _source, _U('packing_in_prog')) - - TransformOpium(_source) -end) - -RegisterServerEvent('esx_drugs:stopTransformOpium') -AddEventHandler('esx_drugs:stopTransformOpium', function() - local _source = source - - PlayersTransformingOpium[_source] = false -end) - -local function SellOpium(source) - if CopsConnected < Config.RequiredCopsOpium then - TriggerClientEvent('esx:showNotification', source, _U('act_imp_police', CopsConnected, Config.RequiredCopsOpium)) - return - end - - SetTimeout(Config.TimeToSell, function() - if PlayersSellingOpium[source] then - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) - local poochQuantity = xPlayer.getInventoryItem('opium_pooch').count - - if poochQuantity == 0 then - TriggerClientEvent('esx:showNotification', source, _U('no_pouches_sale')) - else - xPlayer.removeInventoryItem('opium_pooch', 1) - if CopsConnected == 0 then - xPlayer.addAccountMoney('black_money', 300) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_opium')) - elseif CopsConnected == 1 then - xPlayer.addAccountMoney('black_money', 500) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_opium')) - elseif CopsConnected == 2 then - xPlayer.addAccountMoney('black_money', 700) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_opium')) - elseif CopsConnected == 3 then - xPlayer.addAccountMoney('black_money', 800) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_opium')) - elseif CopsConnected == 4 then - xPlayer.addAccountMoney('black_money', 900) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_opium')) - elseif CopsConnected >= 5 then - xPlayer.addAccountMoney('black_money', 1000) - TriggerClientEvent('esx:showNotification', source, _U('sold_one_opium')) - end - - SellOpium(source) - end - end - end) -end - -RegisterServerEvent('esx_drugs:startSellOpium') -AddEventHandler('esx_drugs:startSellOpium', function() - local _source = source - - PlayersSellingOpium[_source] = true - - TriggerClientEvent('esx:showNotification', _source, _U('sale_in_prog')) - - SellOpium(_source) -end) - -RegisterServerEvent('esx_drugs:stopSellOpium') -AddEventHandler('esx_drugs:stopSellOpium', function() - local _source = source - - PlayersSellingOpium[_source] = false -end) - -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.getInventoryItem('opium').count, - xPlayer.getInventoryItem('opium_pooch').count, - xPlayer.job.name, - currentZone - ) -end) - -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, _U('used_one_weed')) -end) +ESX = nil +local CopsConnected = 0 +local PlayersHarvestingCoke = {} +local PlayersTransformingCoke = {} +local PlayersSellingCoke = {} +local PlayersHarvestingMeth = {} +local PlayersTransformingMeth = {} +local PlayersSellingMeth = {} +local PlayersHarvestingWeed = {} +local PlayersTransformingWeed = {} +local PlayersSellingWeed = {} +local PlayersHarvestingOpium = {} +local PlayersTransformingOpium = {} +local PlayersSellingOpium = {} + +TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) + +function CountCops() + local xPlayers = ESX.GetPlayers() + + CopsConnected = 0 + + for i=1, #xPlayers, 1 do + local xPlayer = ESX.GetPlayerFromId(xPlayers[i]) + if xPlayer.job.name == 'police' then + CopsConnected = CopsConnected + 1 + end + end + + SetTimeout(120 * 1000, CountCops) +end + +CountCops() + +--coke +local function HarvestCoke(source) + if CopsConnected < Config.RequiredCopsCoke then + TriggerClientEvent('esx:showNotification', source, _U('act_imp_police', CopsConnected, Config.RequiredCopsCoke)) + return + end + + SetTimeout(Config.TimeToFarm, function() + if PlayersHarvestingCoke[source] 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, _U('inv_full_coke')) + 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, _U('pickup_in_prog')) + + 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, _U('act_imp_police', CopsConnected, Config.RequiredCopsCoke)) + return + end + + SetTimeout(Config.TimeToProcess, function() + if PlayersTransformingCoke[source] then + local xPlayer = ESX.GetPlayerFromId(source) + local cokeQuantity = xPlayer.getInventoryItem('coke').count + local pooch = xPlayer.getInventoryItem('coke_pooch').count + + if pooch.limit ~= -1 and pooch.count >= pooch.limit then + TriggerClientEvent('esx:showNotification', source, _U('too_many_pouches')) + elseif cokeQuantity < 5 then + TriggerClientEvent('esx:showNotification', source, _U('not_enough_coke')) + 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, _U('packing_in_prog')) + + 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, _U('act_imp_police', CopsConnected, Config.RequiredCopsCoke)) + return + end + + SetTimeout(Config.TimeToSell, function() + if PlayersSellingCoke[source] then + local xPlayer = ESX.GetPlayerFromId(source) + local poochQuantity = xPlayer.getInventoryItem('coke_pooch').count + + if poochQuantity == 0 then + TriggerClientEvent('esx:showNotification', source, _U('no_pouches_sale')) + else + xPlayer.removeInventoryItem('coke_pooch', 1) + if CopsConnected == 0 then + xPlayer.addAccountMoney('black_money', 198) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_coke')) + elseif CopsConnected == 1 then + xPlayer.addAccountMoney('black_money', 258) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_coke')) + elseif CopsConnected == 2 then + xPlayer.addAccountMoney('black_money', 308) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_coke')) + elseif CopsConnected == 3 then + xPlayer.addAccountMoney('black_money', 358) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_coke')) + elseif CopsConnected == 4 then + xPlayer.addAccountMoney('black_money', 396) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_coke')) + elseif CopsConnected >= 5 then + xPlayer.addAccountMoney('black_money', 428) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_coke')) + 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, _U('sale_in_prog')) + + SellCoke(_source) +end) + +RegisterServerEvent('esx_drugs:stopSellCoke') +AddEventHandler('esx_drugs:stopSellCoke', function() + local _source = source + + PlayersSellingCoke[_source] = false +end) + +--meth +local function HarvestMeth(source) + if CopsConnected < Config.RequiredCopsMeth then + TriggerClientEvent('esx:showNotification', source, _U('act_imp_police', CopsConnected, Config.RequiredCopsMeth)) + return + end + + SetTimeout(Config.TimeToFarm, function() + if PlayersHarvestingMeth[source] 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, _U('inv_full_meth')) + 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, _U('pickup_in_prog')) + + 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, _U('act_imp_police', CopsConnected, Config.RequiredCopsMeth)) + return + end + + SetTimeout(Config.TimeToProcess, function() + if PlayersTransformingMeth[source] then + local xPlayer = ESX.GetPlayerFromId(source) + local methQuantity = xPlayer.getInventoryItem('meth').count + local pooch = xPlayer.getInventoryItem('meth_pooch') + + if pooch.limit ~= -1 and pooch.count >= pooch.limit then + TriggerClientEvent('esx:showNotification', source, _U('too_many_pouches')) + elseif methQuantity < 5 then + TriggerClientEvent('esx:showNotification', source, _U('not_enough_meth')) + else + xPlayer.removeInventoryItem('meth', 5) + xPlayer.addInventoryItem('meth_pooch', 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, _U('packing_in_prog')) + + 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, _U('act_imp_police', CopsConnected, Config.RequiredCopsMeth)) + return + end + + SetTimeout(Config.TimeToSell, function() + if PlayersSellingMeth[source] then + local xPlayer = ESX.GetPlayerFromId(source) + local poochQuantity = xPlayer.getInventoryItem('meth_pooch').count + + if poochQuantity == 0 then + TriggerClientEvent('esx:showNotification', source, _U('no_pouches_sale')) + else + xPlayer.removeInventoryItem('meth_pooch', 1) + if CopsConnected == 0 then + xPlayer.addAccountMoney('black_money', 276) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_meth')) + elseif CopsConnected == 1 then + xPlayer.addAccountMoney('black_money', 374) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_meth')) + elseif CopsConnected == 2 then + xPlayer.addAccountMoney('black_money', 474) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_meth')) + elseif CopsConnected == 3 then + xPlayer.addAccountMoney('black_money', 552) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_meth')) + elseif CopsConnected == 4 then + xPlayer.addAccountMoney('black_money', 616) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_meth')) + elseif CopsConnected == 5 then + xPlayer.addAccountMoney('black_money', 654) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_meth')) + elseif CopsConnected >= 6 then + xPlayer.addAccountMoney('black_money', 686) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_meth')) + 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, _U('sale_in_prog')) + + SellMeth(_source) +end) + +RegisterServerEvent('esx_drugs:stopSellMeth') +AddEventHandler('esx_drugs:stopSellMeth', function() + local _source = source + + PlayersSellingMeth[_source] = false +end) + +--weed +local function HarvestWeed(source) + if CopsConnected < Config.RequiredCopsWeed then + TriggerClientEvent('esx:showNotification', source, _U('act_imp_police', CopsConnected, Config.RequiredCopsWeed)) + return + end + + SetTimeout(Config.TimeToFarm, function() + if PlayersHarvestingWeed[source] == true then + local _source = source + local xPlayer = ESX.GetPlayerFromId(_source) + local weed = xPlayer.getInventoryItem('weed') + + if weed.limit ~= -1 and weed.count >= weed.limit then + TriggerClientEvent('esx:showNotification', source, _U('inv_full_weed')) + 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, _U('pickup_in_prog')) + + 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, _U('act_imp_police', CopsConnected, Config.RequiredCopsWeed)) + return + end + + SetTimeout(Config.TimeToProcess, function() + if PlayersTransformingWeed[source] then + local _source = source + local xPlayer = ESX.GetPlayerFromId(_source) + local weedQuantity = xPlayer.getInventoryItem('weed').count + local pooch = xPlayer.getInventoryItem('weed_pooch') + + if pooch.limit ~= -1 and pooch.count >= pooch.limit then + TriggerClientEvent('esx:showNotification', source, _U('too_many_pouches')) + elseif weedQuantity < 5 then + TriggerClientEvent('esx:showNotification', source, _U('not_enough_weed')) + 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, _U('packing_in_prog')) + + 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:showNotification', source, _U('act_imp_police', CopsConnected, Config.RequiredCopsWeed)) + return + end + + SetTimeout(Config.TimeToSell, function() + if PlayersSellingWeed[source] then + local _source = source + local xPlayer = ESX.GetPlayerFromId(_source) + local poochQuantity = xPlayer.getInventoryItem('weed_pooch').count + + if poochQuantity == 0 then + TriggerClientEvent('esx:showNotification', source, _U('no_pouches_sale')) + else + xPlayer.removeInventoryItem('weed_pooch', 1) + if CopsConnected == 0 then + xPlayer.addAccountMoney('black_money', 108) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_weed')) + elseif CopsConnected == 1 then + xPlayer.addAccountMoney('black_money', 128) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_weed')) + elseif CopsConnected == 2 then + xPlayer.addAccountMoney('black_money', 152) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_weed')) + elseif CopsConnected == 3 then + xPlayer.addAccountMoney('black_money', 165) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_weed')) + elseif CopsConnected >= 4 then + xPlayer.addAccountMoney('black_money', 180) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_weed')) + 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, _U('sale_in_prog')) + + SellWeed(_source) +end) + +RegisterServerEvent('esx_drugs:stopSellWeed') +AddEventHandler('esx_drugs:stopSellWeed', function() + local _source = source + + PlayersSellingWeed[_source] = false +end) + + +--opium + +local function HarvestOpium(source) + if CopsConnected < Config.RequiredCopsOpium then + TriggerClientEvent('esx:showNotification', source, _U('act_imp_police', CopsConnected, Config.RequiredCopsOpium)) + return + end + + SetTimeout(Config.TimeToFarm, function() + if PlayersHarvestingOpium[source] then + local _source = source + local xPlayer = ESX.GetPlayerFromId(_source) + local opium = xPlayer.getInventoryItem('opium') + + if opium.limit ~= -1 and opium.count >= opium.limit then + TriggerClientEvent('esx:showNotification', _source, _U('inv_full_opium')) + else + xPlayer.addInventoryItem('opium', 1) + HarvestOpium(_source) + end + end + end) +end + +RegisterServerEvent('esx_drugs:startHarvestOpium') +AddEventHandler('esx_drugs:startHarvestOpium', function() + local _source = source + + PlayersHarvestingOpium[_source] = true + + TriggerClientEvent('esx:showNotification', _source, _U('pickup_in_prog')) + + HarvestOpium(_source) +end) + +RegisterServerEvent('esx_drugs:stopHarvestOpium') +AddEventHandler('esx_drugs:stopHarvestOpium', function() + local _source = source + + PlayersHarvestingOpium[_source] = false +end) + +local function TransformOpium(source) + if CopsConnected < Config.RequiredCopsOpium then + TriggerClientEvent('esx:showNotification', source, _U('act_imp_police', CopsConnected, Config.RequiredCopsOpium)) + return + end + + SetTimeout(Config.TimeToProcess, function() + if PlayersTransformingOpium[source] then + local _source = source + local xPlayer = ESX.GetPlayerFromId(_source) + + local opiumQuantity = xPlayer.getInventoryItem('opium').count + local pooch = xPlayer.getInventoryItem('opium_pooch') + + if pooch.limit ~= -1 and pooch.count >= pooch.limit then + TriggerClientEvent('esx:showNotification', _source, _U('too_many_pouches')) + elseif opiumQuantity < 5 then + TriggerClientEvent('esx:showNotification', _source, _U('not_enough_opium')) + else + xPlayer.removeInventoryItem('opium', 5) + xPlayer.addInventoryItem('opium_pooch', 1) + + TransformOpium(_source) + end + end + end) +end + +RegisterServerEvent('esx_drugs:startTransformOpium') +AddEventHandler('esx_drugs:startTransformOpium', function() + local _source = source + + PlayersTransformingOpium[_source] = true + + TriggerClientEvent('esx:showNotification', _source, _U('packing_in_prog')) + + TransformOpium(_source) +end) + +RegisterServerEvent('esx_drugs:stopTransformOpium') +AddEventHandler('esx_drugs:stopTransformOpium', function() + local _source = source + + PlayersTransformingOpium[_source] = false +end) + +local function SellOpium(source) + if CopsConnected < Config.RequiredCopsOpium then + TriggerClientEvent('esx:showNotification', source, _U('act_imp_police', CopsConnected, Config.RequiredCopsOpium)) + return + end + + SetTimeout(Config.TimeToSell, function() + if PlayersSellingOpium[source] then + local _source = source + local xPlayer = ESX.GetPlayerFromId(_source) + local poochQuantity = xPlayer.getInventoryItem('opium_pooch').count + + if poochQuantity == 0 then + TriggerClientEvent('esx:showNotification', source, _U('no_pouches_sale')) + else + xPlayer.removeInventoryItem('opium_pooch', 1) + if CopsConnected == 0 then + xPlayer.addAccountMoney('black_money', 300) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_opium')) + elseif CopsConnected == 1 then + xPlayer.addAccountMoney('black_money', 500) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_opium')) + elseif CopsConnected == 2 then + xPlayer.addAccountMoney('black_money', 700) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_opium')) + elseif CopsConnected == 3 then + xPlayer.addAccountMoney('black_money', 800) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_opium')) + elseif CopsConnected == 4 then + xPlayer.addAccountMoney('black_money', 900) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_opium')) + elseif CopsConnected >= 5 then + xPlayer.addAccountMoney('black_money', 1000) + TriggerClientEvent('esx:showNotification', source, _U('sold_one_opium')) + end + + SellOpium(source) + end + end + end) +end + +RegisterServerEvent('esx_drugs:startSellOpium') +AddEventHandler('esx_drugs:startSellOpium', function() + local _source = source + + PlayersSellingOpium[_source] = true + + TriggerClientEvent('esx:showNotification', _source, _U('sale_in_prog')) + + SellOpium(_source) +end) + +RegisterServerEvent('esx_drugs:stopSellOpium') +AddEventHandler('esx_drugs:stopSellOpium', function() + local _source = source + + PlayersSellingOpium[_source] = false +end) + +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.getInventoryItem('opium').count, + xPlayer.getInventoryItem('opium_pooch').count, + xPlayer.job.name, + currentZone + ) +end) + +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, _U('used_one_weed')) +end)