first commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
local playerBlips = {}
|
||||
|
||||
local function removePlayerBlip(serverId)
|
||||
local blip = playerBlips[serverId]
|
||||
if blip and DoesBlipExist(blip) then RemoveBlip(blip) end
|
||||
playerBlips[serverId] = nil
|
||||
end
|
||||
|
||||
local function ensureBlip(entry)
|
||||
local serverId = tonumber(entry.serverId)
|
||||
if not serverId or serverId == GetPlayerServerId(PlayerId()) then return end
|
||||
|
||||
local blip = playerBlips[serverId]
|
||||
if not blip or not DoesBlipExist(blip) then
|
||||
blip = AddBlipForCoord(entry.x + 0.0, entry.y + 0.0, entry.z + 0.0)
|
||||
SetBlipSprite(blip, 1)
|
||||
SetBlipColour(blip, 3)
|
||||
SetBlipScale(blip, 0.82)
|
||||
SetBlipDisplay(blip, 2)
|
||||
SetBlipAsShortRange(blip, false)
|
||||
ShowHeadingIndicatorOnBlip(blip, true)
|
||||
playerBlips[serverId] = blip
|
||||
end
|
||||
|
||||
SetBlipCoords(blip, entry.x + 0.0, entry.y + 0.0, entry.z + 0.0)
|
||||
SetBlipRotation(blip, math.floor(tonumber(entry.heading) or 0.0))
|
||||
BeginTextCommandSetBlipName('STRING')
|
||||
AddTextComponentString(('%s [%s]'):format(entry.name or 'Spieler', serverId))
|
||||
EndTextCommandSetBlipName(blip)
|
||||
end
|
||||
|
||||
RegisterNetEvent('devx_players:client:sync', function(entries)
|
||||
local seen = {}
|
||||
for _, entry in ipairs(entries or {}) do
|
||||
local serverId = tonumber(entry.serverId)
|
||||
if serverId and serverId ~= GetPlayerServerId(PlayerId()) then
|
||||
seen[serverId] = true
|
||||
ensureBlip(entry)
|
||||
end
|
||||
end
|
||||
|
||||
for serverId in pairs(playerBlips) do
|
||||
if not seen[serverId] then removePlayerBlip(serverId) end
|
||||
end
|
||||
end)
|
||||
|
||||
AddEventHandler('onResourceStop', function(resourceName)
|
||||
if resourceName ~= GetCurrentResourceName() then return end
|
||||
for serverId in pairs(playerBlips) do removePlayerBlip(serverId) end
|
||||
end)
|
||||
@@ -0,0 +1,13 @@
|
||||
fx_version 'cerulean'
|
||||
game 'gta5'
|
||||
|
||||
author 'Colin-Joel / DevX Studios'
|
||||
description 'DevX RP player visibility and GTA Online-style map blips'
|
||||
version '0.4.3'
|
||||
|
||||
lua54 'yes'
|
||||
|
||||
client_script 'client/main.lua'
|
||||
server_script 'server/main.lua'
|
||||
|
||||
dependency 'devx_core'
|
||||
@@ -0,0 +1,37 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user