Prevent Citizen.CreateThread from spamming a certain function

So I have a drug script, and I want to be able for the server to detect the time on every tick & if it is a certain time in the “CITY” then the markers will appear and a chat message will be added. The markers appear… everything works… but the chat and notification script spam. I want the server to read the time and draw markers on every tick, but I don’t want it to add chat message and notify every tick.

Can anyone help me with this :)? Thanks
P.S. I am new to this, but I am very capable & have been giving it my all.

Client Side LUA

Citizen.CreateThread(function()

while true do 

    Citizen.Wait(0)

    local player = {

        ped = PlayerPedId(),

        coords = GetEntityCoords(PlayerPedId())

    }

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

        for a,b in pairs(v) do 

            if (firstIteration) then

                SetupBlips(b.Blip)

            end

            local location = b.Location

            local marker = b.Marker

            local hour = GetClockHours()

            local minute = GetClockMinutes()

            if (hour >= 11 and hour <=15) then

                asd()

                DrawMarker(marker.Type, location.x, location.y, location.z, 0, 0, 0, 0, 0, 0, marker.Size.x, marker.Size.y, marker.Size.z, marker.RGBA[1], marker.RGBA[2], marker.RGBA[3], marker.RGBA[4], 0, 1, 0, 0)

                if allowedToInteract and #(player.coords - location) < marker.Size.x + (marker.Size.x * 0.25) then 

                    ESX.ShowHelpNotification(b.HelpText)

                    if (IsControlJustPressed(1, 51)) then 

                        AttemptInteraction(k, a)

                    end

                end

            end

        end

    end

    firstIteration = false

end

end)

function asd()

hour = GetClockHours()

minute = GetClockMinutes()

if (hour >= 11 and hour <=15) then

    local redzone = AddBlipForRadius( 1216.7, -3280.86, 5.5, 451.0)

    SetBlipHighDetail(redzone, true)

    SetBlipColour(redzone, 1)

    SetBlipAlpha (redzone, 128)

    --TriggerEvent('chat:addMessage', {

        --color = { 255, 0, 0},

        --multiline = true,

        --args = {"Me", "Please be careful to not step on too many snails!"}

      --})

    TriggerEvent('chat:addMessage', {

        template = '<div style="padding: 0.5vw; margin: 0.5vw; background-color: rgba(220,172,235, 0.6); border-radius: 3px;"><i class="fa-solid fa-truck"></i> {0}:<br> {1}</div>',

        args = {"Pablo Escobar", "Drug delivered. No Man's Land access authorized. 💊💊"}

    })

    Citizen.Wait(1000)

    exports['t-notify']:Alert({

        style = 'Info', 

        sound = true,

        message = 'No Man\'s Land is now active'

    })

end

end

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.