cl_utils.lua

function Draw3DText(data)
    local text = data.text
    local x, y, z = data.coords.x, data.coords.y, data.coords.z

    local onScreen, screenX, screenY = World3dToScreen2d(x, y, z)
    if onScreen then
        local dist = #(GetGameplayCamCoord() - vector3(x, y, z))
        SendNUIMessage({
            action = "showInteract",
            label = text,
            keydisplay = data.keydisplay,
            x = screenX * 100,
            y = screenY * 100
        })
        visible = true
        lastDrawTick = GetGameTimer()
    else
        SendNUIMessage({ action = "hideInteract" })
    end
end

function GiveVehicleKey(plate, vehicle)
    TriggerServerEvent('qb-vehiclekeys:server:AcquireVehicleKeys', plate)
end

CreateThread(function()
    blipOpen = true
    if Config.StartJob.blip then
        JobBlip = AddBlipForCoord(Config.StartJob.coords.x, Config.StartJob.coords.y)
        SetBlipSprite(JobBlip, Config.StartJob.blip.sprite)
        SetBlipDisplay(JobBlip, 2)
        SetBlipScale(JobBlip, Config.StartJob.blip.scale)
        SetBlipColour(JobBlip, Config.StartJob.blip.color)
        SetBlipAsShortRange(JobBlip, true)
        BeginTextCommandSetBlipName("STRING")
        AddTextComponentString(Config.StartJob.blip.name)
        EndTextCommandSetBlipName(JobBlip)
    end
    RequestModel(Config.StartJob.ped)
    while not HasModelLoaded(Config.StartJob.ped) do Wait(10) end
    workerPed = CreatePed(0, Config.StartJob.ped, Config.StartJob.coords.x, Config.StartJob.coords.y, Config.StartJob.coords.z - 0.95, Config.StartJob.coords.w, false, false)
    FreezeEntityPosition(workerPed, true)
	SetEntityHeading(workerPed, Config.StartJob.coords.w)
	SetEntityInvincible(workerPed, true)
	SetBlockingOfNonTemporaryEvents(workerPed, true)
	TaskStartScenarioInPlace(workerPed, "WORLD_HUMAN_CLIPBOARD", 0, true)
    if Config.Interaction == "drawtext" then
        local sleep = 1000
        while true do
            if GetDistanceBetweenCoords(GetEntityCoords(PlayerPedId()), Config.StartJob.coords.x, Config.StartJob.coords.y, Config.StartJob.coords.z, true) < 30.0 then
                sleep = 1
            else
                sleep = 1000
            end
            if GetDistanceBetweenCoords(GetEntityCoords(PlayerPedId()), Config.StartJob.coords.x, Config.StartJob.coords.y, Config.StartJob.coords.z, true) < 2.0 then
                Draw3DText({
                    text = Config.locales[Config.Locale].game.access_menu,
                    coords = vec3(Config.StartJob.coords.x, Config.StartJob.coords.y, Config.StartJob.coords.z),
                })
                if IsControlJustReleased(0, 38) then
                    TriggerEvent('ak4y-transport:OpenMenu')
                end
            end
            Wait(sleep)
        end
    elseif Config.Interaction == "target" then
        exports["ak4y-core"]:AddEntityToTargeting(
            workerPed,
            Config.locales[Config.Locale].game.access_menu,
            "ak4y-transport:OpenMenu", nil, nil, 2.5
        )
    end
end)

function OnBoxAttach()
    TriggerServerEvent('ak4y-transport:AddTaskCount', 5, 1)
end

function OnBoxDetach()
    TriggerServerEvent('ak4y-transport:AddTaskCount', 6, 1)
end

function OnTieRope()
    TriggerServerEvent('ak4y-transport:AddTaskCount', 8, 1)
end

function UntieRope()
    TriggerServerEvent('ak4y-transport:AddTaskCount', 7, 1)
end

function DeliverVehicle(vehiclemodel)
    if vehiclemodel == "italirsx" then
        TriggerServerEvent('ak4y-transport:AddTaskCount', 3, 1)
    end

    TriggerServerEvent('ak4y-transport:AddTaskCount', 10, 1)
end

function DeliverItemInBox(itemModel)
    if itemModel == "ch_prop_ch_generator_01a" then
        TriggerServerEvent('ak4y-transport:AddTaskCount', 2, 1)
    end
end

function AddFinishJob(playersCount, jobType)
    if playersCount >= 2 then
        TriggerServerEvent('ak4y-transport:AddTaskCount', 1, 1)
    end

    if playersCount >= 3 then
        TriggerServerEvent('ak4y-transport:AddTaskCount', 9, 1)
    end

    TriggerServerEvent('ak4y-transport:AddTaskCount', 4, 1)
end

function NotifyFunc(text)
    exports["ak4y-core"]:NotifyViaFramework(text)
end

-- Stages = {
--     ["pallet"] = {
--         [1] = {
--             header = "Box Loading",
--             desc = "put boxes etc. etc.",
--             current = 0,
--             need = 6,            
--         },
--         [2] = {
--             header = "deliver to coord",
--             desc = "deliver to coord etc.",
--             current = 0,
--             need = 1,            
--         },
--         [3] = {
--             header = "Box Unloading",
--             desc = "unload boxes etc. etc.",
--             current = 0,
--             need = 6,            
--         },
--         [4] = {
--             header = "Deliver the items",
--             desc = "deliver items etc. etc.",
--             current = 0,
--             need = 6,            
--         },
--     },
--     ["vehicle"] = {
--         [1] = {
--             header = "vehicle Loading",
--             desc = "vehicle load etc. etc.",
--             current = 0,
--             need = 2,            
--         },
--         [2] = {
--             header = "deliver to coord",
--             desc = "deliver to coord etc.",
--             current = 0,
--             need = 1,            
--         },
--         [3] = {
--             header = "deliver vehicle",
--             desc = "vehicle deliver etc. etc.",
--             current = 0,
--             need = 2,            
--         },
--         [4] = {
--             header = "deliver to trailer",
--             desc = "deliver trailer to coord etc.",
--             current = 0,
--             need = 1,                
--         },
--     }
-- }

Last updated