Skip to content

updated #26

@Robg815

Description

@Robg815

Updated to prevent it from showing till player is loaded for qbcore/qbox

cl_render.lua

local vec = vec
local Wait = Citizen.Wait
local format = string.format
local RemoveBlip = RemoveBlip
local PlayerPedId = PlayerPedId
local IsHudHidden = IsHudHidden
local IsPauseMenuActive = IsPauseMenuActive
local IsScreenFadedOut = IsScreenFadedOut
local IsCinematicCamRendering = IsCinematicCamRendering
local SetTextFont = SetTextFont
local SetTextScale = SetTextScale
local SetTextOutline = SetTextOutline
local GetEntityCoords = GetEntityCoords
local EndTextCommandDisplayText = EndTextCommandDisplayText
local BeginTextCommandDisplayText = BeginTextCommandDisplayText
local AddTextComponentSubstringPlayerName = AddTextComponentSubstringPlayerName

local nearestPostalText = ""
local playerLoaded = false

RegisterNetEvent("QBCore:Client:OnPlayerLoaded", function()
playerLoaded = true
end)

RegisterNetEvent("QBCore:Client:OnPlayerUnload", function()
playerLoaded = false
end)

Citizen.CreateThread(function()
while postals == nil do Wait(1) end

local delay = math.max(config.updateDelay and tonumber(config.updateDelay) or 300, 50)
if not delay or tonumber(delay) <= 0 then
    error("Invalid render delay provided, it must be a number > 0")
end

local postals = postals
local deleteDist = config.blip.distToDelete
local formatTemplate = config.text.format
local _total = #postals

while true do
    if playerLoaded then
        local coords = GetEntityCoords(PlayerPedId())
        local _nearestIndex, _nearestD
        coords = vec(coords[1], coords[2])

        for i = 1, _total do
            local D = #(coords - postals[i][1])
            if not _nearestD or D < _nearestD then
                _nearestIndex = i
                _nearestD = D
            end
        end

        if pBlip and #(pBlip.p[1] - coords) < deleteDist then
            TriggerEvent('chat:addMessage', {
                color = { 255, 0, 0 },
                args = {
                    'Postals',
                    "You've reached your postal destination!"
                }
            })
            RemoveBlip(pBlip.hndl)
            pBlip = nil
        end

        local _code = postals[_nearestIndex].code
        nearest = { code = _code, dist = _nearestD }
        nearestPostalText = format(formatTemplate, _code, _nearestD)
    end
    Wait(delay)
end

end)

Citizen.CreateThread(function()
local posX = config.text.posX
local posY = config.text.posY
local _string = "STRING"
local _scale = 0.42
local _font = 4
while true do
if playerLoaded
and nearest
and not IsHudHidden()
and not IsPauseMenuActive()
and not IsScreenFadedOut()
and not IsCinematicCamRendering() then

        SetTextScale(_scale, _scale)
        SetTextFont(_font)
        SetTextOutline()
        BeginTextCommandDisplayText(_string)
        AddTextComponentSubstringPlayerName(nearestPostalText)
        EndTextCommandDisplayText(posX, posY)
    end
    Wait(0)
end

end)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions