38 lines
1.2 KiB
Lua
38 lines
1.2 KiB
Lua
local function buildSnapshots()
|
|
local byBucket = {}
|
|
local activePlayers = exports.devx_core:GetActivePlayers()
|
|
|
|
for source, player in pairs(activePlayers) do
|
|
source = tonumber(source)
|
|
local ped = GetPlayerPed(source)
|
|
if ped and ped > 0 and DoesEntityExist(ped) then
|
|
local coords = GetEntityCoords(ped)
|
|
local bucket = GetPlayerRoutingBucket(source)
|
|
byBucket[bucket] = byBucket[bucket] or {}
|
|
byBucket[bucket][#byBucket[bucket] + 1] = {
|
|
serverId = source,
|
|
name = player.fullName or GetPlayerName(source) or ('Spieler %s'):format(source),
|
|
x = coords.x,
|
|
y = coords.y,
|
|
z = coords.z,
|
|
heading = GetEntityHeading(ped)
|
|
}
|
|
end
|
|
end
|
|
|
|
return byBucket, activePlayers
|
|
end
|
|
|
|
CreateThread(function()
|
|
while true do
|
|
Wait(1500)
|
|
local snapshots, activePlayers = buildSnapshots()
|
|
|
|
for source in pairs(activePlayers) do
|
|
source = tonumber(source)
|
|
local bucket = GetPlayerRoutingBucket(source)
|
|
TriggerClientEvent('devx_players:client:sync', source, snapshots[bucket] or {})
|
|
end
|
|
end
|
|
end)
|