Neler yeni

Foruma hoş geldin, Ziyaretçi

Forum içeriğine ve tüm hizmetlerimize erişim sağlamak için foruma kayıt olmalı ya da giriş yapmalısınız. Foruma üye olmak tamamen ücretsizdir.

Türkiye'nin İlk ve tek FiveM forum adresi

Forum adresimize hoş geldin FiveMTürk olarak amacımız siz değerli kullanıcılarımıza en aktif fikir ve paylaşım platformu sunmak bir yana en güvenilir şekilde alışveriş yapabileceğiniz bir platform sunmaktır.
DF DF
DF DF
DF DF

Yardım Policejob Obje Al Açılmıyor

  • Konbuyu başlatan Turqi
  • Başlangıç tarihi
  • Cevaplar 0
  • Görüntüleme 554

Turqi

Üye
FT Kullanıcı
Katılım
4 yıl 4 ay 8 gün
Mesajlar
208
Discord
TheRock#0001
Merhaba Arkadşalar Tekrardan Yardım Gerektiği İçin Bu Konuyu Açmak İstedim Sorunum Şuki obje al menüsü hiç Bir Şekilde açılmamaktadır. Yardımınız Gerek





Client/main.lua

Kod:
local PlayerData, CurrentActionData, handcuffTimer, dragStatus, blipsCops, currentTask, spawnedVehicles = {}, {}, {}, {}, {}, {}, {}
local HasAlreadyEnteredMarker, isDead, IsHandcuffed, hasAlreadyJoined, playerInService, isInShopMenu = false, false, false, false, false, false
local LastStation, LastPart, LastPartNum, LastEntity, CurrentAction, CurrentActionMsg
dragStatus.isDragged = false
ESX = nil

Citizen.CreateThread(function()
    while ESX == nil do
        TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
        Citizen.Wait(0)
    end

    while ESX.GetPlayerData().job == nil do
        Citizen.Wait(10)
    end

    PlayerData = ESX.GetPlayerData()
end)

function cleanPlayer(playerPed)
    SetPedArmour(playerPed, 0)
    ClearPedBloodDamage(playerPed)
    ResetPedVisibleDamage(playerPed)
    ClearPedLastWeaponDamage(playerPed)
    ResetPedMovementClipset(playerPed, 0)
end

function setUniform(job, playerPed)
    TriggerEvent('skinchanger:getSkin', function(skin)
        if skin.sex == 0 then
            if Config.Uniforms[job].male ~= nil then
                TriggerEvent('skinchanger:loadClothes', skin, Config.Uniforms[job].male)
            else
                ESX.ShowNotification(_U('no_outfit'))
            end
            if job == 'Balistic_Vest' then
                SetPedArmour(playerPed, 100)
            end
        else
            if Config.Uniforms[job].female ~= nil then
                TriggerEvent('skinchanger:loadClothes', skin, Config.Uniforms[job].female)
            else
                ESX.ShowNotification(_U('no_outfit'))
            end
            if job == 'Balistic_Vest' then
                SetPedArmour(playerPed, 100)
            end
        end
    end)
end

function OpenCloakroomMenu()

    local playerPed = PlayerPedId()
    local grade = PlayerData.job.grade_name

    local elements = {
        { label = "Üniformayı Çıkart", value = 'citizen_wear' },
        { label = "Çelik Yelek Çıkart", value = 'remove_vest' },
        { label = "Kaskı Çıkart", value = 'remove_helmet' },
        { label = "Çanta Çıkart", value = 'Remove_Bag' },
        { label = "Çelik Yelek", value = 'Balistic_Vest' },
        { label = "Silah Kılıfı (1)", value = 'Duty_belt_1' },
        { label = "Silah Kılıfı (2)", value = 'Duty_belt_2' },
        { label = "Silah Kılıfı (3)", value = 'Duty_belt_3' },
        { label = "Silah Kılıfı (4)", value = 'Duty_belt_4' },
        { label = "Tactical Kıyafet (Siyah)", value = 'Tactical_Top_SWAT' },
        { label = "Tactical Kıyafet (Yeşil)", value = 'Tactical_Top_SERT' },
        { label = "Tactical Kıyafet (Gri)", value = 'Tactical_Top_SESU' },
        { label = "Polis Gömlek", value = 'Police_Shirt' },
        { label = "Polis Pantolon", value = 'Suit_Pants' },
        { label = "Tactical Pantolon", value = 'Tactical_Pants' },
        { label = "Polis Ayakkabı", value = 'Suit_Shoes' },
        { label = "Polis Bot", value = 'Posh_Work_Shoes' },
        { label = "Tactical Bot", value = 'Tactical_Shoes' },
        { label = "Polis Rozet (1)", value = 'Police_ID_1' },
        { label = "Polis Rozet (2)", value = 'Police_ID_2' },
        { label = "Polis Kaskı", value = 'Basic_Helmet' },
        { label = "Polis Şapka", value = 'Police_Hat' },
        { label = "Polis Siyah Şapka", value = 'Black_Cap' },
        { label = "Geliştirilmiş Kask", value = 'Enhanced_Helmet' },
        { label = "Polis Kask", value = 'Riot_Helmet' },
        { label = "Polis Siyah Bere", value = 'Black_Beanie' }
    }
--[[
    table.insert(elements, {label = 'State Police Uniform', value = 'freemode_ped', maleModel = 's_m_y_hwaycop_01', femaleModel = 's_m_y_hwaycop_01'})
    table.insert(elements, {label = 'SWAT Uniform (3)', value = 'freemode_ped', maleModel = 's_m_y_swat_01', femaleModel = 's_m_y_swat_01'})
--]]
    ESX.UI.Menu.CloseAll()

    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'cloakroom',
    {
        title    = _U('cloakroom'),
        align    = 'top-left',
        elements = elements
    }, function(data, menu)

        cleanPlayer(playerPed)

        if data.current.value == 'citizen_wear' then
            
            if Config.EnableNonFreemodePeds then
                ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin)
                    local isMale = skin.sex == 0

                    TriggerEvent('skinchanger:loadDefaultModel', isMale, function()
                        ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
                            TriggerEvent('skinchanger:loadSkin', skin)
                            TriggerEvent('esx:restoreLoadout')
                        end)
                    end)

                end)
            else
                ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin)
                    TriggerEvent('skinchanger:loadSkin', skin)
                end)
            end
        end
        if
            data.current.value == 'Balistic_Vest' or
            data.current.value == 'remove_vest' or
            data.current.value == 'remove_helmet' or
            data.current.value == 'Remove_Bag' or
            data.current.value == 'Duty_belt_1' or
            data.current.value == 'Duty_belt_2' or
            data.current.value == 'Duty_belt_3' or
            data.current.value == 'Duty_belt_4' or
            data.current.value == 'Tactical_Top_SWAT' or
            data.current.value == 'Tactical_Top_SERT' or
            data.current.value == 'Tactical_Top_SESU' or
            data.current.value == 'Police_Shirt' or
            data.current.value == 'Suit_Pants' or
            data.current.value == 'Tactical_Pants' or
            data.current.value == 'Suit_Shoes' or
            data.current.value == 'Posh_Work_Shoes' or
            data.current.value == 'Tactical_Shoes' or
            data.current.value == 'Police_ID_1' or
            data.current.value == 'Police_ID_2' or
            data.current.value == 'Basic_Helmet' or
            data.current.value == 'Police_Hat' or
            data.current.value == 'Black_Cap' or
            data.current.value == 'Enhanced_Helmet' or
            data.current.value == 'Riot_Helmet' or
            data.current.value == 'Black_Beanie'       
        then
            setUniform(data.current.value, playerPed)
        end

        if data.current.value == 'freemode_ped' then
            local modelHash = ''

            ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin)
                if skin.sex == 0 then
                    modelHash = GetHashKey(data.current.maleModel)
                else
                    modelHash = GetHashKey(data.current.femaleModel)
                end

                ESX.Streaming.RequestModel(modelHash, function()
                    SetPlayerModel(PlayerId(), modelHash)
                    SetModelAsNoLongerNeeded(modelHash)

                    TriggerEvent('esx:restoreLoadout')
                end)
            end)
        end

    end, function(data, menu)
        menu.close()
        CurrentAction     = 'menu_cloakroom'
        CurrentActionMsg  = _U('open_cloackroom')
        CurrentActionData = {}
    end)
end

function OpenArmoryMenu(station)
    local elements = {
        {label = _U('buy_weapons'), value = 'buy_weapons'}
    }

    if Config.EnableArmoryManagement then
        table.insert(elements, {label = _U('get_weapon'),     value = 'get_weapon'})
        table.insert(elements, {label = _U('put_weapon'),     value = 'put_weapon'})
        table.insert(elements, {label = _U('remove_object'),  value = 'get_stock'})
        table.insert(elements, {label = _U('deposit_object'), value = 'put_stock'})
    end

    ESX.UI.Menu.CloseAll()

    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'armory',
    {
        title    = _U('armory'),
        align    = 'top-left',
        elements = elements
    }, function(data, menu)

        if data.current.value == 'get_weapon' then
            OpenGetWeaponMenu()
        elseif data.current.value == 'put_weapon' then
            OpenPutWeaponMenu()
        elseif data.current.value == 'buy_weapons' then
            OpenBuyWeaponsMenu()
        elseif data.current.value == 'put_stock' then
            OpenPutStocksMenu()
        elseif data.current.value == 'get_stock' then
            OpenGetStocksMenu()
        end

    end, function(data, menu)
        menu.close()

        CurrentAction     = 'menu_armory'
        CurrentActionMsg  = _U('open_armory')
        CurrentActionData = {station = station}
    end)
end

function OpenVehicleSpawnerMenu(type, station, part, partNum)
    local playerCoords = GetEntityCoords(PlayerPedId())
    PlayerData = ESX.GetPlayerData()
    local elements = {
        {label = _U('garage_storeditem'), action = 'garage'},
        {label = _U('garage_storeitem'), action = 'store_garage'},
        {label = _U('garage_buyitem'), action = 'buy_vehicle'}
    }

    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle', {
        title    = _U('garage_title'),
        align    = 'top-left',
        elements = elements
    }, function(data, menu)
        if data.current.action == 'buy_vehicle' then
            local shopElements, shopCoords = {}

            if type == 'car' then
                shopCoords = Config.PoliceStations[station].Vehicles[partNum].InsideShop
                local authorizedVehicles = Config.AuthorizedVehicles[PlayerData.job.grade_name]

                if #Config.AuthorizedVehicles.Shared > 0 then
                    for k,vehicle in ipairs(Config.AuthorizedVehicles.Shared) do
                        table.insert(shopElements, {
                            label = ('%s - <span style="color:green;">%s</span>'):format(vehicle.label, _U('shop_item', ESX.Math.GroupDigits(vehicle.price))),
                            name  = vehicle.label,
                            model = vehicle.model,
                            price = vehicle.price,
                            type  = 'car'
                        })
                    end
                end

                if #authorizedVehicles > 0 then
                    for k,vehicle in ipairs(authorizedVehicles) do
                        table.insert(shopElements, {
                            label = ('%s - <span style="color:green;">%s</span>'):format(vehicle.label, _U('shop_item', ESX.Math.GroupDigits(vehicle.price))),
                            name  = vehicle.label,
                            model = vehicle.model,
                            price = vehicle.price,
                            type  = 'car'
                        })
                    end
                else
                    if #Config.AuthorizedVehicles.Shared == 0 then
                        return
                    end
                end
            elseif type == 'helicopter' then
                shopCoords = Config.PoliceStations[station].Helicopters[partNum].InsideShop
                local authorizedHelicopters = Config.AuthorizedHelicopters[PlayerData.job.grade_name]

                if #authorizedHelicopters > 0 then
                    for k,vehicle in ipairs(authorizedHelicopters) do
                        table.insert(shopElements, {
                            label = ('%s - <span style="color:green;">%s</span>'):format(vehicle.label, _U('shop_item', ESX.Math.GroupDigits(vehicle.price))),
                            name  = vehicle.label,
                            model = vehicle.model,
                            price = vehicle.price,
                            livery = vehicle.livery or nil,
                            type  = 'helicopter'
                        })
                    end
                else
                    ESX.ShowNotification(_U('helicopter_notauthorized'))
                    return
                end
            end

            OpenShopMenu(shopElements, playerCoords, shopCoords)
        elseif data.current.action == 'garage' then
            local garage = {}

            ESX.TriggerServerCallback('esx_vehicleshop:retrieveJobVehicles', function(jobVehicles)
                if #jobVehicles > 0 then
                    for k,v in ipairs(jobVehicles) do
                        local props = json.decode(v.vehicle)
                        local vehicleName = GetLabelText(GetDisplayNameFromVehicleModel(props.model))
                        local label = ('%s - <span style="color:darkgoldenrod;">%s</span>: '):format(vehicleName, props.plate)

                        if v.stored then
                            label = label .. ('<span style="color:green;">%s</span>'):format(_U('garage_stored'))
                        else
                            label = label .. ('<span style="color:darkred;">%s</span>'):format(_U('garage_notstored'))
                        end

                        table.insert(garage, {
                            label = label,
                            stored = v.stored,
                            model = props.model,
                            vehicleProps = props
                        })
                    end

                    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_garage', {
                        title    = _U('garage_title'),
                        align    = 'top-left',
                        elements = garage
                    }, function(data2, menu2)
                        if data2.current.stored then
                            local foundSpawn, spawnPoint = GetAvailableVehicleSpawnPoint(station, part, partNum)

                            if foundSpawn then
                                menu2.close()

                                ESX.Game.SpawnVehicle(data2.current.model, spawnPoint.coords, spawnPoint.heading, function(vehicle)
                                    ESX.Game.SetVehicleProperties(vehicle, data2.current.vehicleProps)

                                    TriggerServerEvent('esx_vehicleshop:setJobVehicleState', data2.current.vehicleProps.plate, false)
                                    ESX.ShowNotification(_U('garage_released'))
                                end)
                            end
                        else
                            ESX.ShowNotification(_U('garage_notavailable'))
                        end
                    end, function(data2, menu2)
                        menu2.close()
                    end)
                else
                    ESX.ShowNotification(_U('garage_empty'))
                end
            end, type)
        elseif data.current.action == 'store_garage' then
            StoreNearbyVehicle(playerCoords)
        end
    end, function(data, menu)
        menu.close()
    end)
end

function StoreNearbyVehicle(playerCoords)
    local vehicles, vehiclePlates = ESX.Game.GetVehiclesInArea(playerCoords, 30.0), {}

    if #vehicles > 0 then
        for k,v in ipairs(vehicles) do

            -- Make sure the vehicle we're saving is empty, or else it wont be deleted
            if GetVehicleNumberOfPassengers(v) == 0 and IsVehicleSeatFree(v, -1) then
                table.insert(vehiclePlates, {
                    vehicle = v,
                    plate = ESX.Math.Trim(GetVehicleNumberPlateText(v))
                })
            end
        end
    else
        ESX.ShowNotification(_U('garage_store_nearby'))
        return
    end

    ESX.TriggerServerCallback('esx_policejob:storeNearbyVehicle', function(storeSuccess, foundNum)
        if storeSuccess then
            local vehicleId = vehiclePlates[foundNum]
            local attempts = 0
            ESX.Game.DeleteVehicle(vehicleId.vehicle)
            IsBusy = true

            Citizen.CreateThread(function()
                BeginTextCommandBusyString('STRING')
                AddTextComponentSubstringPlayerName(_U('garage_storing'))
                EndTextCommandBusyString(4)

                while IsBusy do
                    Citizen.Wait(100)
                end

                RemoveLoadingPrompt()
            end)

            -- Workaround for vehicle not deleting when other players are near it.
            while DoesEntityExist(vehicleId.vehicle) do
                Citizen.Wait(500)
                attempts = attempts + 1

                -- Give up
                if attempts > 30 then
                    break
                end

                vehicles = ESX.Game.GetVehiclesInArea(playerCoords, 30.0)
                if #vehicles > 0 then
                    for k,v in ipairs(vehicles) do
                        if ESX.Math.Trim(GetVehicleNumberPlateText(v)) == vehicleId.plate then
                            ESX.Game.DeleteVehicle(v)
                            break
                        end
                    end
                end
            end

            IsBusy = false
            ESX.ShowNotification(_U('garage_has_stored'))
        else
            ESX.ShowNotification(_U('garage_has_notstored'))
        end
    end, vehiclePlates)
end

function GetAvailableVehicleSpawnPoint(station, part, partNum)
    local spawnPoints = Config.PoliceStations[station][part][partNum].SpawnPoints
    local found, foundSpawnPoint = false, nil

    for i=1, #spawnPoints, 1 do
        if ESX.Game.IsSpawnPointClear(spawnPoints[i].coords, spawnPoints[i].radius) then
            found, foundSpawnPoint = true, spawnPoints[i]
            break
        end
    end

    if found then
        return true, foundSpawnPoint
    else
        ESX.ShowNotification(_U('vehicle_blocked'))
        return false
    end
end

function OpenShopMenu(elements, restoreCoords, shopCoords)
    local playerPed = PlayerPedId()
    isInShopMenu = true

    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_shop', {
        title    = _U('vehicleshop_title'),
        align    = 'top-left',
        elements = elements
    }, function(data, menu)
        ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_shop_confirm', {
            title    = _U('vehicleshop_confirm', data.current.name, data.current.price),
            align    = 'top-left',
            elements = {
                {label = _U('confirm_no'), value = 'no'},
                {label = _U('confirm_yes'), value = 'yes'}
        }}, function(data2, menu2)
            if data2.current.value == 'yes' then
                local newPlate = exports['esx_vehicleshop']:GeneratePlate()
                local vehicle  = GetVehiclePedIsIn(playerPed, false)
                local props    = ESX.Game.GetVehicleProperties(vehicle)
                props.plate    = newPlate

                ESX.TriggerServerCallback('esx_policejob:buyJobVehicle', function (bought)
                    if bought then
                        ESX.ShowNotification(_U('vehicleshop_bought', data.current.name, ESX.Math.GroupDigits(data.current.price)))

                        isInShopMenu = false
                        ESX.UI.Menu.CloseAll()
                        DeleteSpawnedVehicles()
                        FreezeEntityPosition(playerPed, false)
                        SetEntityVisible(playerPed, true)

                        ESX.Game.Teleport(playerPed, restoreCoords)
                    else
                        ESX.ShowNotification(_U('vehicleshop_money'))
                        menu2.close()
                    end
                end, props, data.current.type)
            else
                menu2.close()
            end
        end, function(data2, menu2)
            menu2.close()
        end)
    end, function(data, menu)
        isInShopMenu = false
        ESX.UI.Menu.CloseAll()

        DeleteSpawnedVehicles()
        FreezeEntityPosition(playerPed, false)
        SetEntityVisible(playerPed, true)

        ESX.Game.Teleport(playerPed, restoreCoords)
    end, function(data, menu)
        DeleteSpawnedVehicles()
        WaitForVehicleToLoad(data.current.model)

        ESX.Game.SpawnLocalVehicle(data.current.model, shopCoords, 0.0, function(vehicle)
            table.insert(spawnedVehicles, vehicle)
            TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
            FreezeEntityPosition(vehicle, true)
            SetModelAsNoLongerNeeded(data.current.model)

            if data.current.livery then
                SetVehicleModKit(vehicle, 0)
                SetVehicleLivery(vehicle, data.current.livery)
            end
        end)
    end)

    WaitForVehicleToLoad(elements[1].model)
    ESX.Game.SpawnLocalVehicle(elements[1].model, shopCoords, 0.0, function(vehicle)
        table.insert(spawnedVehicles, vehicle)
        TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
        FreezeEntityPosition(vehicle, true)
        SetModelAsNoLongerNeeded(elements[1].model)

        if elements[1].livery then
            SetVehicleModKit(vehicle, 0)
            SetVehicleLivery(vehicle, elements[1].livery)
        end
    end)
end

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)

        if isInShopMenu then
            DisableControlAction(0, 75, true)  -- Disable exit vehicle
            DisableControlAction(27, 75, true) -- Disable exit vehicle
        else
            Citizen.Wait(500)
        end
    end
end)

function DeleteSpawnedVehicles()
    while #spawnedVehicles > 0 do
        local vehicle = spawnedVehicles[1]
        ESX.Game.DeleteVehicle(vehicle)
        table.remove(spawnedVehicles, 1)
    end
end

function WaitForVehicleToLoad(modelHash)
    modelHash = (type(modelHash) == 'number' and modelHash or GetHashKey(modelHash))

    if not HasModelLoaded(modelHash) then
        RequestModel(modelHash)

        BeginTextCommandBusyString('STRING')
        AddTextComponentSubstringPlayerName(_U('vehicleshop_awaiting_model'))
        EndTextCommandBusyString(4)

        while not HasModelLoaded(modelHash) do
            Citizen.Wait(0)
            DisableAllControlActions(0)
        end

        RemoveLoadingPrompt()
    end
end

function OpenPoliceActionsMenu()
    ESX.UI.Menu.CloseAll()

    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'police_actions', {
        title    = 'Polis Etkileşim Menüsü',
        align    = 'top-left',
        elements = {
            {label = _U('citizen_interaction'), value = 'citizen_interaction'},
            {label = _U('vehicle_interaction'), value = 'vehicle_interaction'},
            {label = _U('object_spawner'),      value = 'object_spawner'},
            {label = _U("hapis"),               value = 'jail_menu'}
    }}, function(data, menu)

        if data.current.value == 'jail_menu' then
            TriggerEvent("esx-qalle-jail:openJailMenu")
        end

        if data.current.value == 'citizen_interaction' then
            local elements = {
                {label = _U('id_card'), value = 'identity_card'},
                {label = _U('revive player'),   value = 'revive'},
                {label = _U('search'), value = 'body_search'},
                --{label = _U('handcuff'), value = 'handcuff'},
                {label = 'Kelepçe Tak/Çıkar', value = 'uncuff'},
                {label = _U('drag'), value = 'drag'},
                {label = _U('put_in_vehicle'), value = 'put_in_vehicle'},
                {label = _U('out_the_vehicle'), value = 'out_the_vehicle'},
                {label = _U('fine'), value = 'fine'},
                {label = _U('unpaid_bills'), value = 'unpaid_bills'},
                {label = "Hizmet Cezası",    value = 'communityservice'},
                {label = "Barut Testi",        value = 'gsr_test'}
            }

            if Config.EnableLicenses then
                table.insert(elements, { label = _U('license_check'), value = 'license' })
            end

            ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'citizen_interaction', {
                title    = _U('citizen_interaction'),
                align    = 'top-left',
                elements = elements
            }, function(data2, menu2)
                local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()
                if closestPlayer ~= -1 and closestDistance <= 3.0 then
                    local action = data2.current.value

                    if action == 'revive' then
                    local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()
                    local closestPlayerPed = GetPlayerPed(closestPlayer)
                    local health = GetEntityHealth(closestPlayerPed)
                    if health == 0 then
                        local playerPed = GetPlayerPed(-1)
                        Citizen.CreateThread(function()
                        ESX.ShowNotification(_U('revive_inprogress'))
                        TaskStartScenarioInPlace(playerPed, 'CODE_HUMAN_MEDIC_TEND_TO_DEAD', 0, true)
                        Wait(10000)
                        ClearPedTasks(playerPed)
                            if GetEntityHealth(closestPlayerPed) == 0 then
                            TriggerServerEvent('esx_ambulancejob:revive', GetPlayerServerId(closestPlayer))
                            ESX.ShowNotification(_U('revive_complete'))
                            else
                            ESX.ShowNotification(_U('isdead'))
                            end
                        end)
                    end

                    elseif action == 'identity_card' then
                        OpenIdentityCardMenu(closestPlayer)
                    elseif action == 'body_search' then
                        TriggerServerEvent('esx_policejob:message', GetPlayerServerId(closestPlayer), _U('being_searched'))
                        OpenBodySearchMenu(closestPlayer)
                    elseif action == 'handcuff' then
                        TriggerServerEvent('esx_ruski_areszt:handcuff', GetPlayerServerId(closestPlayer))                                   
                        Citizen.Wait(3200)                                                                                                                                                                                               
                    TriggerServerEvent('esx_policejob:handcuff',  GetPlayerServerId(closestPlayer))
                    elseif action == 'uncuff' then
                        TriggerServerEvent('fizzfau-uncuff:uncuff', GetPlayerServerId(closestPlayer))
                        Citizen.Wait(3600)
                        TriggerServerEvent('esx_policejob:handcuff', GetPlayerServerId(closestPlayer))
                    elseif action == 'drag' then
                        TriggerServerEvent('esx_policejob:drag', GetPlayerServerId(closestPlayer))
                    elseif action == 'put_in_vehicle' then
                        TriggerServerEvent('esx_policejob:putInVehicle', GetPlayerServerId(closestPlayer))
                    elseif action == 'out_the_vehicle' then
                        TriggerServerEvent('esx_policejob:OutVehicle', GetPlayerServerId(closestPlayer))
                    elseif action == 'fine' then
                        OpenFineMenu(closestPlayer)
                    elseif action == 'license' then
                        ShowPlayerLicense(closestPlayer)
                    elseif action == 'unpaid_bills' then
                        OpenUnpaidBillsMenu(closestPlayer)
                    elseif action == 'communityservice' then
                        SendToCommunityService(GetPlayerServerId(closestPlayer))
                    elseif action == 'gsr_test' then
                        TriggerServerEvent('GSR:Status2', GetPlayerServerId(closestPlayer))
                    end
                else
                    ESX.ShowNotification(_U('no_players_nearby'))
                end
            end, function(data2, menu2)
                menu2.close()
            end)
        elseif data.current.value == 'vehicle_interaction' then
            local elements  = {}
            local playerPed = PlayerPedId()
            local vehicle = ESX.Game.GetVehicleInDirection()

            if DoesEntityExist(vehicle) then
                table.insert(elements, {label = _U('vehicle_info'), value = 'vehicle_infos'})
                table.insert(elements, {label = _U('pick_lock'), value = 'hijack_vehicle'})
                table.insert(elements, {label = _U('impound'), value = 'impound'})
            end

            table.insert(elements, {label = _U('search_database'), value = 'search_database'})

            ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_interaction', {
                title    = _U('vehicle_interaction'),
                align    = 'top-left',
                elements = elements
            }, function(data2, menu2)
                local coords  = GetEntityCoords(playerPed)
                vehicle = ESX.Game.GetVehicleInDirection()
                action  = data2.current.value

                if action == 'search_database' then
                    LookupVehicle()
                elseif DoesEntityExist(vehicle) then
                    if action == 'vehicle_infos' then
                        local vehicleData = ESX.Game.GetVehicleProperties(vehicle)
                        OpenVehicleInfosMenu(vehicleData)
                    elseif action == 'hijack_vehicle' then
                        if IsAnyVehicleNearPoint(coords.x, coords.y, coords.z, 3.0) then
                            TaskStartScenarioInPlace(playerPed, 'WORLD_HUMAN_WELDING', 0, true)
                            Citizen.Wait(20000)
                            ClearPedTasksImmediately(playerPed)

                            SetVehicleDoorsLocked(vehicle, 1)
                            SetVehicleDoorsLockedForAllPlayers(vehicle, false)
                            ESX.ShowNotification(_U('vehicle_unlocked'))
                        end
                    elseif action == 'impound' then
                        -- is the script busy?
                        if currentTask.busy then
                            return
                        end

                        ESX.ShowHelpNotification(_U('impound_prompt'))
                        TaskStartScenarioInPlace(playerPed, 'CODE_HUMAN_MEDIC_TEND_TO_DEAD', 0, true)

                        currentTask.busy = true
                        currentTask.task = ESX.SetTimeout(10000, function()
                            ClearPedTasks(playerPed)
                            ImpoundVehicle(vehicle)
                            Citizen.Wait(100) -- sleep the entire script to let stuff sink back to reality
                        end)

                        -- keep track of that vehicle!
                        Citizen.CreateThread(function()
                            while currentTask.busy do
                                Citizen.Wait(1000)

                                vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 3.0, 0, 71)
                                if not DoesEntityExist(vehicle) and currentTask.busy then
                                    ESX.ShowNotification(_U('impound_canceled_moved'))
                                    ESX.ClearTimeout(currentTask.task)
                                    ClearPedTasks(playerPed)
                                    currentTask.busy = false
                                    break
                                end
                            end
                        end)
                    end
                else
                    ESX.ShowNotification(_U('no_vehicles_nearby'))
                end

            end, function(data2, menu2)
                menu2.close()
            end)
        elseif data.current.value == 'object_spawner' then
            ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'citizen_interaction', {
                title    = _U('traffic_interaction'),
                align    = 'top-left',
                elements = {
                    {label = _U('barrier'), model = 'prop_barrier_work05'},
                    {label = _U('spikestrips'), model = 'p_ld_stinger_s'},
                    {label = _U('cone'), model = 'prop_roadcone02a'},
                    {label = _U('box'), model = 'prop_boxpile_07d'}
            }}, function(data2, menu2)
                local playerPed = PlayerPedId()
                local coords    = GetEntityCoords(playerPed)
                local forward   = GetEntityForwardVector(playerPed)
                local x, y, z   = table.unpack(coords + forward * 1.0)

                if data2.current.model == 'prop_roadcone02a' then
                    z = z - 1.0
                end

                ESX.Game.SpawnObject(data2.current.model, {x = x, y = y, z = z}, function(obj)
                    SetEntityHeading(obj, GetEntityHeading(playerPed))
                    PlaceObjectOnGroundProperly(obj)
                end)
            end, function(data2, menu2)
                menu2.close()
            end)
        end
    end, function(data, menu)
        menu.close()
    end)
end

function OpenIdentityCardMenu(player)
    ESX.TriggerServerCallback('esx_policejob:getOtherPlayerData', function(data)
        local elements = {}
        local nameLabel = _U('name', data.name)
        local jobLabel, sexLabel, dobLabel, heightLabel, idLabel

        if data.job.grade_label and  data.job.grade_label ~= '' then
            jobLabel = _U('job', data.job.label .. ' - ' .. data.job.grade_label)
        else
            jobLabel = _U('job', data.job.label)
        end

        if Config.EnableESXIdentity then
            nameLabel = _U('name', data.firstname .. ' ' .. data.lastname)

            if data.sex then
                if string.lower(data.sex) == 'm' then
                    sexLabel = _U('sex', _U('male'))
                else
                    sexLabel = _U('sex', _U('female'))
                end
            else
                sexLabel = _U('sex', _U('unknown'))
            end

            if data.dob then
                dobLabel = _U('dob', data.dob)
            else
                dobLabel = _U('dob', _U('unknown'))
            end

            if data.height then
                heightLabel = _U('height', data.height)
            else
                heightLabel = _U('height', _U('unknown'))
            end

            if data.name then
                idLabel = _U('id', data.name)
            else
                idLabel = _U('id', _U('unknown'))
            end
        end

        local elements = {
            {label = nameLabel},
            {label = jobLabel}
        }

        if Config.EnableESXIdentity then
            table.insert(elements, {label = sexLabel})
            table.insert(elements, {label = dobLabel})
            table.insert(elements, {label = heightLabel})
            table.insert(elements, {label = idLabel})
        end

        if data.drunk then
            table.insert(elements, {label = _U('bac', data.drunk)})
        end

        if data.licenses then
            table.insert(elements, {label = _U('license_label')})

            for i=1, #data.licenses, 1 do
                table.insert(elements, {label = data.licenses[i].label})
            end
        end

        ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'citizen_interaction', {
            title    = _U('citizen_interaction'),
            align    = 'top-left',
            elements = elements
        }, nil, function(data, menu)
            menu.close()
        end)
    end, GetPlayerServerId(player))
end

function OpenBodySearchMenu(player)
    ESX.TriggerServerCallback('esx_policejob:getOtherPlayerData', function(data)
        local elements = {}

        for i=1, #data.accounts, 1 do
            if data.accounts[i].name == 'black_money' and data.accounts[i].money > 0 then
                table.insert(elements, {
                    label    = _U('confiscate_dirty', ESX.Math.Round(data.accounts[i].money)),
                    value    = 'black_money',
                    itemType = 'item_account',
                    amount   = data.accounts[i].money
                })

                break
            end
        end

        table.insert(elements, {label = _U('guns_label')})

        for i=1, #data.weapons, 1 do
            table.insert(elements, {
                label    = _U('confiscate_weapon', ESX.GetWeaponLabel(data.weapons[i].name), data.weapons[i].ammo),
                value    = data.weapons[i].name,
                itemType = 'item_weapon',
                amount   = data.weapons[i].ammo
            })
        end

        table.insert(elements, {label = _U('inventory_label')})

        for i=1, #data.inventory, 1 do
            if data.inventory[i].count > 0 then
                table.insert(elements, {
                    label    = _U('confiscate_inv', data.inventory[i].count, data.inventory[i].label),
                    value    = data.inventory[i].name,
                    itemType = 'item_standard',
                    amount   = data.inventory[i].count
                })
            end
        end

        ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'body_search', {
            title    = _U('search'),
            align    = 'top-left',
            elements = elements
        }, function(data, menu)
            if data.current.value then
                TriggerServerEvent('esx_policejob:confiscatePlayerItem', GetPlayerServerId(player), data.current.itemType, data.current.value, data.current.amount)
                OpenBodySearchMenu(player)
            end
        end, function(data, menu)
            menu.close()
        end)
    end, GetPlayerServerId(player))
end

function OpenFineMenu(player)
    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'fine', {
        title    = _U('fine'),
        align    = 'top-tight',
        elements = {
            {label = _U('traffic_offense'), value = 0},
            {label = _U('minor_offense'),   value = 1},
            {label = _U('average_offense'), value = 2},
            {label = _U('major_offense'),   value = 3}
    }}, function(data, menu)
        OpenFineCategoryMenu(player, data.current.value)
    end, function(data, menu)
        menu.close()
    end)
end

function OpenFineCategoryMenu(player, category)
    ESX.TriggerServerCallback('esx_policejob:getFineList', function(fines)
        local elements = {}

        for k,fine in ipairs(fines) do
            table.insert(elements, {
                label     = ('%s <span style="color:green;">%s</span>'):format(fine.label, _U('armory_item', ESX.Math.GroupDigits(fine.amount))),
                value     = fine.id,
                amount    = fine.amount,
                fineLabel = fine.label
            })
        end

        ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'fine_category', {
            title    = _U('fine'),
            align    = 'top-left',
            elements = elements
        }, function(data, menu)
            menu.close()

            if Config.EnablePlayerManagement then
                TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(player), 'society_police', _U('fine_total', data.current.fineLabel), data.current.amount)
            else
                TriggerServerEvent('esx_billing:sendBill', GetPlayerServerId(player), 'society_police', _U('fine_total', data.current.fineLabel), data.current.amount)
            end

            ESX.SetTimeout(300, function()
                OpenFineCategoryMenu(player, category)
            end)
        end, function(data, menu)
            menu.close()
        end)
    end, category)
end

function LookupVehicle()
    ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'lookup_vehicle',
    {
        title = _U('search_database_title'),
    }, function(data, menu)
        local length = string.len(data.value)
        if data.value == nil or length < 2 or length > 13 then
            ESX.ShowNotification(_U('search_database_error_invalid'))
        else
            ESX.TriggerServerCallback('esx_policejob:getVehicleFromPlate', function(owner, found)
                if found then
                    ESX.ShowNotification(_U('search_database_found', owner))
                else
                    ESX.ShowNotification(_U('search_database_error_not_found'))
                end
            end, data.value)
            menu.close()
        end
    end, function(data, menu)
        menu.close()
    end)
end

function ShowPlayerLicense(player)
    local elements, targetName = {}

    ESX.TriggerServerCallback('esx_policejob:getOtherPlayerData', function(data)
        if data.licenses then
            for i=1, #data.licenses, 1 do
                if data.licenses[i].label and data.licenses[i].type then
                    table.insert(elements, {
                        label = data.licenses[i].label,
                        type = data.licenses[i].type
                    })
                end
            end
        end

        if Config.EnableESXIdentity then
            targetName = data.firstname .. ' ' .. data.lastname
        else
            targetName = data.name
        end

        ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'manage_license', {
            title    = _U('license_revoke'),
            align    = 'top-left',
            elements = elements,
        }, function(data, menu)
            ESX.ShowNotification(_U('licence_you_revoked', data.current.label, targetName))
            TriggerServerEvent('esx_policejob:message', GetPlayerServerId(player), _U('license_revoked', data.current.label))

            TriggerServerEvent('esx_license:removeLicense', GetPlayerServerId(player), data.current.type)

            ESX.SetTimeout(300, function()
                ShowPlayerLicense(player)
            end)
        end, function(data, menu)
            menu.close()
        end)

    end, GetPlayerServerId(player))
end

function OpenUnpaidBillsMenu(player)
    local elements = {}

    ESX.TriggerServerCallback('esx_billing:getTargetBills', function(bills)
        for k,bill in ipairs(bills) do
            table.insert(elements, {
                label = ('%s - <span style="color:red;">%s</span>'):format(bill.label, _U('armory_item', ESX.Math.GroupDigits(bill.amount))),
                billId = bill.id
            })
        end

        ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'billing', {
            title    = _U('unpaid_bills'),
            align    = 'top-left',
            elements = elements
        }, nil, function(data, menu)
            menu.close()
        end)
    end, GetPlayerServerId(player))
end

function OpenVehicleInfosMenu(vehicleData)
    ESX.TriggerServerCallback('esx_policejob:getVehicleInfos', function(retrivedInfo)
        local elements = {{label = _U('plate', retrivedInfo.plate)}}

        if retrivedInfo.owner == nil then
            table.insert(elements, {label = _U('owner_unknown')})
        else
            table.insert(elements, {label = _U('owner', retrivedInfo.owner)})
        end

        ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_infos', {
            title    = _U('vehicle_info'),
            align    = 'top-left',
            elements = elements
        }, nil, function(data, menu)
            menu.close()
        end)
    end, vehicleData.plate)
end

function OpenGetWeaponMenu()
    ESX.TriggerServerCallback('esx_policejob:getArmoryWeapons', function(weapons)
        local elements = {}

        for i=1, #weapons, 1 do
            if weapons[i].count > 0 then
                table.insert(elements, {
                    label = 'x' .. weapons[i].count .. ' ' .. ESX.GetWeaponLabel(weapons[i].name),
                    value = weapons[i].name
                })
            end
        end

        ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'armory_get_weapon', {
            title    = _U('get_weapon_menu'),
            align    = 'top-left',
            elements = elements
        }, function(data, menu)
            menu.close()

            ESX.TriggerServerCallback('esx_policejob:removeArmoryWeapon', function()
                OpenGetWeaponMenu()
            end, data.current.value)
        end, function(data, menu)
            menu.close()
        end)
    end)
end

function OpenPutWeaponMenu()
    local elements   = {}
    local playerPed  = PlayerPedId()
    local weaponList = ESX.GetWeaponList()

    for i=1, #weaponList, 1 do
        local weaponHash = GetHashKey(weaponList[i].name)

        if HasPedGotWeapon(playerPed, weaponHash, false) and weaponList[i].name ~= 'WEAPON_UNARMED' then
            table.insert(elements, {
                label = weaponList[i].label,
                value = weaponList[i].name
            })
        end
    end

    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'armory_put_weapon', {
        title    = _U('put_weapon_menu'),
        align    = 'top-left',
        elements = elements
    }, function(data, menu)
        menu.close()

        ESX.TriggerServerCallback('esx_policejob:addArmoryWeapon', function()
            OpenPutWeaponMenu()
        end, data.current.value, true)
    end, function(data, menu)
        menu.close()
    end)
end

function OpenBuyWeaponsMenu()
    local elements = {}
    local playerPed = PlayerPedId()
    PlayerData = ESX.GetPlayerData()

    for k,v in ipairs(Config.AuthorizedWeapons[PlayerData.job.grade_name]) do
        local weaponNum, weapon = ESX.GetWeapon(v.weapon)
        local components, label = {}
        local hasWeapon = HasPedGotWeapon(playerPed, GetHashKey(v.weapon), false)

        if v.components then
            for i=1, #v.components do
                if v.components[i] then
                    local component = weapon.components[i]
                    local hasComponent = HasPedGotWeaponComponent(playerPed, GetHashKey(v.weapon), component.hash)

                    if hasComponent then
                        label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_owned'))
                    else
                        if v.components[i] > 0 then
                            label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_item', ESX.Math.GroupDigits(v.components[i])))
                        else
                            label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_free'))
                        end
                    end

                    table.insert(components, {
                        label = label,
                        componentLabel = component.label,
                        hash = component.hash,
                        name = component.name,
                        price = v.components[i],
                        hasComponent = hasComponent,
                        componentNum = i
                    })
                end
            end
        end

        if hasWeapon and v.components then
            label = ('%s: <span style="color:green;">></span>'):format(weapon.label)
        elseif hasWeapon and not v.components then
            label = ('%s: <span style="color:green;">%s</span>'):format(weapon.label, _U('armory_owned'))
        else
            if v.price > 0 then
                label = ('%s: <span style="color:green;">%s</span>'):format(weapon.label, _U('armory_item', ESX.Math.GroupDigits(v.price)))
            else
                label = ('%s: <span style="color:green;">%s</span>'):format(weapon.label, _U('armory_free'))
            end
        end

        table.insert(elements, {
            label = label,
            weaponLabel = weapon.label,
            name = weapon.name,
            components = components,
            price = v.price,
            hasWeapon = hasWeapon
        })
    end

    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'armory_buy_weapons', {
        title    = _U('armory_weapontitle'),
        align    = 'top-left',
        elements = elements
    }, function(data, menu)
        if data.current.hasWeapon then
            if #data.current.components > 0 then
                OpenWeaponComponentShop(data.current.components, data.current.name, menu)
            end
        else
            ESX.TriggerServerCallback('esx_policejob:buyWeapon', function(bought)
                if bought then
                    if data.current.price > 0 then
                        ESX.ShowNotification(_U('armory_bought', data.current.weaponLabel, ESX.Math.GroupDigits(data.current.price)))
                    end

                    menu.close()
                    OpenBuyWeaponsMenu()
                else
                    ESX.ShowNotification(_U('armory_money'))
                end
            end, data.current.name, 1)
        end
    end, function(data, menu)
        menu.close()
    end)
end

function OpenWeaponComponentShop(components, weaponName, parentShop)
    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'armory_buy_weapons_components', {
        title    = _U('armory_componenttitle'),
        align    = 'top-left',
        elements = components
    }, function(data, menu)
        if data.current.hasComponent then
            ESX.ShowNotification(_U('armory_hascomponent'))
        else
            ESX.TriggerServerCallback('esx_policejob:buyWeapon', function(bought)
                if bought then
                    if data.current.price > 0 then
                        ESX.ShowNotification(_U('armory_bought', data.current.componentLabel, ESX.Math.GroupDigits(data.current.price)))
                    end

                    menu.close()
                    parentShop.close()
                    OpenBuyWeaponsMenu()
                else
                    ESX.ShowNotification(_U('armory_money'))
                end
            end, weaponName, 2, data.current.componentNum)
        end
    end, function(data, menu)
        menu.close()
    end)
end

function OpenGetStocksMenu()
    ESX.TriggerServerCallback('esx_policejob:getStockItems', function(items)
        local elements = {}

        for i=1, #items, 1 do
            table.insert(elements, {
                label = 'x' .. items[i].count .. ' ' .. items[i].label,
                value = items[i].name
            })
        end

        ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'stocks_menu', {
            title    = _U('police_stock'),
            align    = 'top-left',
            elements = elements
        }, function(data, menu)
            local itemName = data.current.value

            ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'stocks_menu_get_item_count', {
                title = _U('quantity')
            }, function(data2, menu2)
                local count = tonumber(data2.value)

                if count == nil then
                    ESX.ShowNotification(_U('quantity_invalid'))
                else
                    menu2.close()
                    menu.close()
                    TriggerServerEvent('esx_policejob:getStockItem', itemName, count)

                    Citizen.Wait(300)
                    OpenGetStocksMenu()
                end
            end, function(data2, menu2)
                menu2.close()
            end)
        end, function(data, menu)
            menu.close()
        end)
    end)
end

function OpenPutStocksMenu()
    ESX.TriggerServerCallback('esx_policejob:getPlayerInventory', function(inventory)
        local elements = {}

        for i=1, #inventory.items, 1 do
            local item = inventory.items[i]

            if item.count > 0 then
                table.insert(elements, {
                    label = item.label .. ' x' .. item.count,
                    type = 'item_standard',
                    value = item.name
                })
            end
        end

        ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'stocks_menu', {
            title    = _U('inventory'),
            align    = 'top-left',
            elements = elements
        }, function(data, menu)
            local itemName = data.current.value

            ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'stocks_menu_put_item_count', {
                title = _U('quantity')
            }, function(data2, menu2)
                local count = tonumber(data2.value)

                if count == nil then
                    ESX.ShowNotification(_U('quantity_invalid'))
                else
                    menu2.close()
                    menu.close()
                    TriggerServerEvent('esx_policejob:putStockItems', itemName, count)

                    Citizen.Wait(300)
                    OpenPutStocksMenu()
                end
            end, function(data2, menu2)
                menu2.close()
            end)
        end, function(data, menu)
            menu.close()
        end)
    end)
end

RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
    PlayerData.job = job

    Citizen.Wait(5000)
    TriggerServerEvent('esx_policejob:forceBlip')
end)

RegisterNetEvent('esx_phone:loaded')
AddEventHandler('esx_phone:loaded', function(phoneNumber, contacts)
    local specialContact = {
        name       = _U('phone_police'),
        number     = 'police',
        base64Icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoV2luZG93cykiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NDFGQTJDRkI0QUJCMTFFN0JBNkQ5OENBMUI4QUEzM0YiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NDFGQTJDRkM0QUJCMTFFN0JBNkQ5OENBMUI4QUEzM0YiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo0MUZBMkNGOTRBQkIxMUU3QkE2RDk4Q0ExQjhBQTMzRiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo0MUZBMkNGQTRBQkIxMUU3QkE2RDk4Q0ExQjhBQTMzRiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PoW66EYAAAjGSURBVHjapJcLcFTVGcd/u3cfSXaTLEk2j80TCI8ECI9ABCyoiBqhBVQqVG2ppVKBQqUVgUl5OU7HKqNOHUHU0oHamZZWoGkVS6cWAR2JPJuAQBPy2ISEvLN57+v2u2E33e4k6Ngz85+9d++95/zP9/h/39GpqsqiRYsIGz8QZAq28/8PRfC+4HT4fMXFxeiH+GC54NeCbYLLATLpYe/ECx4VnBTsF0wWhM6lXY8VbBE0Ch4IzLcpfDFD2P1TgrdC7nMCZLRxQ9AkiAkQCn77DcH3BC2COoFRkCSIG2JzLwqiQi0RSmCD4JXbmNKh0+kc/X19tLtc9Ll9sk9ZS1yoU71YIk3xsbEx8QaDEc2ttxmaJSKC1ggSKBK8MKwTFQVXRzs3WzpJGjmZgvxcMpMtWIwqsjztvSrlzjYul56jp+46qSmJmMwR+P3+4aZ8TtCprRkk0DvUW7JjmV6lsqoKW/pU1q9YQOE4Nxkx4ladE7zd8ivuVmJQfXZKW5dx5EwPRw4fxNx2g5SUVLw+33AkzoRaQDP9SkFu6OKqz0uF8yaz7vsOL6ycQVLkcSg/BlWNsjuFoKE1knqDSl5aNnmPLmThrE0UvXqQqvJPyMrMGorEHwQfEha57/3P7mXS684GFjy8kreLppPUuBXfyd/ibeoS2kb0mWPANhJdYjb61AxUvx5PdT3+4y+Tb3mTd19ZSebE+VTXVGNQlHAC7w4VhH8TbA36vKq6ilnzlvPSunHw6Trc7XpZ14AyfgYeyz18crGN1Alz6e3qwNNQSv4dZox1h/BW9+O7eIaEsVv41Y4XeHJDG83Nl4mLTwzGhJYtx0PzNTjOB9KMTlc7Nkcem39YAGU7cbeBKVLMPGMVf296nMd2VbBq1wmizHoqqm/wrS1/Zf0+N19YN2PIu1fcIda4Vk66Zx/rVi+jo9eIX9wZGGcFXUMR6BHUa76/2ezioYcXMtpyAl91DSaTfDxlJbtLprHm2ecpObqPuTPzSNV9yKz4a4zJSuLo71/j8Q17ON69EmXiPIlNMe6FoyzOqWPW/MU03Lw5EFcyKghTrNDh7+/vw545mcJcWbTiGKpRdGPMXbx90sGmDaux6sXk+kimjU+BjnMkx3kYP34cXrFuZ+3nrHi6iDMt92JITcPjk3R3naRwZhpuNSqoD93DKaFVU7j2dhcF8+YzNlpErbIBTVh8toVccbaysPB+4pMcuPw25kwSsau7BIlmHpy3guaOPtISYyi/UkaJM5Lpc5agq5Xkcl6gIHkmqaMn0dtylcjIyPThCNyhaXyfR2W0I1our0v6qBii07ih5rDtGSOxNVdk1y4R2SR8jR/g7hQD9l1jUeY/WLJB5m39AlZN4GZyIQ1fFJNsEgt0duBIc5GRkcZF53mNwIzhXPDgQPoZIkiMkbTxtstDMVnmFA4cOsbz2/aKjSQjev4Mp9ZAg+hIpFhB3EH5Yal16+X+Kq3dGfxkzRY+KauBjBzREvGN0kNCTARu94AejBLMHorAQ7cEQMGs2cXvkWshYLDi6e9l728O8P1XW6hKeB2yv42q18tjj+iFTGoSi+X9jJM9RTxS9E+OHT0krhNiZqlbqraoT7RAU5bBGrEknEBhgJks7KXbLS8qERI0ErVqF/Y4K6NHZfLZB+/wzJvncacvFd91oXO3o/O40MfZKJOKu/rne+mRQByXM4lYreb1tUnkizVVA/0SpfpbWaCNBeEE5gb/UH19NLqEgDF+oNDQWcn41Cj0EXFEWqzkOIyYekslFkThsvMxpIyE2hIc6lXGZ6cPyK7Nnk5OipixRdxgUESAYmhq68VsGgy5CYKCUAJTg0+izApXne3CJFmUTwg4L3FProFxU+6krqmXu3MskkhSD2av41jLdzlnfFrSdCZxyqfMnppN6ZUa7pwt0h3fiK9DCt4IO9e7YqisvI7VYgmNv7mhBKKD/9psNi5dOMv5ZjukjsLdr0ffWsyTi6eSlfcA+dmiVyOXs+/sHNZu3M6PdxzgVO9GmDSHsSNqmTz/R6y6Xxqma4fwaS5Mn85n1ZE0Vl3CHBER3lUNEhiURpPJRFdTOcVnpUJnPIhR7cZXfoH5UYc5+E4RzRH3sfSnl9m2dSMjE+Tz9msse+o5dr7UwcQ5T3HwlWUkNuzG3dKFSTbsNs7m/Y8vExOlC29UWkMJlAxKoRQMR3IC7x85zOn6fHS50+U/2Untx2R1voinu5no+DQmz7yPXmMKZnsu0wrm0Oe3YhOVHdm8A09dBQYhTv4T7C+xUPrZh8Qn2MMr4qcDSRfoirWgKAvtgOpv1JI8Zi77X15G7L+fxeOUOiUFxZiULD5fSlNzNM62W+k1yq5gjajGX/ZHvOIyxd+Fkj+P092rWP/si0Qr7VisMaEWuCiYonXFwbAUTWWPYLV245NITnGkUXnpI9butLJn2y6iba+hlp7C09qBcvoN7FYL9mhxo1/y/LoEXK8Pv6qIC8WbBY/xr9YlPLf9dZT+OqKTUwfmDBm/GOw7ws4FWpuUP2gJEZvKqmocuXPZuWYJMzKuSsH+SNwh3bo0p6hao6HeEqwYEZ2M6aKWd3PwTCy7du/D0F1DsmzE6/WGLr5LsDF4LggnYBacCOboQLHQ3FFfR58SR+HCR1iQH8ukhA5s5o5AYZMwUqOp74nl8xvRHDlRTsnxYpJsUjtsceHt2C8Fm0MPJrphTkZvBc4It9RKLOFx91Pf0Igu0k7W2MmkOewS2QYJUJVWVz9VNbXUVVwkyuAmKTFJayrDo/4Jwe/CT0aGYTrWVYEeUfsgXssMRcpyenraQJa0VX9O3ZU+Ma1fax4xGxUsUVFkOUbcama1hf+7+LmA9juHWshwmwOE1iMmCFYEzg1jtIm1BaxW6wCGGoFdewPfvyE4ertTiv4rHC73B855dwp2a23bbd4tC1hvhOCbX7b4VyUQKhxrtSOaYKngasizvwi0RmOS4O1QZf2yYfiaR+73AvhTQEVf+rpn9/8IMAChKDrDzfsdIQAAAABJRU5ErkJggg=='
    }

    TriggerEvent('esx_phone:addSpecialContact', specialContact.name, specialContact.number, specialContact.base64Icon)
end)

-- don't show dispatches if the player isn't in service
AddEventHandler('esx_phone:cancelMessage', function(dispatchNumber)
    if PlayerData.job and PlayerData.job.name == 'police' and PlayerData.job.name == dispatchNumber then
        -- if esx_service is enabled
        if Config.MaxInService ~= -1 and not playerInService then
            CancelEvent()
        end
    end
end)

AddEventHandler('esx_policejob:hasEnteredMarker', function(station, part, partNum)
    if part == 'Cloakroom' then
        CurrentAction     = 'menu_cloakroom'
        CurrentActionMsg  = _U('open_cloackroom')
        CurrentActionData = {}
    elseif part == 'Armory' then
        CurrentAction     = 'menu_armory'
        CurrentActionMsg  = _U('open_armory')
        CurrentActionData = {station = station}
    elseif part == 'Vehicles' then
        CurrentAction     = 'menu_vehicle_spawner'
        CurrentActionMsg  = _U('garage_prompt')
        CurrentActionData = {station = station, part = part, partNum = partNum}
    elseif part == 'Helicopters' then
        CurrentAction     = 'Helicopters'
        CurrentActionMsg  = _U('helicopter_prompt')
        CurrentActionData = {station = station, part = part, partNum = partNum}
    elseif part == 'BossActions' then
        CurrentAction     = 'menu_boss_actions'
        CurrentActionMsg  = _U('open_bossmenu')
        CurrentActionData = {}
    end
end)

AddEventHandler('esx_policejob:hasExitedMarker', function(station, part, partNum)
    if not isInShopMenu then
        ESX.UI.Menu.CloseAll()
    end

    CurrentAction = nil
end)

AddEventHandler('esx_policejob:hasEnteredEntityZone', function(entity)
    local playerPed = PlayerPedId()

    if PlayerData.job and PlayerData.job.name == 'police' and IsPedOnFoot(playerPed) then
        CurrentAction     = 'remove_entity'
        CurrentActionMsg  = _U('remove_prop')
        CurrentActionData = {entity = entity}
    end

    if GetEntityModel(entity) == GetHashKey('p_ld_stinger_s') then
        local playerPed = PlayerPedId()
        local coords    = GetEntityCoords(playerPed)

        if IsPedInAnyVehicle(playerPed, false) then
            local vehicle = GetVehiclePedIsIn(playerPed)

            for i=0, 7, 1 do
                SetVehicleTyreBurst(vehicle, i, true, 1000)
            end
        end
    end
end)

AddEventHandler('esx_policejob:hasExitedEntityZone', function(entity)
    if CurrentAction == 'remove_entity' then
        CurrentAction = nil
    end
end)


ESX = nil
cuffed = false

Citizen.CreateThread(function()
    while ESX == nil do
        TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
        Citizen.Wait(0)
    end
    while ESX.GetPlayerData().job == nil do
        Citizen.Wait(10)
    end
    ESX.PlayerData = ESX.GetPlayerData()
end)

RegisterNetEvent('esx_policejob:getarrested')
AddEventHandler('esx_policejob:getarrested', function(playerheading, playercoords, playerlocation)
    playerPed = GetPlayerPed(-1)
    SetCurrentPedWeapon(playerPed, GetHashKey('WEAPON_UNARMED'), true) -- unarm player
    local x, y, z   = table.unpack(playercoords + playerlocation * 1.0)
    SetEntityCoords(GetPlayerPed(-1), x, y, z)
    SetEntityHeading(GetPlayerPed(-1), playerheading)
    Citizen.Wait(250)
    loadanimdict('mp_arrest_paired')
    TaskPlayAnim(GetPlayerPed(-1), 'mp_arrest_paired', 'crook_p2_back_left', 8.0, -8, 3750 , 2, 0, 0, 0, 0)
    Citizen.Wait(3760)
    cuffed = true
    loadanimdict('mp_arresting')
    TaskPlayAnim(GetPlayerPed(-1), 'mp_arresting', 'idle', 8.0, -8, -1, 49, 0.0, false, false, false)
end)

RegisterNetEvent('esx_policejob:doarrested')
AddEventHandler('esx_policejob:doarrested', function()
    Citizen.Wait(250)
    loadanimdict('mp_arrest_paired')
    TaskPlayAnim(GetPlayerPed(-1), 'mp_arrest_paired', 'cop_p2_back_left', 8.0, -8,3750, 2, 0, 0, 0, 0)
    Citizen.Wait(3000)

end)

RegisterNetEvent('esx_policejob:douncuffing')
AddEventHandler('esx_policejob:douncuffing', function()
    Citizen.Wait(250)
    loadanimdict('mp_arresting')
    TaskPlayAnim(GetPlayerPed(-1), 'mp_arresting', 'a_uncuff', 8.0, -8,-1, 2, 0, 0, 0, 0)
    Citizen.Wait(5500)
    ClearPedTasks(GetPlayerPed(-1))
end)

RegisterNetEvent('esx_policejob:getuncuffed')
AddEventHandler('esx_policejob:getuncuffed', function(playerheading, playercoords, playerlocation)
    local x, y, z   = table.unpack(playercoords + playerlocation * 1.0)
    SetEntityCoords(GetPlayerPed(-1), x, y, z)
    SetEntityHeading(GetPlayerPed(-1), playerheading)
    Citizen.Wait(250)
    loadanimdict('mp_arresting')
    TaskPlayAnim(GetPlayerPed(-1), 'mp_arresting', 'b_uncuff', 8.0, -8,-1, 2, 0, 0, 0, 0)
    Citizen.Wait(5500)
    cuffed = false
    ClearPedTasks(GetPlayerPed(-1))
end)

RegisterCommand('cuff', function()
    local target, distance = ESX.Game.GetClosestPlayer()
    playerheading = GetEntityHeading(GetPlayerPed(-1))
    playerlocation = GetEntityForwardVector(PlayerPedId())
    playerCoords = GetEntityCoords(GetPlayerPed(-1))
    local target_id = GetPlayerServerId(target)
    if distance <= 2.0 then
        TriggerServerEvent('esx_policejob:requestarrest', target_id, playerheading, playerCoords, playerlocation)
    else
        ESX.ShowNotification('Not Close Enough')
    end
end)

RegisterCommand('uncuff', function()
    local target, distance = ESX.Game.GetClosestPlayer()
    playerheading = GetEntityHeading(GetPlayerPed(-1))
    playerlocation = GetEntityForwardVector(PlayerPedId())
    playerCoords = GetEntityCoords(GetPlayerPed(-1))
    local target_id = GetPlayerServerId(target)
    TriggerServerEvent('esx_policejob:requestrelease', target_id, playerheading, playerCoords, playerlocation)
end)

function loadanimdict(dictname)
    if not HasAnimDictLoaded(dictname) then
        RequestAnimDict(dictname)
        while not HasAnimDictLoaded(dictname) do
            Citizen.Wait(1)
        end
    end
end

RegisterNetEvent('esx_policejob:handcuff')
AddEventHandler('esx_policejob:handcuff', function()
    IsHandcuffed    = not IsHandcuffed
    local playerPed = PlayerPedId()

    Citizen.CreateThread(function()
        if IsHandcuffed then

            RequestAnimDict('mp_arresting')
            while not HasAnimDictLoaded('mp_arresting') do
                Citizen.Wait(100)
            end
            
            --TaskPlayAnim(playerPed, 'mp_arresting', 'idle', 8.0, -8, -1, 49, 0, 0, 0, 0)
            --SetEnableHandcuffs(playerPed, true)
            --DisablePlayerFiring(playerPed, true)
            --SetCurrentPedWeapon(playerPed, GetHashKey('WEAPON_UNARMED'), true) -- unarm player
            --SetPedCanPlayGestureAnims(playerPed, false)
            --FreezeEntityPosition(playerPed, true)
            --DisplayRadar(false)

            --if Config.EnableHandcuffTimer then
            --    if handcuffTimer.active then
            --        ESX.ClearTimeout(handcuffTimer.task)
            --    end

            --    StartHandcuffTimer()
            --end
        else
            if Config.EnableHandcuffTimer and handcuffTimer.active then
                ESX.ClearTimeout(handcuffTimer.task)
            end

            ClearPedSecondaryTask(playerPed)
            SetEnableHandcuffs(playerPed, false)
            --DisablePlayerFiring(playerPed, false)
            --SetPedCanPlayGestureAnims(playerPed, true)
            --FreezeEntityPosition(playerPed, false)
            --DisplayRadar(true)
        end
    end)
end)

RegisterNetEvent('esx_policejob:unrestrain')
AddEventHandler('esx_policejob:unrestrain', function()
    if IsHandcuffed then
        local playerPed = PlayerPedId()
        IsHandcuffed = false

        ClearPedSecondaryTask(playerPed)
        SetEnableHandcuffs(playerPed, false)
        DisablePlayerFiring(playerPed, false)
        SetPedCanPlayGestureAnims(playerPed, true)
        FreezeEntityPosition(playerPed, false)
        DisplayRadar(true)

        -- end timer
        if Config.EnableHandcuffTimer and handcuffTimer.active then
            ESX.ClearTimeout(handcuffTimer.task)
        end
    end
end)

RegisterNetEvent('esx_policejob:drag')
AddEventHandler('esx_policejob:drag', function(copId)
    if not IsHandcuffed then
        return
    end

    dragStatus.isDragged = not dragStatus.isDragged
    dragStatus.CopId = copId
end)

Citizen.CreateThread(function()
    local playerPed
    local targetPed

    while true do
        Citizen.Wait(1)

        if IsHandcuffed then
            playerPed = PlayerPedId()

            if dragStatus.isDragged then
                targetPed = GetPlayerPed(GetPlayerFromServerId(dragStatus.CopId))

                -- undrag if target is in an vehicle
                if not IsPedSittingInAnyVehicle(targetPed) then
                    AttachEntityToEntity(playerPed, targetPed, 11816, 0.54, 0.54, 0.0, 0.0, 0.0, 0.0, false, false, false, false, 2, true)
                else
                    dragStatus.isDragged = false
                    DetachEntity(playerPed, true, false)
                end

                if IsPedDeadOrDying(targetPed, true) then
                    dragStatus.isDragged = false
                    DetachEntity(playerPed, true, false)
                end

            else
                DetachEntity(playerPed, true, false)
            end
        else
            Citizen.Wait(500)
        end
    end
end)

RegisterNetEvent('esx_policejob:putInVehicle')
AddEventHandler('esx_policejob:putInVehicle', function()
    local playerPed = PlayerPedId()
    local coords = GetEntityCoords(playerPed)

    if not IsHandcuffed then
        return
    end

    if IsAnyVehicleNearPoint(coords, 5.0) then
        local vehicle = GetClosestVehicle(coords, 5.0, 0, 71)

        if DoesEntityExist(vehicle) then
            local maxSeats, freeSeat = GetVehicleMaxNumberOfPassengers(vehicle)

            for i=maxSeats - 1, 0, -1 do
                if IsVehicleSeatFree(vehicle, i) then
                    freeSeat = i
                    break
                end
            end

            if freeSeat then
                TaskWarpPedIntoVehicle(playerPed, vehicle, freeSeat)
                dragStatus.isDragged = false
            end
        end
    end
end)

RegisterNetEvent('esx_policejob:OutVehicle')
AddEventHandler('esx_policejob:OutVehicle', function()
    local playerPed = PlayerPedId()

    if not IsPedSittingInAnyVehicle(playerPed) then
        return
    end

    local vehicle = GetVehiclePedIsIn(playerPed, false)
    TaskLeaveVehicle(playerPed, vehicle, 16)
end)

-- Handcuff
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        local playerPed = PlayerPedId()

        if IsHandcuffed then
            DisableControlAction(0, 2, true)    -- Disable tilt
            DisableControlAction(0, 24, true)   -- Attack
            DisableControlAction(0, 257, true)  -- Attack 2
            DisableControlAction(0, 25, true)   -- Aim
            DisableControlAction(0, 263, true)  -- Melee Attack 1

            DisableControlAction(0, 45, true)   -- Reload
            DisableControlAction(0, 44, true)   -- Cover
            DisableControlAction(0, 37, true)   -- Select Weapon
            DisableControlAction(0, 23, true)   -- Also 'enter'?

            DisableControlAction(0, 288,  true) -- Disable phone
            DisableControlAction(0, 289, true)  -- Inventory
            DisableControlAction(0, 170, true)  -- Animations
            DisableControlAction(0, 167, true)  -- Job

            DisableControlAction(0, 0, true)    -- Disable changing view
            DisableControlAction(0, 26, true)   -- Disable looking behind
            DisableControlAction(0, 73, true)   -- Disable clearing animation
            DisableControlAction(2, 199, true)  -- Disable pause screen

            DisableControlAction(0, 59, true)   -- Disable steering in vehicle
            DisableControlAction(0, 71, true)   -- Disable driving forward in vehicle
            DisableControlAction(0, 72, true)   -- Disable reversing in vehicle

            DisableControlAction(2, 36, true)   -- Disable going stealth

            DisableControlAction(0, 47, true)   -- Disable weapon
            DisableControlAction(0, 264, true)  -- Disable melee
            DisableControlAction(0, 257, true)  -- Disable melee
            DisableControlAction(0, 140, true)  -- Disable melee
            DisableControlAction(0, 141, true)  -- Disable melee
            DisableControlAction(0, 142, true)  -- Disable melee
            DisableControlAction(0, 143, true)  -- Disable melee
            DisableControlAction(0, 75, true)   -- Disable exit vehicle
            DisableControlAction(27, 75, true)  -- Disable exit vehicle

            if IsEntityPlayingAnim(playerPed, 'mp_arresting', 'idle', 3) ~= 1 then
                ESX.Streaming.RequestAnimDict('mp_arresting', function()
                    TaskPlayAnim(playerPed, 'mp_arresting', 'idle', 8.0, -8, -1, 49, 0.0, false, false, false)
                end)
            end
        else
            Citizen.Wait(500)
        end
    end
end)

-- Create blips
Citizen.CreateThread(function()

    for k,v in pairs(Config.PoliceStations) do
        local blip = AddBlipForCoord(v.Blip.Coords)

        SetBlipSprite (blip, v.Blip.Sprite)
        SetBlipDisplay(blip, v.Blip.Display)
        SetBlipScale  (blip, v.Blip.Scale)
        SetBlipAsShortRange(blip, true)

        BeginTextCommandSetBlipName('STRING')
        AddTextComponentString(_U('map_blip'))
        EndTextCommandSetBlipName(blip)
    end

end)

-- Display markers
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)

        if PlayerData.job and PlayerData.job.name == 'police' then

            local playerPed = PlayerPedId()
            local coords    = GetEntityCoords(playerPed)
            local isInMarker, hasExited, letSleep = false, false, true
            local currentStation, currentPart, currentPartNum

            for k,v in pairs(Config.PoliceStations) do

                for i=1, #v.Cloakrooms, 1 do
                    local distance = GetDistanceBetweenCoords(coords, v.Cloakrooms[i], true)

                    if distance < Config.DrawDistance then
                        DrawMarker(20, v.Cloakrooms[i], 0.0, 0.0, 0.0, 0, 0.0, 0.0, 1.0, 1.0, 1.0, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, true, false, false, false)
                        letSleep = false
                    end

                    if distance < Config.MarkerSize.x then
                        isInMarker, currentStation, currentPart, currentPartNum = true, k, 'Cloakroom', i
                    end
                end

                for i=1, #v.Armories, 1 do
                    local distance = GetDistanceBetweenCoords(coords, v.Armories[i], true)

                    if distance < Config.DrawDistance then
                        DrawMarker(21, v.Armories[i], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, true, false, false, false)
                        letSleep = false
                    end

                    if distance < Config.MarkerSize.x then
                        isInMarker, currentStation, currentPart, currentPartNum = true, k, 'Armory', i
                    end
                end

                for i=1, #v.Vehicles, 1 do
                    local distance = GetDistanceBetweenCoords(coords, v.Vehicles[i].Spawner, true)

                    if distance < Config.DrawDistance then
                        DrawMarker(36, v.Vehicles[i].Spawner, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, true, false, false, false)
                        letSleep = false
                    end

                    if distance < Config.MarkerSize.x then
                        isInMarker, currentStation, currentPart, currentPartNum = true, k, 'Vehicles', i
                    end
                end

                for i=1, #v.Helicopters, 1 do
                    local distance =  GetDistanceBetweenCoords(coords, v.Helicopters[i].Spawner, true)

                    if distance < Config.DrawDistance then
                        DrawMarker(34, v.Helicopters[i].Spawner, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, true, false, false, false)
                        letSleep = false
                    end

                    if distance < Config.MarkerSize.x then
                        isInMarker, currentStation, currentPart, currentPartNum = true, k, 'Helicopters', i
                    end
                end

                if Config.EnablePlayerManagement and PlayerData.job.grade_name == 'boss' then
                    for i=1, #v.BossActions, 1 do
                        local distance = GetDistanceBetweenCoords(coords, v.BossActions[i], true)

                        if distance < Config.DrawDistance then
                            DrawMarker(22, v.BossActions[i], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, true, false, false, false)
                            letSleep = false
                        end

                        if distance < Config.MarkerSize.x then
                            isInMarker, currentStation, currentPart, currentPartNum = true, k, 'BossActions', i
                        end
                    end
                end
            end

            if isInMarker and not HasAlreadyEnteredMarker or (isInMarker and (LastStation ~= currentStation or LastPart ~= currentPart or LastPartNum ~= currentPartNum)) then
                if
                    (LastStation and LastPart and LastPartNum) and
                    (LastStation ~= currentStation or LastPart ~= currentPart or LastPartNum ~= currentPartNum)
                then
                    TriggerEvent('esx_policejob:hasExitedMarker', LastStation, LastPart, LastPartNum)
                    hasExited = true
                end

                HasAlreadyEnteredMarker = true
                LastStation             = currentStation
                LastPart                = currentPart
                LastPartNum             = currentPartNum

                TriggerEvent('esx_policejob:hasEnteredMarker', currentStation, currentPart, currentPartNum)
            end

            if not hasExited and not isInMarker and HasAlreadyEnteredMarker then
                HasAlreadyEnteredMarker = false
                TriggerEvent('esx_policejob:hasExitedMarker', LastStation, LastPart, LastPartNum)
            end

            if letSleep then
                Citizen.Wait(500)
            end

        else
            Citizen.Wait(500)
        end
    end
end)

-- Enter / Exit entity zone events
Citizen.CreateThread(function()
    local trackedEntities = {
        'prop_roadcone02a',
        'prop_barrier_work05',
        'p_ld_stinger_s',
        'prop_boxpile_07d',
        'hei_prop_cash_crate_half_full'
    }

    while true do
        Citizen.Wait(500)

        local playerPed = PlayerPedId()
        local coords    = GetEntityCoords(playerPed)

        local closestDistance = -1
        local closestEntity   = nil

        for i=1, #trackedEntities, 1 do
            local object = GetClosestObjectOfType(coords, 3.0, GetHashKey(trackedEntities[i]), false, false, false)

            if DoesEntityExist(object) then
                local objCoords = GetEntityCoords(object)
                local distance  = GetDistanceBetweenCoords(coords, objCoords, true)

                if closestDistance == -1 or closestDistance > distance then
                    closestDistance = distance
                    closestEntity   = object
                end
            end
        end

        if closestDistance ~= -1 and closestDistance <= 3.0 then
            if LastEntity ~= closestEntity then
                TriggerEvent('esx_policejob:hasEnteredEntityZone', closestEntity)
                LastEntity = closestEntity
            end
        else
            if LastEntity then
                TriggerEvent('esx_policejob:hasExitedEntityZone', LastEntity)
                LastEntity = nil
            end
        end
    end
end)

-- Key Controls
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)

        if CurrentAction then
            ESX.ShowHelpNotification(CurrentActionMsg)

            if IsControlJustReleased(0, 38) and PlayerData.job and PlayerData.job.name == 'police' then

                if CurrentAction == 'menu_cloakroom' then
                    OpenCloakroomMenu()
                elseif CurrentAction == 'menu_armory' then
                    if Config.MaxInService == -1 then
                        OpenArmoryMenu(CurrentActionData.station)
                    elseif playerInService then
                        OpenArmoryMenu(CurrentActionData.station)
                    else
                        ESX.ShowNotification(_U('service_not'))
                    end
                elseif CurrentAction == 'menu_vehicle_spawner' then
                    if Config.MaxInService == -1 then
                        OpenVehicleSpawnerMenu('car', CurrentActionData.station, CurrentActionData.part, CurrentActionData.partNum)
                    elseif playerInService then
                        OpenVehicleSpawnerMenu('car', CurrentActionData.station, CurrentActionData.part, CurrentActionData.partNum)
                    else
                        ESX.ShowNotification(_U('service_not'))
                    end
                elseif CurrentAction == 'Helicopters' then
                    if Config.MaxInService == -1 then
                        OpenVehicleSpawnerMenu('helicopter', CurrentActionData.station, CurrentActionData.part, CurrentActionData.partNum)
                    elseif playerInService then
                        OpenVehicleSpawnerMenu('helicopter', CurrentActionData.station, CurrentActionData.part, CurrentActionData.partNum)
                    else
                        ESX.ShowNotification(_U('service_not'))
                    end
                elseif CurrentAction == 'delete_vehicle' then
                    ESX.Game.DeleteVehicle(CurrentActionData.vehicle)
                elseif CurrentAction == 'menu_boss_actions' then
                    ESX.UI.Menu.CloseAll()
                    TriggerEvent('esx_society:openBossMenu', 'police', function(data, menu)
                        menu.close()

                        CurrentAction     = 'menu_boss_actions'
                        CurrentActionMsg  = _U('open_bossmenu')
                        CurrentActionData = {}
                    end, { wash = false }) -- disable washing money
                elseif CurrentAction == 'remove_entity' then
                    DeleteEntity(CurrentActionData.entity)
                end

                CurrentAction = nil
            end
        end -- CurrentAction end

        if IsControlJustReleased(0, 167) and not isDead and PlayerData.job and PlayerData.job.name == 'police' and not ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'police_actions') then
            if Config.MaxInService == -1 then
                OpenPoliceActionsMenu()
            elseif playerInService then
                OpenPoliceActionsMenu()
            else
                ESX.ShowNotification(_U('service_not'))
            end
        end

        if IsControlJustReleased(0, 38) and currentTask.busy then
            ESX.ShowNotification(_U('impound_canceled'))
            ESX.ClearTimeout(currentTask.task)
            ClearPedTasks(PlayerPedId())

            currentTask.busy = false
        end
    end
end)

-- Create blip for colleagues
function createBlip(id)
    local ped = GetPlayerPed(id)
    local blip = GetBlipFromEntity(ped)

    if not DoesBlipExist(blip) then -- Add blip and create head display on player
        blip = AddBlipForEntity(ped)
        SetBlipSprite(blip, 1)
        SetBlipColour(blip,68)
        ShowHeadingIndicatorOnBlip(blip, true) -- Player Blip indicator
        SetBlipRotation(blip, math.ceil(GetEntityHeading(ped))) -- update rotation
        SetBlipNameToPlayerName(blip, id) -- update blip name
        SetBlipScale(blip, 0.85) -- set scale
        SetBlipAsShortRange(blip, true)

        table.insert(blipsCops, blip) -- add blip to array so we can remove it later
    end
end

function createBlip2(id)
    local ped = GetPlayerPed(id)
    local blip = GetBlipFromEntity(ped)

    if not DoesBlipExist(blip) then
        blip = AddBlipForEntity(ped)
        SetBlipSprite(blip, 1)
        SetBlipColour(blip,75)
        ShowHeadingIndicatorOnBlip(blip, true)
        SetBlipRotation(blip, math.ceil(GetEntityHeading(ped)))
        SetBlipNameToPlayerName(blip, id)
        SetBlipScale(blip, 0.85)
        SetBlipAsShortRange(blip, true)
      
        table.insert(blipsCops, blip)
    end
end

RegisterNetEvent('esx_policejob:updateBlip')
AddEventHandler('esx_policejob:updateBlip', function()

    -- Refresh all blips
    for k, existingBlip in pairs(blipsCops) do
        RemoveBlip(existingBlip)
    end

    -- Clean the blip table
    blipsCops = {}

    -- Enable blip?
    if Config.MaxInService ~= -1 and not playerInService then
        return
    end

    if not Config.EnableJobBlip then
        return
    end

    -- Is the player a cop? In that case show all the blips for other cops
    if PlayerData.job and PlayerData.job.name == 'police' then
        ESX.TriggerServerCallback('esx_society:getOnlinePlayers', function(players)
            for i=1, #players, 1 do
                if players[i].job.name == 'police' then
                    local id = GetPlayerFromServerId(players[i].source)
                    if NetworkIsPlayerActive(id) and GetPlayerPed(id) ~= PlayerPedId() then
                        createBlip(id)
                    end
                end
            end
        end)
    end

    if PlayerData.job and PlayerData.job.name == 'police' then
        ESX.TriggerServerCallback('esx_society:getOnlinePlayers', function(players)
            for i=1, #players, 1 do
                if players[i].job.name == 'ambulance' then
                    local id = GetPlayerFromServerId(players[i].source)
                    if NetworkIsPlayerActive(id) and GetPlayerPed(id) ~= PlayerPedId() then
                        createBlip2(id)
                    end
                end
            end
        end)
    end

end)

AddEventHandler('playerSpawned', function(spawn)
    isDead = false
    TriggerEvent('esx_policejob:unrestrain')

    if not hasAlreadyJoined then
        TriggerServerEvent('esx_policejob:spawned')
    end
    hasAlreadyJoined = true
end)

AddEventHandler('esx:onPlayerDeath', function(data)
    isDead = false
end)

AddEventHandler('onResourceStop', function(resource)
    if resource == GetCurrentResourceName() then
        TriggerEvent('esx_policejob:unrestrain')
        TriggerEvent('esx_phone:removeSpecialContact', 'police')

        if Config.MaxInService ~= -1 then
            TriggerServerEvent('esx_service:disableService', 'police')
        end

        if Config.EnableHandcuffTimer and handcuffTimer.active then
            ESX.ClearTimeout(handcuffTimer.task)
        end
    end
end)

-- handcuff timer, unrestrain the player after an certain amount of time
function StartHandcuffTimer()
    if Config.EnableHandcuffTimer and handcuffTimer.active then
        ESX.ClearTimeout(handcuffTimer.task)
    end

    handcuffTimer.active = true

    handcuffTimer.task = ESX.SetTimeout(Config.handcuffTimer, function()
        ESX.ShowNotification(_U('unrestrained_timer'))
        TriggerEvent('esx_policejob:unrestrain')
        handcuffTimer.active = false
    end)
end

-- TODO
--   - return to garage if owned
--   - message owner that his vehicle has been impounded
function ImpoundVehicle(vehicle)
    --local vehicleName = GetLabelText(GetDisplayNameFromVehicleModel(GetEntityModel(vehicle)))
    ESX.Game.DeleteVehicle(vehicle)
    ESX.ShowNotification(_U('impound_successful'))
    currentTask.busy = false
end

function SendToCommunityService(player)
    ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'Hizmet Cezası Menüsü', {
        title = "Hizmet Cezası Menüsü",
    }, function (data2, menu)
        local community_services_count = tonumber(data2.value)
        
        if community_services_count == nil then
            ESX.ShowNotification('Geçersiz Hizmet Sayısı !')
        else
            TriggerServerEvent("esx_communityservice:sendToCommunityService", player, community_services_count)
            menu.close()
        end
    end, function (data2, menu)
        menu.close()
    end)
end



es_extended/client/functions.lu

Kod:
ESX                           = {}
ESX.PlayerData                = {}
ESX.PlayerLoaded              = false
ESX.CurrentRequestId          = 0
ESX.ServerCallbacks           = {}
ESX.TimeoutCallbacks          = {}

ESX.UI                        = {}
ESX.UI.HUD                    = {}
ESX.UI.HUD.RegisteredElements = {}
ESX.UI.Menu                   = {}
ESX.UI.Menu.RegisteredTypes   = {}
ESX.UI.Menu.Opened            = {}

ESX.Game                      = {}
ESX.Game.Utils                = {}

ESX.Scaleform                 = {}
ESX.Scaleform.Utils           = {}

ESX.Streaming                 = {}

ESX.SetTimeout = function(msec, cb)
    table.insert(ESX.TimeoutCallbacks, {
        time = GetGameTimer() + msec,
        cb   = cb
    })
    return #ESX.TimeoutCallbacks
end

ESX.ClearTimeout = function(i)
    ESX.TimeoutCallbacks[i] = nil
end

ESX.IsPlayerLoaded = function()
    return ESX.PlayerLoaded
end

ESX.GetPlayerData = function()
    return ESX.PlayerData
end

ESX.SetPlayerData = function(key, val)
    ESX.PlayerData[key] = val
end

ESX.ShowNotification = function(msg)
    SetNotificationTextEntry('STRING')
    AddTextComponentSubstringPlayerName(msg)
    DrawNotification(false, true)
end

ESX.ShowAdvancedNotification = function(title, subject, msg, icon, iconType)
    SetNotificationTextEntry('STRING')
    AddTextComponentSubstringPlayerName(msg)
    SetNotificationMessage(icon, icon, false, iconType, title, subject)
    DrawNotification(false, false)
end

ESX.ShowHelpNotification = function(msg)
    --if not IsHelpMessageBeingDisplayed() then
        BeginTextCommandDisplayHelp('STRING')
        AddTextComponentSubstringPlayerName(msg)
        EndTextCommandDisplayHelp(0, false, true, -1)
    --end
end

ESX.TriggerServerCallback = function(name, cb, ...)
    ESX.ServerCallbacks[ESX.CurrentRequestId] = cb

    TriggerServerEvent('esx:triggerServerCallback', name, ESX.CurrentRequestId, ...)

    if ESX.CurrentRequestId < 65535 then
        ESX.CurrentRequestId = ESX.CurrentRequestId + 1
    else
        ESX.CurrentRequestId = 0
    end
end

ESX.UI.HUD.SetDisplay = function(opacity)
    SendNUIMessage({
        action  = 'setHUDDisplay',
        opacity = opacity
    })
end

ESX.UI.HUD.RegisterElement = function(name, index, priority, html, data)
    local found = false

    for i=1, #ESX.UI.HUD.RegisteredElements, 1 do
        if ESX.UI.HUD.RegisteredElements[i] == name then
            found = true
            break
        end
    end

    if found then
        return
    end

    table.insert(ESX.UI.HUD.RegisteredElements, name)

    SendNUIMessage({
        action    = 'insertHUDElement',
        name      = name,
        index     = index,
        priority  = priority,
        html      = html,
        data      = data
    })

    ESX.UI.HUD.UpdateElement(name, data)
end

ESX.UI.HUD.RemoveElement = function(name)
    for i=1, #ESX.UI.HUD.RegisteredElements, 1 do
        if ESX.UI.HUD.RegisteredElements[i] == name then
            table.remove(ESX.UI.HUD.RegisteredElements, i)
            break
        end
    end

    SendNUIMessage({
        action    = 'deleteHUDElement',
        name      = name
    })
end

ESX.UI.HUD.UpdateElement = function(name, data)
    SendNUIMessage({
        action = 'updateHUDElement',
        name   = name,
        data   = data
    })
end

ESX.UI.Menu.RegisterType = function(type, open, close)
    ESX.UI.Menu.RegisteredTypes[type] = {
        open   = open,
        close  = close
    }
end

ESX.UI.Menu.Open = function(type, namespace, name, data, submit, cancel, change, close)
    local menu = {}

    menu.type      = type
    menu.namespace = namespace
    menu.name      = name
    menu.data      = data
    menu.submit    = submit
    menu.cancel    = cancel
    menu.change    = change

    menu.close = function()

        ESX.UI.Menu.RegisteredTypes[type].close(namespace, name)

        for i=1, #ESX.UI.Menu.Opened, 1 do
            if ESX.UI.Menu.Opened[i] ~= nil then
                if ESX.UI.Menu.Opened[i].type == type and ESX.UI.Menu.Opened[i].namespace == namespace and ESX.UI.Menu.Opened[i].name == name then
                    ESX.UI.Menu.Opened[i] = nil
                end
            end
        end

        if close ~= nil then
            close()
        end

    end

    menu.update = function(query, newData)

        for i=1, #menu.data.elements, 1 do
            local match = true

            for k,v in pairs(query) do
                if menu.data.elements[i][k] ~= v then
                    match = false
                end
            end

            if match then
                for k,v in pairs(newData) do
                    menu.data.elements[i][k] = v
                end
            end
        end

    end

    menu.refresh = function()
        ESX.UI.Menu.RegisteredTypes[type].open(namespace, name, menu.data)
    end

    menu.setElement = function(i, key, val)
        menu.data.elements[i][key] = val
    end

    menu.setTitle = function(val)
        menu.data.title = val
    end

    menu.removeElement = function(query)
        for i=1, #menu.data.elements, 1 do
            for k,v in pairs(query) do
                if menu.data.elements[i] then
                    if menu.data.elements[i][k] == v then
                        table.remove(menu.data.elements, i)
                        break
                    end
                end

            end
        end
    end

    table.insert(ESX.UI.Menu.Opened, menu)
    ESX.UI.Menu.RegisteredTypes[type].open(namespace, name, data)

    return menu
end

ESX.UI.Menu.Close = function(type, namespace, name)
    for i=1, #ESX.UI.Menu.Opened, 1 do
        if ESX.UI.Menu.Opened[i] ~= nil then
            if ESX.UI.Menu.Opened[i].type == type and ESX.UI.Menu.Opened[i].namespace == namespace and ESX.UI.Menu.Opened[i].name == name then
                ESX.UI.Menu.Opened[i].close()
                ESX.UI.Menu.Opened[i] = nil
            end
        end
    end
end

ESX.UI.Menu.CloseAll = function()
    for i=1, #ESX.UI.Menu.Opened, 1 do
        if ESX.UI.Menu.Opened[i] ~= nil then
            ESX.UI.Menu.Opened[i].close()
            ESX.UI.Menu.Opened[i] = nil
        end
    end
end

ESX.UI.Menu.GetOpened = function(type, namespace, name)
    for i=1, #ESX.UI.Menu.Opened, 1 do
        if ESX.UI.Menu.Opened[i] ~= nil then
            if ESX.UI.Menu.Opened[i].type == type and ESX.UI.Menu.Opened[i].namespace == namespace and ESX.UI.Menu.Opened[i].name == name then
                return ESX.UI.Menu.Opened[i]
            end
        end
    end
end

ESX.UI.Menu.GetOpenedMenus = function()
    return ESX.UI.Menu.Opened
end

ESX.UI.Menu.IsOpen = function(type, namespace, name)
    return ESX.UI.Menu.GetOpened(type, namespace, name) ~= nil
end

ESX.UI.ShowInventoryItemNotification = function(add, item, count)
    SendNUIMessage({
        action = 'inventoryNotification',
        add    = add,
        item   = item,
        count  = count
    })
end

ESX.Game.GetPedMugshot = function(ped)
    local mugshot = RegisterPedheadshot(ped)

    while not IsPedheadshotReady(mugshot) do
        Citizen.Wait(0)
    end

    return mugshot, GetPedheadshotTxdString(mugshot)
end

ESX.Game.Teleport = function(entity, coords, cb)
    RequestCollisionAtCoord(coords.x, coords.y, coords.z)

    while not HasCollisionLoadedAroundEntity(entity) do
        RequestCollisionAtCoord(coords.x, coords.y, coords.z)
        Citizen.Wait(0)
    end

    SetEntityCoords(entity, coords.x, coords.y, coords.z)

    if cb ~= nil then
        cb()
    end
end

ESX.Game.SpawnObject = function(model, coords, cb)
    local model = (type(model) == 'number' and model or GetHashKey(model))

    Citizen.CreateThread(function()
        ESX.Streaming.RequestModel(model)

        local obj = CreateObject(model, coords.x, coords.y, coords.z, true, false, true)

        if cb ~= nil then
            cb(obj)
        end
    end)
end

ESX.Game.SpawnLocalObject = function(model, coords, cb)
    local model = (type(model) == 'number' and model or GetHashKey(model))

    Citizen.CreateThread(function()
        ESX.Streaming.RequestModel(model)

        local obj = CreateObject(model, coords.x, coords.y, coords.z, false, false, true)

        if cb ~= nil then
            cb(obj)
        end
    end)
end

ESX.Game.DeleteVehicle = function(vehicle)
    SetEntityAsMissionEntity(vehicle, false, true)
    DeleteVehicle(vehicle)
end

ESX.Game.DeleteObject = function(object)
    SetEntityAsMissionEntity(object, false, true)
    DeleteObject(object)
end

ESX.Game.SpawnVehicle = function(modelName, coords, heading, cb)
    local model = (type(modelName) == 'number' and modelName or GetHashKey(modelName))

    Citizen.CreateThread(function()
        ESX.Streaming.RequestModel(model)

        local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, heading, true, false)
        local id      = NetworkGetNetworkIdFromEntity(vehicle)

        SetNetworkIdCanMigrate(id, true)
        SetEntityAsMissionEntity(vehicle, true, false)
        SetVehicleHasBeenOwnedByPlayer(vehicle, true)
        SetVehicleNeedsToBeHotwired(vehicle, false)
        SetModelAsNoLongerNeeded(model)

        RequestCollisionAtCoord(coords.x, coords.y, coords.z)

        while not HasCollisionLoadedAroundEntity(vehicle) do
            RequestCollisionAtCoord(coords.x, coords.y, coords.z)
            Citizen.Wait(0)
        end

        SetVehRadioStation(vehicle, 'OFF')

        if cb ~= nil then
            cb(vehicle)
        end
    end)
end

ESX.Game.SpawnLocalVehicle = function(modelName, coords, heading, cb)
    local model = (type(modelName) == 'number' and modelName or GetHashKey(modelName))

    Citizen.CreateThread(function()
        ESX.Streaming.RequestModel(model)

        local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, heading, false, false)

        SetEntityAsMissionEntity(vehicle, true, false)
        SetVehicleHasBeenOwnedByPlayer(vehicle, true)
        SetVehicleNeedsToBeHotwired(vehicle, false)
        SetModelAsNoLongerNeeded(model)
        RequestCollisionAtCoord(coords.x, coords.y, coords.z)

        while not HasCollisionLoadedAroundEntity(vehicle) do
            RequestCollisionAtCoord(coords.x, coords.y, coords.z)
            Citizen.Wait(0)
        end

        SetVehRadioStation(vehicle, 'OFF')

        if cb ~= nil then
            cb(vehicle)
        end
    end)
end

ESX.Game.IsVehicleEmpty = function(vehicle)
    local passengers = GetVehicleNumberOfPassengers(vehicle)
    local driverSeatFree = IsVehicleSeatFree(vehicle, -1)

    return passengers == 0 and driverSeatFree
end

ESX.Game.GetObjects = function()
    local objects = {}

    for object in EnumerateObjects() do
        table.insert(objects, object)
    end

    return objects
end

ESX.Game.GetClosestObject = function(filter, coords)
    local objects         = ESX.Game.GetObjects()
    local closestDistance = -1
    local closestObject   = -1
    local filter          = filter
    local coords          = coords

    if type(filter) == 'string' then
        if filter ~= '' then
            filter = {filter}
        end
    end

    if coords == nil then
        local playerPed = PlayerPedId()
        coords          = GetEntityCoords(playerPed)
    end

    for i=1, #objects, 1 do
        local foundObject = false

        if filter == nil or (type(filter) == 'table' and #filter == 0) then
            foundObject = true
        else
            local objectModel = GetEntityModel(objects[i])

            for j=1, #filter, 1 do
                if objectModel == GetHashKey(filter[j]) then
                    foundObject = true
                end
            end
        end

        if foundObject then
            local objectCoords = GetEntityCoords(objects[i])
            local distance     = GetDistanceBetweenCoords(objectCoords, coords.x, coords.y, coords.z, true)

            if closestDistance == -1 or closestDistance > distance then
                closestObject   = objects[i]
                closestDistance = distance
            end
        end
    end

    return closestObject, closestDistance
end

ESX.Game.GetPlayers = function()
    local maxPlayers = Config.MaxPlayers
    local players    = {}

    for i=0, maxPlayers, 1 do

        local ped = GetPlayerPed(i)

        if DoesEntityExist(ped) then
            table.insert(players, i)
        end
    end

    return players
end

ESX.Game.GetClosestPlayer = function(coords)
    local players         = ESX.Game.GetPlayers()
    local closestDistance = -1
    local closestPlayer   = -1
    local coords          = coords
    local usePlayerPed    = false
    local playerPed       = PlayerPedId()
    local playerId        = PlayerId()

    if coords == nil then
        usePlayerPed = true
        coords       = GetEntityCoords(playerPed)
    end

    for i=1, #players, 1 do
        local target = GetPlayerPed(players[i])

        if not usePlayerPed or (usePlayerPed and players[i] ~= playerId) then
            local targetCoords = GetEntityCoords(target)
            local distance     = GetDistanceBetweenCoords(targetCoords, coords.x, coords.y, coords.z, true)

            if closestDistance == -1 or closestDistance > distance then
                closestPlayer   = players[i]
                closestDistance = distance
            end
        end
    end

    return closestPlayer, closestDistance
end

ESX.Game.GetPlayersInArea = function(coords, area)
    local players       = ESX.Game.GetPlayers()
    local playersInArea = {}

    for i=1, #players, 1 do
        local target       = GetPlayerPed(players[i])
        local targetCoords = GetEntityCoords(target)
        local distance     = GetDistanceBetweenCoords(targetCoords, coords.x, coords.y, coords.z, true)

        if distance <= area then
            table.insert(playersInArea, players[i])
        end
    end

    return playersInArea
end

ESX.Game.GetVehicles = function()
    local vehicles = {}

    for vehicle in EnumerateVehicles() do
        table.insert(vehicles, vehicle)
    end

    return vehicles
end

ESX.Game.GetClosestVehicle = function(coords)
    local vehicles        = ESX.Game.GetVehicles()
    local closestDistance = -1
    local closestVehicle  = -1
    local coords          = coords

    if coords == nil then
        local playerPed = PlayerPedId()
        coords          = GetEntityCoords(playerPed)
    end

    for i=1, #vehicles, 1 do
        local vehicleCoords = GetEntityCoords(vehicles[i])
        local distance      = GetDistanceBetweenCoords(vehicleCoords, coords.x, coords.y, coords.z, true)

        if closestDistance == -1 or closestDistance > distance then
            closestVehicle  = vehicles[i]
            closestDistance = distance
        end
    end

    return closestVehicle, closestDistance
end

ESX.Game.GetVehiclesInArea = function(coords, area)
    local vehicles       = ESX.Game.GetVehicles()
    local vehiclesInArea = {}

    for i=1, #vehicles, 1 do
        local vehicleCoords = GetEntityCoords(vehicles[i])
        local distance      = GetDistanceBetweenCoords(vehicleCoords, coords.x, coords.y, coords.z, true)

        if distance <= area then
            table.insert(vehiclesInArea, vehicles[i])
        end
    end

    return vehiclesInArea
end

ESX.Game.GetVehicleInDirection = function()
    local playerPed    = PlayerPedId()
    local playerCoords = GetEntityCoords(playerPed)
    local inDirection  = GetOffsetFromEntityInWorldCoords(playerPed, 0.0, 5.0, 0.0)
    local rayHandle    = StartShapeTestRay(playerCoords, inDirection, 10, playerPed, 0)
    local numRayHandle, hit, endCoords, surfaceNormal, entityHit = GetShapeTestResult(rayHandle)

    if hit == 1 and GetEntityType(entityHit) == 2 then
        return entityHit
    end

    return nil
end

ESX.Game.IsSpawnPointClear = function(coords, radius)
    local vehicles = ESX.Game.GetVehiclesInArea(coords, radius)

    return #vehicles == 0
end

ESX.Game.GetPeds = function(ignoreList)
    local ignoreList = ignoreList or {}
    local peds       = {}

    for ped in EnumeratePeds() do
        local found = false

        for j=1, #ignoreList, 1 do
            if ignoreList[j] == ped then
                found = true
            end
        end

        if not found then
            table.insert(peds, ped)
        end
    end

    return peds
end

ESX.Game.GetClosestPed = function(coords, ignoreList)
    local ignoreList      = ignoreList or {}
    local peds            = ESX.Game.GetPeds(ignoreList)
    local closestDistance = -1
    local closestPed      = -1

    for i=1, #peds, 1 do
        local pedCoords = GetEntityCoords(peds[i])
        local distance  = GetDistanceBetweenCoords(pedCoords, coords.x, coords.y, coords.z, true)

        if closestDistance == -1 or closestDistance > distance then
            closestPed      = peds[i]
            closestDistance = distance
        end
    end

    return closestPed, closestDistance
end

ESX.Game.GetVehicleProperties = function(vehicle)
    local color1, color2 = GetVehicleColours(vehicle)
    local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle)
    local extras = {}

    for id=0, 12 do
        if DoesExtraExist(vehicle, id) then
            local state = IsVehicleExtraTurnedOn(vehicle, id) == 1
            extras[tostring(id)] = state
        end
    end

    return {

        model             = GetEntityModel(vehicle),

        plate             = ESX.Math.Trim(GetVehicleNumberPlateText(vehicle)),
        plateIndex        = GetVehicleNumberPlateTextIndex(vehicle),

        health            = GetEntityHealth(vehicle),
        dirtLevel         = GetVehicleDirtLevel(vehicle),

        color1            = color1,
        color2            = color2,

        pearlescentColor  = pearlescentColor,
        wheelColor        = wheelColor,

        wheels            = GetVehicleWheelType(vehicle),
        windowTint        = GetVehicleWindowTint(vehicle),

        neonEnabled       = {
            IsVehicleNeonLightEnabled(vehicle, 0),
            IsVehicleNeonLightEnabled(vehicle, 1),
            IsVehicleNeonLightEnabled(vehicle, 2),
            IsVehicleNeonLightEnabled(vehicle, 3)
        },

        extras            = extras,

        neonColor         = table.pack(GetVehicleNeonLightsColour(vehicle)),
        tyreSmokeColor    = table.pack(GetVehicleTyreSmokeColor(vehicle)),

        modSpoilers       = GetVehicleMod(vehicle, 0),
        modFrontBumper    = GetVehicleMod(vehicle, 1),
        modRearBumper     = GetVehicleMod(vehicle, 2),
        modSideSkirt      = GetVehicleMod(vehicle, 3),
        modExhaust        = GetVehicleMod(vehicle, 4),
        modFrame          = GetVehicleMod(vehicle, 5),
        modGrille         = GetVehicleMod(vehicle, 6),
        modHood           = GetVehicleMod(vehicle, 7),
        modFender         = GetVehicleMod(vehicle, 8),
        modRightFender    = GetVehicleMod(vehicle, 9),
        modRoof           = GetVehicleMod(vehicle, 10),

        modEngine         = GetVehicleMod(vehicle, 11),
        modBrakes         = GetVehicleMod(vehicle, 12),
        modTransmission   = GetVehicleMod(vehicle, 13),
        modHorns          = GetVehicleMod(vehicle, 14),
        modSuspension     = GetVehicleMod(vehicle, 15),
        modArmor          = GetVehicleMod(vehicle, 16),

        modTurbo          = IsToggleModOn(vehicle, 18),
        modSmokeEnabled   = IsToggleModOn(vehicle, 20),
        modXenon          = IsToggleModOn(vehicle, 22),

        modFrontWheels    = GetVehicleMod(vehicle, 23),
        modBackWheels     = GetVehicleMod(vehicle, 24),

        modPlateHolder    = GetVehicleMod(vehicle, 25),
        modVanityPlate    = GetVehicleMod(vehicle, 26),
        modTrimA          = GetVehicleMod(vehicle, 27),
        modOrnaments      = GetVehicleMod(vehicle, 28),
        modDashboard      = GetVehicleMod(vehicle, 29),
        modDial           = GetVehicleMod(vehicle, 30),
        modDoorSpeaker    = GetVehicleMod(vehicle, 31),
        modSeats          = GetVehicleMod(vehicle, 32),
        modSteeringWheel  = GetVehicleMod(vehicle, 33),
        modShifterLeavers = GetVehicleMod(vehicle, 34),
        modAPlate         = GetVehicleMod(vehicle, 35),
        modSpeakers       = GetVehicleMod(vehicle, 36),
        modTrunk          = GetVehicleMod(vehicle, 37),
        modHydrolic       = GetVehicleMod(vehicle, 38),
        modEngineBlock    = GetVehicleMod(vehicle, 39),
        modAirFilter      = GetVehicleMod(vehicle, 40),
        modStruts         = GetVehicleMod(vehicle, 41),
        modArchCover      = GetVehicleMod(vehicle, 42),
        modAerials        = GetVehicleMod(vehicle, 43),
        modTrimB          = GetVehicleMod(vehicle, 44),
        modTank           = GetVehicleMod(vehicle, 45),
        modWindows        = GetVehicleMod(vehicle, 46),
        modLivery         = GetVehicleLivery(vehicle)
    }
end

ESX.Game.SetVehicleProperties = function(vehicle, props)
    SetVehicleModKit(vehicle, 0)

    if props.plate ~= nil then
        SetVehicleNumberPlateText(vehicle, props.plate)
    end

    if props.plateIndex ~= nil then
        SetVehicleNumberPlateTextIndex(vehicle, props.plateIndex)
    end

    if props.health ~= nil then
        SetEntityHealth(vehicle, props.health)
    end

    if props.dirtLevel ~= nil then
        SetVehicleDirtLevel(vehicle, props.dirtLevel)
    end

    if props.color1 ~= nil then
        local color1, color2 = GetVehicleColours(vehicle)
        SetVehicleColours(vehicle, props.color1, color2)
    end

    if props.color2 ~= nil then
        local color1, color2 = GetVehicleColours(vehicle)
        SetVehicleColours(vehicle, color1, props.color2)
    end

    if props.pearlescentColor ~= nil then
        local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle)
        SetVehicleExtraColours(vehicle, props.pearlescentColor, wheelColor)
    end

    if props.wheelColor ~= nil then
        local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle)
        SetVehicleExtraColours(vehicle, pearlescentColor, props.wheelColor)
    end

    if props.wheels ~= nil then
        SetVehicleWheelType(vehicle, props.wheels)
    end

    if props.windowTint ~= nil then
        SetVehicleWindowTint(vehicle, props.windowTint)
    end

    if props.neonEnabled ~= nil then
        SetVehicleNeonLightEnabled(vehicle, 0, props.neonEnabled[1])
        SetVehicleNeonLightEnabled(vehicle, 1, props.neonEnabled[2])
        SetVehicleNeonLightEnabled(vehicle, 2, props.neonEnabled[3])
        SetVehicleNeonLightEnabled(vehicle, 3, props.neonEnabled[4])
    end

    if props.extras ~= nil then
        for id,enabled in pairs(props.extras) do
            if enabled then
                SetVehicleExtra(vehicle, tonumber(id), 0)
            else
                SetVehicleExtra(vehicle, tonumber(id), 1)
            end
        end
    end

    if props.neonColor ~= nil then
        SetVehicleNeonLightsColour(vehicle, props.neonColor[1], props.neonColor[2], props.neonColor[3])
    end

    if props.modSmokeEnabled ~= nil then
        ToggleVehicleMod(vehicle, 20, true)
    end

    if props.tyreSmokeColor ~= nil then
        SetVehicleTyreSmokeColor(vehicle, props.tyreSmokeColor[1], props.tyreSmokeColor[2], props.tyreSmokeColor[3])
    end

    if props.modSpoilers ~= nil then
        SetVehicleMod(vehicle, 0, props.modSpoilers, false)
    end

    if props.modFrontBumper ~= nil then
        SetVehicleMod(vehicle, 1, props.modFrontBumper, false)
    end

    if props.modRearBumper ~= nil then
        SetVehicleMod(vehicle, 2, props.modRearBumper, false)
    end

    if props.modSideSkirt ~= nil then
        SetVehicleMod(vehicle, 3, props.modSideSkirt, false)
    end

    if props.modExhaust ~= nil then
        SetVehicleMod(vehicle, 4, props.modExhaust, false)
    end

    if props.modFrame ~= nil then
        SetVehicleMod(vehicle, 5, props.modFrame, false)
    end

    if props.modGrille ~= nil then
        SetVehicleMod(vehicle, 6, props.modGrille, false)
    end

    if props.modHood ~= nil then
        SetVehicleMod(vehicle, 7, props.modHood, false)
    end

    if props.modFender ~= nil then
        SetVehicleMod(vehicle, 8, props.modFender, false)
    end

    if props.modRightFender ~= nil then
        SetVehicleMod(vehicle, 9, props.modRightFender, false)
    end

    if props.modRoof ~= nil then
        SetVehicleMod(vehicle, 10, props.modRoof, false)
    end

    if props.modEngine ~= nil then
        SetVehicleMod(vehicle, 11, props.modEngine, false)
    end

    if props.modBrakes ~= nil then
        SetVehicleMod(vehicle, 12, props.modBrakes, false)
    end

    if props.modTransmission ~= nil then
        SetVehicleMod(vehicle, 13, props.modTransmission, false)
    end

    if props.modHorns ~= nil then
        SetVehicleMod(vehicle, 14, props.modHorns, false)
    end

    if props.modSuspension ~= nil then
        SetVehicleMod(vehicle, 15, props.modSuspension, false)
    end

    if props.modArmor ~= nil then
        SetVehicleMod(vehicle, 16, props.modArmor, false)
    end

    if props.modTurbo ~= nil then
        ToggleVehicleMod(vehicle,  18, props.modTurbo)
    end

    if props.modXenon ~= nil then
        ToggleVehicleMod(vehicle,  22, props.modXenon)
    end

    if props.modFrontWheels ~= nil then
        SetVehicleMod(vehicle, 23, props.modFrontWheels, false)
    end

    if props.modBackWheels ~= nil then
        SetVehicleMod(vehicle, 24, props.modBackWheels, false)
    end

    if props.modPlateHolder ~= nil then
        SetVehicleMod(vehicle, 25, props.modPlateHolder, false)
    end

    if props.modVanityPlate ~= nil then
        SetVehicleMod(vehicle, 26, props.modVanityPlate, false)
    end

    if props.modTrimA ~= nil then
        SetVehicleMod(vehicle, 27, props.modTrimA, false)
    end

    if props.modOrnaments ~= nil then
        SetVehicleMod(vehicle, 28, props.modOrnaments, false)
    end

    if props.modDashboard ~= nil then
        SetVehicleMod(vehicle, 29, props.modDashboard, false)
    end

    if props.modDial ~= nil then
        SetVehicleMod(vehicle, 30, props.modDial, false)
    end

    if props.modDoorSpeaker ~= nil then
        SetVehicleMod(vehicle, 31, props.modDoorSpeaker, false)
    end

    if props.modSeats ~= nil then
        SetVehicleMod(vehicle, 32, props.modSeats, false)
    end

    if props.modSteeringWheel ~= nil then
        SetVehicleMod(vehicle, 33, props.modSteeringWheel, false)
    end

    if props.modShifterLeavers ~= nil then
        SetVehicleMod(vehicle, 34, props.modShifterLeavers, false)
    end

    if props.modAPlate ~= nil then
        SetVehicleMod(vehicle, 35, props.modAPlate, false)
    end

    if props.modSpeakers ~= nil then
        SetVehicleMod(vehicle, 36, props.modSpeakers, false)
    end

    if props.modTrunk ~= nil then
        SetVehicleMod(vehicle, 37, props.modTrunk, false)
    end

    if props.modHydrolic ~= nil then
        SetVehicleMod(vehicle, 38, props.modHydrolic, false)
    end

    if props.modEngineBlock ~= nil then
        SetVehicleMod(vehicle, 39, props.modEngineBlock, false)
    end

    if props.modAirFilter ~= nil then
        SetVehicleMod(vehicle, 40, props.modAirFilter, false)
    end

    if props.modStruts ~= nil then
        SetVehicleMod(vehicle, 41, props.modStruts, false)
    end

    if props.modArchCover ~= nil then
        SetVehicleMod(vehicle, 42, props.modArchCover, false)
    end

    if props.modAerials ~= nil then
        SetVehicleMod(vehicle, 43, props.modAerials, false)
    end

    if props.modTrimB ~= nil then
        SetVehicleMod(vehicle, 44, props.modTrimB, false)
    end

    if props.modTank ~= nil then
        SetVehicleMod(vehicle, 45, props.modTank, false)
    end

    if props.modWindows ~= nil then
        SetVehicleMod(vehicle, 46, props.modWindows, false)
    end

    if props.modLivery ~= nil then
        SetVehicleMod(vehicle, 48, props.modLivery, false)
        SetVehicleLivery(vehicle, props.modLivery)
    end
end

ESX.Game.Utils.DrawText3D = function(coords, text, size)
    local onScreen, x, y = World3dToScreen2d(coords.x, coords.y, coords.z)
    local camCoords      = GetGameplayCamCoords()
    local dist           = GetDistanceBetweenCoords(camCoords, coords.x, coords.y, coords.z, true)
    local size           = size

    if size == nil then
        size = 1
    end

    local scale = (size / dist) * 2
    local fov   = (1 / GetGameplayCamFov()) * 100
    local scale = scale * fov

    if onScreen then
        SetTextScale(0.0 * scale, 0.55 * scale)
        SetTextFont(0)
        SetTextColour(255, 255, 255, 255)
        SetTextDropshadow(0, 0, 0, 0, 255)
        SetTextDropShadow()
        SetTextOutline()
        SetTextEntry('STRING')
        SetTextCentre(1)

        AddTextComponentString(text)
        DrawText(x, y)
    end
end

ESX.ShowInventory = function()
    local playerPed = PlayerPedId()
    local elements  = {}

    if ESX.PlayerData.money > 0 then
        local formattedMoney = _U('locale_currency', ESX.Math.GroupDigits(ESX.PlayerData.money))

        table.insert(elements, {
            label     = ('%s: <span style="color:green;">%s</span>'):format(_U('cash'), formattedMoney),
            count     = ESX.PlayerData.money,
            type      = 'item_money',
            value     = 'money',
            usable    = false,
            rare      = false,
            canRemove = true
        })
    end

    for i=1, #ESX.PlayerData.accounts, 1 do
        if ESX.PlayerData.accounts[i].money > 0 then
            local formattedMoney = _U('locale_currency', ESX.Math.GroupDigits(ESX.PlayerData.accounts[i].money))
            local canDrop = ESX.PlayerData.accounts[i].name ~= 'bank'

            table.insert(elements, {
                label     = ('%s: <span style="color:green;">%s</span>'):format(ESX.PlayerData.accounts[i].label, formattedMoney),
                count     = ESX.PlayerData.accounts[i].money,
                type      = 'item_account',
                value     = ESX.PlayerData.accounts[i].name,
                usable    = false,
                rare      = false,
                canRemove = canDrop
            })
        end
    end

    for i=1, #ESX.PlayerData.inventory, 1 do
        if ESX.PlayerData.inventory[i].count > 0 then
            table.insert(elements, {
                label     = ESX.PlayerData.inventory[i].label .. ' x' .. ESX.PlayerData.inventory[i].count,
                count     = ESX.PlayerData.inventory[i].count,
                type      = 'item_standard',
                value     = ESX.PlayerData.inventory[i].name,
                usable    = ESX.PlayerData.inventory[i].usable,
                rare      = ESX.PlayerData.inventory[i].rare,
                canRemove = ESX.PlayerData.inventory[i].canRemove
            })
        end
    end

    for i=1, #Config.Weapons, 1 do
        local weaponHash = GetHashKey(Config.Weapons[i].name)

        if HasPedGotWeapon(playerPed, weaponHash, false) and Config.Weapons[i].name ~= 'WEAPON_UNARMED' then
            local ammo = GetAmmoInPedWeapon(playerPed, weaponHash)
            table.insert(elements, {
                label     = Config.Weapons[i].label .. ' [' .. ammo .. ']',
                count     = 1,
                type      = 'item_weapon',
                value     = Config.Weapons[i].name,
                ammo      = ammo,
                usable    = false,
                rare      = false,
                canRemove = true
            })
        end
    end

    ESX.UI.Menu.CloseAll()

    ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'inventory',
    {
        title    = _U('inventory'),
        align    = 'bottom-right',
        elements = elements,
    }, function(data, menu)
        menu.close()

        local player, distance = ESX.Game.GetClosestPlayer()
        local elements = {}

        if data.current.usable then
            table.insert(elements, {label = _U('use'), action = 'use', type = data.current.type, value = data.current.value})
        end

        if data.current.canRemove then
            if player ~= -1 and distance <= 3.0 then
                table.insert(elements, {label = _U('give'), action = 'give', type = data.current.type, value = data.current.value})
            end

            table.insert(elements, {label = _U('remove'), action = 'remove', type = data.current.type, value = data.current.value})
        end

        if data.current.type == 'item_weapon' and data.current.ammo > 0 and player ~= -1 and distance <= 3.0 then
            table.insert(elements, {label = _U('giveammo'), action = 'giveammo', type = data.current.type, value = data.current.value})
        end

        table.insert(elements, {label = _U('return'), action = 'return'})

        ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'inventory_item',
        {
            title    = data.current.label,
            align    = 'bottom-right',
            elements = elements,
        }, function(data1, menu1)

            local item = data1.current.value
            local type = data1.current.type
            local playerPed = PlayerPedId()

            if data1.current.action == 'give' then

                local players      = ESX.Game.GetPlayersInArea(GetEntityCoords(playerPed), 3.0)
                local foundPlayers = false
                local elements     = {}

                for i=1, #players, 1 do
                    if players[i] ~= PlayerId() then
                        foundPlayers = true

                        table.insert(elements, {
                            label = GetPlayerName(players[i]),
                            player = players[i]
                        })
                    end
                end

                if not foundPlayers then
                    ESX.ShowNotification(_U('players_nearby'))
                    return
                end

                foundPlayers = false

                ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'give_item_to',
                {
                    title    = _U('give_to'),
                    align    = 'bottom-right',
                    elements = elements
                }, function(data2, menu2)

                    local players, nearbyPlayer = ESX.Game.GetPlayersInArea(GetEntityCoords(playerPed), 3.0)

                    for i=1, #players, 1 do
                        if players[i] ~= PlayerId() then

                            if players[i] == data2.current.player then
                                foundPlayers = true
                                nearbyPlayer = players[i]
                                break
                            end
                        end
                    end

                    if not foundPlayers then
                        ESX.ShowNotification(_U('players_nearby'))
                        menu2.close()
                        return
                    end

                    if type == 'item_weapon' then

                        local closestPed = GetPlayerPed(nearbyPlayer)
                        local sourceAmmo = GetAmmoInPedWeapon(PlayerPedId(), GetHashKey(item))

                        if IsPedSittingInAnyVehicle(closestPed) then
                            ESX.ShowNotification(_U('in_vehicle'))
                            return
                        end

                        TriggerServerEvent('esx:giveInventoryItem', GetPlayerServerId(nearbyPlayer), type, item, sourceAmmo)
                        menu2.close()
                        menu1.close()

                    else

                        ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'inventory_item_count_give', {
                            title = _U('amount')
                        }, function(data3, menu3)
                            local quantity = tonumber(data3.value)
                            local closestPed = GetPlayerPed(nearbyPlayer)

                            if IsPedSittingInAnyVehicle(closestPed) then
                                ESX.ShowNotification(_U('in_vehicle'))
                                return
                            end

                            if quantity ~= nil then
                                TriggerServerEvent('esx:giveInventoryItem', GetPlayerServerId(nearbyPlayer), type, item, quantity)

                                menu3.close()
                                menu2.close()
                                menu1.close()
                            else
                                ESX.ShowNotification(_U('amount_invalid'))
                            end

                        end, function(data3, menu3)
                            menu3.close()
                        end)
                    end
                end, function(data2, menu2)
                    menu2.close()
                end) -- give end

            elseif data1.current.action == 'remove' then

                if IsPedSittingInAnyVehicle(playerPed) then
                    return
                end

                if type == 'item_weapon' then

                    TriggerServerEvent('esx:removeInventoryItem', type, item)
                    menu1.close()

                else -- type: item_standard

                    ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'inventory_item_count_remove', {
                        title = _U('amount')
                    }, function(data2, menu2)
                        local quantity = tonumber(data2.value)

                        if quantity == nil then
                            ESX.ShowNotification(_U('amount_invalid'))
                        else
                            TriggerServerEvent('esx:removeInventoryItem', type, item, quantity)
                            menu2.close()
                            menu1.close()
                        end

                    end, function(data2, menu2)
                        menu2.close()
                    end)
                end

            elseif data1.current.action == 'use' then
                TriggerServerEvent('esx:useItem', item)

            elseif data1.current.action == 'return' then
                ESX.UI.Menu.CloseAll()
                ESX.ShowInventory()
            elseif data1.current.action == 'giveammo' then
                local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()
                local closestPed = GetPlayerPed(closestPlayer)
                local pedAmmo = GetAmmoInPedWeapon(playerPed, GetHashKey(item))

                if IsPedSittingInAnyVehicle(closestPed) then
                    ESX.ShowNotification(_U('in_vehicle'))
                    return
                end

                if closestPlayer ~= -1 and closestDistance < 3.0 then
                    if pedAmmo > 0 then

                        ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'inventory_item_count_give', {
                            title = _U('amountammo')
                        }, function(data2, menu2)

                            local quantity = tonumber(data2.value)

                            if quantity ~= nil then
                                if quantity <= pedAmmo and quantity >= 0 then

                                    local finalAmmoSource = math.floor(pedAmmo - quantity)
                                    SetPedAmmo(playerPed, item, finalAmmoSource)
                                    AddAmmoToPed(closestPed, item, quantity)

                                    ESX.ShowNotification(_U('gave_ammo', quantity, GetPlayerName(closestPlayer)))
                                    -- todo notify target that he received ammo
                                    menu2.close()
                                    menu1.close()
                                else
                                    ESX.ShowNotification(_U('noammo'))
                                end
                            else
                                ESX.ShowNotification(_U('amount_invalid'))
                            end

                        end, function(data2, menu2)
                            menu2.close()
                        end)
                    else
                        ESX.ShowNotification(_U('noammo'))
                    end
                else
                    ESX.ShowNotification(_U('players_nearby'))
                end
            end

        end, function(data1, menu1)
            ESX.UI.Menu.CloseAll()
            ESX.ShowInventory()
        end)

    end, function(data, menu)
        menu.close()
    end)
end

RegisterNetEvent('esx:serverCallback')
AddEventHandler('esx:serverCallback', function(requestId, ...)
    ESX.ServerCallbacks[requestId](...)
    ESX.ServerCallbacks[requestId] = nil
end)

RegisterNetEvent('esx:showNotification')
AddEventHandler('esx:showNotification', function(msg)
    ESX.ShowNotification(msg)
end)

RegisterNetEvent('esx:showAdvancedNotification')
AddEventHandler('esx:showAdvancedNotification', function(title, subject, msg, icon, iconType)
    ESX.ShowAdvancedNotification(title, subject, msg, icon, iconType)
end)

RegisterNetEvent('esx:showHelpNotification')
AddEventHandler('esx:showHelpNotification', function(msg)
    ESX.ShowHelpNotification(msg)
end)

-- SetTimeout
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        local currTime = GetGameTimer()

        for i=1, #ESX.TimeoutCallbacks, 1 do
            if ESX.TimeoutCallbacks[i] then
                if currTime >= ESX.TimeoutCallbacks[i].time then
                    ESX.TimeoutCallbacks[i].cb()
                    ESX.TimeoutCallbacks[i] = nil
                end
            end
        end
    end
end)






Buda Hata REsmi 29772
 
DF

Forumdan daha fazla yararlanmak için giriş yapın yada üye olun!

Forumdan daha fazla yararlanmak için giriş yapın veya kayıt olun!

Kayıt ol

Forumda bir hesap oluşturmak tamamen ücretsizdir.

Şimdi kayıt ol
Giriş yap

Eğer bir hesabınız var ise lütfen giriş yapın

Giriş yap

Bu konuyu görüntüleyen kullanıcılar

Tema düzenleyici

Tema özelletirmeleri

Granit arka planlar

Lütfen Javascript'i etkinleştirin!Javascript'i etkinleştirin!
// Adblock Kod Start // // Adblock Kod End//