Skip to content

Commit

Permalink
Update v1.3.3
Browse files Browse the repository at this point in the history
* Performance Improvements
  • Loading branch information
Musiker15 committed Feb 24, 2024
1 parent 953c574 commit 56ab9cc
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 72 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.2
1.3.3
108 changes: 48 additions & 60 deletions client.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local isActivated = false
local Blips, activeBlips = {}, {}

AddEventHandler('esx:onPlayerDeath', function(data)
AddEventHandler('esx:onPlayerDeath', function()
TriggerServerEvent('msk_jobGPS:setDeath')
end)

Expand Down Expand Up @@ -65,34 +65,28 @@ addBlips = function(GPS, Player, heading)
logging('debug', 'addBlips')

if not Player then
while not ESX.PlayerData.job do Wait(0) end
for playerId, v in pairs(GPS) do
logging('debug', job, playerId, v)
-- v = xPlayer, playerPed, netId, heading
local xPlayer = v.xPlayer

for job, ids in pairs(GPS) do
if ESX.PlayerData.job.name == job then
for playerId, v in pairs(ids) do
logging('debug', job, playerId, v)
-- v = xPlayer, playerPed, netId, heading
local xPlayer = v.xPlayer
if ESX.PlayerData.identifier ~= xPlayer.identifier then
local blip = AddBlipForCoord(xPlayer.coords.x, xPlayer.coords.y, xPlayer.coords.z)

if ESX.PlayerData.identifier ~= xPlayer.identifier then
local blip = AddBlipForCoord(xPlayer.coords.x, xPlayer.coords.y, xPlayer.coords.z)
SetBlipSprite(blip, Config.GPS.blip.id)
SetBlipScale(blip, Config.GPS.blip.scale)
SetBlipColour(blip, Config.GPS.blip.color)

SetBlipSprite(blip, Config.GPS.blip.id)
SetBlipScale(blip, Config.GPS.blip.scale)
SetBlipColour(blip, Config.GPS.blip.color)
ShowNumberOnBlip(blip, playerId)
ShowHeadingIndicatorOnBlip(blip, true)
SetBlipRotation(blip, v.heading)

ShowNumberOnBlip(blip, playerId)
ShowHeadingIndicatorOnBlip(blip, true)
SetBlipRotation(blip, v.heading)
BeginTextCommandSetBlipName('STRING')
AddTextComponentString(('%s'):format(xPlayer.name))
EndTextCommandSetBlipName(blip)

BeginTextCommandSetBlipName('STRING')
AddTextComponentString(('%s'):format(xPlayer.name))
EndTextCommandSetBlipName(blip)

table.insert(Blips, {blip = blip, source = playerId})
activeBlips[playerId] = {isActive = false, blip = blip}
end
end
table.insert(Blips, {blip = blip, source = playerId})
activeBlips[playerId] = {isActive = false, blip = blip}
end
end
else
Expand Down Expand Up @@ -131,48 +125,42 @@ end

refreshBlips = function(GPS)
logging('debug', 'refreshBlips')
while not ESX.PlayerData.job do Wait(0) end

for job, ids in pairs(GPS) do
if ESX.PlayerData.job.name == job then
for playerId, v in pairs(ids) do
-- v = xPlayer, netId, heading
local xPlayer = v.xPlayer
for playerId, v in pairs(GPS) do
-- v = xPlayer, netId, heading
local xPlayer = v.xPlayer

if ESX.PlayerData.identifier ~= xPlayer.identifier then
if not activeBlips[playerId] then addBlips(GPS, xPlayer, v.heading) end

logging('debug', 'Blip is active')
local inOneSync = inOneSync(v.netId)

if ESX.PlayerData.identifier ~= xPlayer.identifier then
if not activeBlips[playerId] then addBlips(GPS, xPlayer, v.heading) end

logging('debug', 'Blip is active')
local inOneSync = inOneSync(v.netId)

if inOneSync and not activeBlips[playerId].isActive then
logging('debug', 'inOneSync')

CreateThread(function()
activeBlips[playerId].isActive = true

while activeBlips[playerId] and activeBlips[playerId].isActive and DoesEntityExist(inOneSync.ped) do
local coords = GetEntityCoords(inOneSync.ped)
local heading = math.ceil(GetEntityHeading(inOneSync.ped))

SetBlipCoords(activeBlips[playerId].blip, coords.x, coords.y, coords.z)
SetBlipRotation(activeBlips[playerId].blip, heading)

Wait(0)
end
end)
elseif not inOneSync then
logging('debug', 'not inOneSync')
activeBlips[playerId].isActive = false

SetBlipCoords(activeBlips[playerId].blip, v.coords.x, v.coords.y, v.coords.z)
SetBlipRotation(activeBlips[playerId].blip, v.heading)
if inOneSync and not activeBlips[playerId].isActive then
logging('debug', 'inOneSync')

CreateThread(function()
activeBlips[playerId].isActive = true

while activeBlips[playerId] and activeBlips[playerId].isActive and DoesEntityExist(inOneSync.ped) do
local coords = GetEntityCoords(inOneSync.ped)
local heading = math.ceil(GetEntityHeading(inOneSync.ped))

SetBlipCoords(activeBlips[playerId].blip, coords.x, coords.y, coords.z)
SetBlipRotation(activeBlips[playerId].blip, heading)

Wait(0)
end
end
end)
elseif not inOneSync then
logging('debug', 'not inOneSync')
activeBlips[playerId].isActive = false

SetBlipCoords(activeBlips[playerId].blip, v.coords.x, v.coords.y, v.coords.z)
SetBlipRotation(activeBlips[playerId].blip, v.heading)
end
end
end
end
end

inOneSync = function(netId)
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ games { 'gta5' }
author 'Musiker15 - MSK Scripts'
name 'msk_jobGPS'
description 'Creates Blips for all players at the same job if they activate there gps'
version '1.3.2'
version '1.3.3'

shared_script {
'@es_extended/imports.lua',
Expand Down
34 changes: 24 additions & 10 deletions server.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local GPS = {}
local playerJobs = {}

AddEventHandler('onResourceStart', function(resource)
if GetCurrentResourceName() == resource then
Expand Down Expand Up @@ -46,7 +47,7 @@ togglePanicbutton = function(source)
end

if not GPS[xPlayer.job.name][xPlayer.source] then canUseItem = false end
if not canUseItem then return Config.Notification(src, 'Panicbutton does not work now') end
if not canUseItem then return Config.Notification(src, 'You have to active GPS first') end

local xPlayers = ESX.GetExtendedPlayers('job', xPlayer.job.name)
for k, xTarget in pairs(xPlayers) do
Expand All @@ -63,22 +64,23 @@ ESX.RegisterUsableItem(Config.GPS.item, function(source)

if not isAllowed(xPlayer, 'gps') then return end

if GPS[xPlayer.job.name][xPlayer.source] then
if GPS[xPlayer.job.name][src] then
Config.Notification(src, 'GPS deactivated')
xPlayer.triggerEvent('msk_jobGPS:deactivateGPS')
removeBlipById(xPlayer)
else
local playerPed = GetPlayerPed(xPlayer.source)
local playerPed = GetPlayerPed(src)

GPS[xPlayer.job.name][xPlayer.source] = {
playerJobs[src] = xPlayer.job.name
GPS[playerJobs[src]][src] = {
xPlayer = xPlayer,
netId = NetworkGetNetworkIdFromEntity(playerPed),
coords = GetEntityCoords(playerPed),
heading = math.ceil(GetEntityHeading(playerPed))
}

Config.Notification(src, 'GPS activated')
xPlayer.triggerEvent('msk_jobGPS:activateGPS', GPS)
xPlayer.triggerEvent('msk_jobGPS:activateGPS', GPS[playerJobs[src]])
end
end)

Expand Down Expand Up @@ -131,7 +133,6 @@ CreateThread(function()
while true do
local sleep = Config.GPS.refresh * 1000

-- New Way to refresh PlayerData
for job, players in pairs(GPS) do
for playerId, info in pairs(players) do
-- info = xPlayer, netId, heading
Expand All @@ -142,22 +143,35 @@ CreateThread(function()
end
end

local xPlayers = ESX.GetExtendedPlayers()
for k, xPlayer in pairs(xPlayers) do
if GPS[xPlayer.job.name] and GPS[xPlayer.job.name][xPlayer.source] then
TriggerClientEvent('msk_jobGPS:refreshBlips', xPlayer.source, GPS)
for k, playerId in pairs(GetPlayers()) do
local playerJob = getPlayerJob(playerId)

if GPS[playerJob] and GPS[playerJob][playerId] then
TriggerClientEvent('msk_jobGPS:refreshBlips', playerId, GPS[playerJob])
end
end

Wait(sleep)
end
end)

getPlayerJob = function(playerId)
if playerJobs[playerId] then
return playerJobs[playerId]
end

local xPlayer = ESX.GetPlayerFromId(playerId)
playerJobs[playerId] = xPlayer.job.name

return playerJobs[playerId]
end

removeBlipById = function(xPlayer)
local source, job = xPlayer.source, xPlayer.job.name

if GPS[job] and GPS[job][source] then
GPS[job][source] = nil
playerJobs[source] = nil

for playerId, v in pairs(GPS[job]) do
TriggerClientEvent('msk_jobGPS:deactivateGPSById', playerId, source)
Expand Down

0 comments on commit 56ab9cc

Please sign in to comment.