Issue sending to all connected clients


#1

I believe my issue is simple and maybe just a typo at this point, am just hoping someone can spot an error to help me get the below working. I am not recieving any errors at this point, nor any of the traces, and yes the files are loaded in __resource.lua.
Running timer on server then sending to all clients a random set of coords to be marked on map and route drawn.
server.lua

local playerslist = {}
local clockcount = 0
local blips = {
    {id=153, x=-246.511 , y=6331.07 , z=32.4262},
    {id=153, x=1826.7 , y=3693.3 , z=34.2242},
    {id=153, x=-664.961 , y=308.31 , z=83.0841},
    {id=153, x=-874.672 , y=-306.777 , z=39.5658},
    {id=153, x=293.059 , y=-584.493 , z=43.1915},
    {id=153, x=405.394 , y=-1420.13 , z=29.4453},
    {id=153, x=1106.35 , y=-1477.55 , z=34.6925},
    {id=153, x=-347.167 , y=-362.721 , z=31.5574},
    {id=153, x=1640.1759 , y=2528.6689 , z=45.56486},
    {id=153, x=-473.026 , y=-338.344 , z=35.202},
}
Citizen.CreateThread(function()
    while true do
    Citizen.Wait(1)
    clockcount = clockcount + 1
        if clockcount == 3000 then
        Citizen.Trace("New LOC"..clockcount)
        --anotherloc = TriggerEvent("zDays:sendloc")
        outbreakloc = blips[math.random(1,#blips)]
            TriggerClientEvent('zDays:getloc', -1, outbreakloc)
            clockcount = 0
        end
    end
end)

client.lua

local playerslist = {}
local bliplist = {}
    RegisterNetEvent("zDays:getloc")
    AddEventHandler("zDays:getloc", function(loc)
    --local X, Y, Z = table.unpack(GetEntityCoords(PlayerPedId(), true))TriggerServerEvent("zDays:sendloc")
    outbreakloc = loc
        for blips in pairs(bliplist) do
            RemoveBlip(blips)
        end
    bliplist = {}
    setloc(outbreakloc)
    Citizen.Trace("Tracking LOC#" ..outbreakloc.."")
    end)
    function setloc(loc)
        hotloc.x, hotloc.y, hotloc.z = table.unpack(loc)
        hotzone = AddBlipForRadius(hotloc.x, hotloc.y, hotloc.z, 200.0)
        SetBlipColour(hotzone, 1)
        SetBlipAlpha(hotzone, 100)
        SetBlipRoute(hotzone, true)
        if not has_value(bliplist, hotzone) then
        table.insert(bliplist, hotzone)
        Citizen.Trace("New LOC#" ..hotzone.."")
        --else
        end
    end

#2

I don’t really see an issue, but your server script is needlessly complex.

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(3000)
        TriggerClientEvent('zDays:getloc', -1, blips[math.random(1,#blips)])
    end
end)

#3

I am finally pulling an error, with adding your trim down. Its telling me the random blip is returning nil. I can not unpack this table any more ways lol. I am at a loss.


#4

That’s because you have too many values in the table, not just x,y,z.
Just make it easier on yourself and do something like this:

function setloc(loc)
        hotzone = AddBlipForRadius(loc.x, loc.y, loc.z, 200.0)
        SetBlipColour(hotzone, 1)
        SetBlipAlpha(hotzone, 100)
        SetBlipRoute(hotzone, true)
        if not has_value(bliplist, hotzone) then
            table.insert(bliplist, hotzone)
        end
    end

#5

Thank you again for a reply @SaltyGrandpa . Oddly enough the solution was to rewrite the table. This is not the solution i wanted because now i have 2 version of all my tables, just formated differently. I just could not get it to read that table.

server.lua

local blips = {
    {-328.156 , 6085.16 , 31.4548},
    {1695.69 , 3761.02 , 34.7053}
}
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(60000*math.random(7,14))
        thisblipis = blips[math.random(1,#blips)]
        thisblip.x, thisblip.y, thisblip.z = table.unpack(thisblipis)
        TriggerClientEvent('zDays:startsim', -1, {thisblip.x, thisblip.y, thisblip.z})      
    end
end)

client.lua

coords = {}
loc = {}
local objNameDist = 1000
    RegisterNetEvent("zDays:startsim")
    AddEventHandler("zDays:startsim", function(coords)
    loc.x, loc.y, loc.z = table.unpack(coords)
    ShowNotification("LOC recieved:\n" .. loc.x.." "..loc.y)
    end)
Citizen.CreateThread(function()        
        while true do
        Citizen.Wait(3000)
        if loc ~= nil then
            playerX, playerY, playerZ = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
            distObj = math.floor(GetDistanceBetweenCoords(playerX,  playerY,  playerZ,  loc.x, loc.y, loc.z,  true))
            if distObj ~= nil and objNameDist ~= nil and ((distObj < objNameDist)) then
            startinfectionsim = true
            else
            startinfectionsim = false
            end
        end
        end
    end)