Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
9.1 kB
0
Indexable
Never
ESX = exports["es_extended"]:getSharedObject()

local ScriptCheck = GetCurrentResourceName()

if ScriptCheck == "ES-Gpt" then
    local active = "main"
    local onDuty = false
    local patrolUnits = {}
    local CarsList = {}

    Citizen.CreateThread(function()
        ESX.PlayerData = ESX.GetPlayerData()
    end)
    RegisterNetEvent('esx:playerLoaded')
    AddEventHandler('esx:playerLoaded', function(xPlayer)
        ESX.PlayerData = xPlayer
    end)
    RegisterNetEvent('esx:setJob')
    AddEventHandler('esx:setJob', function(job)
        ESX.PlayerData.job = job
    end)

    RegisterNUICallback("GptClose", function(data)
        stopAnim()
        SetNuiFocus(false, false)
        SendNUIMessage({type = 'CLOSE'})
        active = data.active
    end)

    RegisterNUICallback("GptGetData", function(data, cb)
        active = data.active
        ESX.TriggerServerCallback("server-gpt-tirex:GetGptData", function(newData, jobData)
            if active == "main" then
                for k, v in pairs(newData.vehicles) do
                    newData.vehicles[k].model = GetDisplayNameFromVehicleModel(v.model)
                end
            elseif active == "citizens" then
                if newData.vehicles ~= nil and #newData.vehicles > 0 then
                    for k, v in pairs(newData.vehicles) do
                        newData.vehicles[k].model = GetDisplayNameFromVehicleModel(v.model)
                    end
                end
            elseif active == "vehicles" then
                    if newData and #newData > 0 then
                        for k, v in pairs(newData) do
                            newData[k].model = GetDisplayNameFromVehicleModel(v.model)
                        end
                    end
                end
                
            cb(newData)
        end, data)
    end)

    RegisterNUICallback("GptAddData", function(data, cb)
        ESX.TriggerServerCallback("server-gpt-tirex:AddGptData", function(newData)
            cb(newData)
        end, data)
    end)

    RegisterNUICallback("DispatchGetData", function(data, cb)
        ESX.TriggerServerCallback("server-gpt-tirex:GetDispatchData", function(newData)
            if data.type == "getCoords" then
                SetNewWaypoint(newData.x, newData.y)
            end
            cb(newData)
        end, data)
    end)

    RegisterNetEvent('client-gpt-tirex:loadGptData')
    AddEventHandler('client-gpt-tirex:loadGptData', function(newData)
        for k, v in pairs(newData.data) do
            local asd, dsa = GetStreetNameAtCoord(v.coords.x, v.coords.y, v.coords.z, Citizen.ResultAsInteger(), Citizen.ResultAsInteger())
            newData.data[k].street = GetStreetNameFromHashKey(asd)
        end
        SendNUIMessage({type = 'LOAD_DISPATCH_DATA', ssn = newData.ssn, newData.data})
    end)
    -- Animation
    function startAnim()
        CreateThread(function()
          RequestAnimDict("amb@world_human_seat_wall_tablet@female@base")
          while not HasAnimDictLoaded("amb@world_human_seat_wall_tablet@female@base") do
            Citizen.Wait(0)
          end
            attachObject()
            TaskPlayAnim(PlayerPedId(), "amb@world_human_seat_wall_tablet@female@base", "base" ,8.0, -8.0, -1, 50, 0, false, false, false)
        end)
    end
    function attachObject()
        tab = Citizen.InvokeNative(0x509D5878EB39E842, GetHashKey("prop_cs_tablet"), 0, 0, 0, true, true, true)
        AttachEntityToEntity(tab, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), 57005), 0.17, 0.10, -0.13, 20.0, 180.0, 180.0, true, true, false, true, 1, true)
    end
    function stopAnim()
        StopAnimTask(PlayerPedId(), "amb@world_human_seat_wall_tablet@female@base", "base" ,8.0, -8.0, -1, 50, 0, false, false, false)
        DeleteEntity(tab)
    end
    
    RegisterNetEvent('client-gpt-tirex:openGpt')
    AddEventHandler('client-gpt-tirex:openGpt', function()
        if ESX.PlayerData.job and ((ESX.PlayerData.job.name == Config.JobName['police'].onDuty and Config.JobName['police'].toogle) or (ESX.PlayerData.job.name == Config.JobName['sheriff'].onDuty and Config.JobName['sheriff'].toogle) or (ESX.PlayerData.job.name == Config.JobName['doj'].onDuty and Config.JobName['doj'].toogle) or (ESX.PlayerData.job.name == Config.JobName['fib'].onDuty and Config.JobName['fib'].toogle)) then
            local acces = false
            if ESX.PlayerData.job.grade >= Config.JobName[ESX.PlayerData.job.name].menagmentGrade then
                acces = true
            end
            ESX.TriggerServerCallback("server-gpt-tirex:GetGptData", function(newData, jobData)
                if active == "main" then
                    for k, v in pairs(newData.vehicles) do
                        newData.vehicles[k].model = GetDisplayNameFromVehicleModel(v.model)
                    end
                elseif active == "vehicles" then
                    if #newData > 0 then
                        for k, v in pairs(newData) do
                            newData[k].model = GetDisplayNameFromVehicleModel(v.model)
                        end
                    end
                end
                startAnim()
                SetNuiFocus(true, true)
                SendNUIMessage({type = 'OPEN-GPT', acces = acces, patrolUnits = patrolUnits, jobData = jobData, newData})
            end, {active = active})
        end
    end)
    RegisterNetEvent('client-gpt-tirex:openDispatch')
    AddEventHandler('client-gpt-tirex:openDispatch', function()
        if ESX.PlayerData.job and ((ESX.PlayerData.job.name == Config.JobName['police'].onDuty and Config.JobName['police'].toogle) or (ESX.PlayerData.job.name == Config.JobName['sheriff'].onDuty and Config.JobName['sheriff'].toogle) or (ESX.PlayerData.job.name == Config.JobName['doj'].onDuty and Config.JobName['doj'].toogle) or (ESX.PlayerData.job.name == Config.JobName['fib'].onDuty and Config.JobName['fib'].toogle)) then
            ESX.TriggerServerCallback("server-gpt-tirex:GetDispatchData", function(newData)
                for k, v in pairs(newData.data) do
                    local asd, dsa = GetStreetNameAtCoord(v.coords.x, v.coords.y, v.coords.z, Citizen.ResultAsInteger(), Citizen.ResultAsInteger())
                    newData.data[k].street = GetStreetNameFromHashKey(asd)
                end
                SetNuiFocus(true, true)
                SendNUIMessage({type = 'OPEN_DISPATCH', ssn = newData.ssn, newData.data})
            end, {type = "getData"})
        end
    end)

    Citizen.CreateThread(function()
        TriggerEvent('chat:addSuggestion', '/'..Config.HelpCommand.name, '/'..Config.HelpCommand.name..' '..Config.HelpCommand.helpText,{ { name = Config.HelpCommand.helpText, help = Config.HelpCommand.helpTextOfArgs} })
        Wait(100)
        if #Config.CarList > 0 then
            CarsList = Config.CarList
        else
            CarsList = {"None"}
        end
        if #Config.UnitsType > 0 then
            patrolUnits = Config.UnitsType
        else
            patrolUnits = {"None"}
        end
        while true do
            Citizen.Wait(10)
            if ESX.PlayerData.job and ((ESX.PlayerData.job.name == Config.JobName['police'].onDuty and Config.JobName['police'].toogle) or (ESX.PlayerData.job.name == Config.JobName['sheriff'].onDuty and Config.JobName['sheriff'].toogle) or (ESX.PlayerData.job.name == Config.JobName['doj'].onDuty and Config.JobName['doj'].toogle) or (ESX.PlayerData.job.name == Config.JobName['fib'].onDuty and Config.JobName['fib'].toogle)) then
                if not onDuty then
                    onDuty = true
                    TriggerServerEvent("server-gpt-tirex:dutyChange", onDuty)
                end
                if Config.OpenOptions["gpt"].keyId ~= nil then
                    if IsControlJustReleased(1, Config.OpenOptions["gpt"].keyId) then
                        TriggerEvent('client-gpt-tirex:openGpt')
                    end
                end
                if Config.OpenOptions["dispatch"].keyId ~= nil then
                    if IsControlJustReleased(1, Config.OpenOptions["dispatch"].keyId) then
                        TriggerEvent('client-gpt-tirex:openDispatch')
                    end
                end
            elseif ESX.PlayerData.job and ((ESX.PlayerData.job.name == Config.JobName['police'].offDuty and Config.JobName['police'].toogle) or (ESX.PlayerData.job.name == Config.JobName['sheriff'].offDuty and Config.JobName['sheriff'].toogle) or (ESX.PlayerData.job.name == Config.JobName['doj'].offDuty and Config.JobName['doj'].toogle) or (ESX.PlayerData.job.name == Config.JobName['fib'].offDuty and Config.JobName['fib'].toogle)) then
                if onDuty then
                    onDuty = false
                    TriggerServerEvent("server-gpt-tirex:dutyChange", onDuty)
                end
            end
        end
    end)
end