Spam Alert

If you have this alert spam error, we present you the cause and the solution, so follow the step by step instructions to solve this small problem.

client.lua
RegisterNetEvent('ramdomscript:client:fight')
AddEventHandler('ramdomscript:client:fight', function()
    local playerData = exports['qs-dispatch']:GetPlayerInfo()

    if (not playerData) then
        ErrorPrint("Error getting player data")
        return
    end

    exports['qs-dispatch']:getSSURL(function(image)
        TriggerServerEvent('qs-dispatch:server:CreateDispatchCall', {
            job = { 'police', 'sheriff', 'traffic', 'patrol' },
            callLocation = playerData.coords,
            callCode = { code = 'Hight Speed', snippet = 'Vehicle' },
            message = " street_1: " ..
            playerData.street_1 ..
            " street_2: " ..
            playerData.street_2 ..
            " sex: " ..
            playerData.sex ..
            " vehicle_label: " ..
            playerData.vehicle_label ..
            " vehicle_colour: " ..
            playerData.vehicle_colour ..
            " vehicle_plate: " .. playerData.vehicle_plate .. " speed: " .. playerData.speed .. "",
            flashes = false,
            image = image or nil,
            blip = {
                sprite = 488,
                scale = 1.5,
                colour = 1,
                flashes = true,
                text = 'Hight Speed',
                time = (20 * 1000), --20 secs
            }
        })
    end)
end)

This problem happens because when calling the client function 'ramdomscript:client:fight' as an example from a server code, they are setting the value of -1, so this will make a call of the alert for each player on the server.

server.lua
RegisterCommand('test', function ()
    TriggerClientEvent('ramdomscript:client:fight', -1)
end)

OR

server.lua
RegisterCommand('test', function(source, args, rawCommand)
    local xPlayers = ESX.GetExtendedPlayers() -- Returns all xPlayers
    for _, xPlayer in pairs(xPlayers) do
        if player.job.name == 'police' then -- Send event TO ALL POLICES CONNECTED
            TriggerClientEvent('ramdomscript:client:fight', xPlayer.source)
        end
    end
end, false)

Last updated