Added blips for cops, closes #4

This commit is contained in:
ElPumpo
2018-04-05 12:32:36 +02:00
parent 442bcbd730
commit aed4db306e
2 changed files with 103 additions and 1 deletions
+59 -1
View File
@@ -23,6 +23,8 @@ local CurrentActionData = {}
local IsHandcuffed = false
local IsDragged = false
local CopPed = 0
local hasAlreadyJoined = false
local blipsCops = {}
ESX = nil
GUI.Time = 0
@@ -1211,7 +1213,10 @@ end)
RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
PlayerData.job = job
PlayerData.job = job
Citizen.Wait(5000)
TriggerServerEvent('esx_policejob:forceBlip')
end)
RegisterNetEvent('esx_phone:loaded')
@@ -1794,3 +1799,56 @@ Citizen.CreateThread(function()
end
end)
function createBlip(id)
ped = GetPlayerPed(id)
blip = GetBlipFromEntity(ped)
if not DoesBlipExist(blip) then -- Add blip and create head display on player
blip = AddBlipForEntity(ped)
SetBlipSprite(blip, 1)
Citizen.InvokeNative(0x5FBCA48327B914DF, blip, true) -- Player Blip indicator
SetBlipRotation(blip, math.ceil(GetEntityHeading(veh))) -- update rotation
SetBlipNameToPlayerName(blip, id) -- update blip name
SetBlipScale(blip, 0.85) -- set scale
SetBlipAsShortRange(blip, true)
table.insert(blipsCops, blip) -- add blip to array so we can remove it later
end
end
RegisterNetEvent('esx_policejob:updateBlip')
AddEventHandler('esx_policejob:updateBlip', function()
-- Refresh all blips
for k, existingBlip in pairs(blipsCops) do
RemoveBlip(existingBlip)
end
-- Clean the blip table
blipsCops = {}
ESX.TriggerServerCallback('esx_policejob:isCop', function(isCop)
if isCop then
ESX.TriggerServerCallback('esx_society:getOnlinePlayers', function(players)
for i=1, #players, 1 do
if players[i].job.name == 'police' then
for id = 0, 32 do
if NetworkIsPlayerActive(id) and GetPlayerPed(id) ~= GetPlayerPed(-1) and GetPlayerName(id) == players[i].name then
createBlip(id)
end
end
end
end
end)
end
end) -- You don't need to specify source
end)
AddEventHandler('playerSpawned', function(spawn)
if not hasAlreadyJoined then
TriggerServerEvent('esx_policejob:spawned')
end
hasAlreadyJoined = true
end)
+44
View File
@@ -458,3 +458,47 @@ ESX.RegisterServerCallback('esx_policejob:getPlayerInventory', function(source,
})
end)
AddEventHandler('playerDropped', function()
-- Save the source in case we lose it (which happens a lot)
local _source = source
-- Did the player ever join?
if _source ~= nil then
local xPlayer = ESX.GetPlayerFromId(_source)
-- Is it worth telling all clients to refresh?
if xPlayer ~= nil and xPlayer.job ~= nil and xPlayer.job.name == 'police' then
Citizen.Wait(5000)
TriggerClientEvent('esx_policejob:updateBlip', -1)
end
end
end)
RegisterServerEvent('esx_policejob:spawned')
AddEventHandler('esx_policejob:spawned', function()
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
if xPlayer ~= nil and xPlayer.job ~= nil and xPlayer.job.name == 'police' then
Citizen.Wait(5000)
TriggerClientEvent('esx_policejob:updateBlip', -1)
end
end)
RegisterServerEvent('esx_policejob:forceBlip')
AddEventHandler('esx_policejob:forceBlip', function()
TriggerClientEvent('esx_policejob:updateBlip', -1)
end)
ESX.RegisterServerCallback('esx_policejob:isCop', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
cb(xPlayer ~= nil and xPlayer.job ~= nil and xPlayer.job.name == 'police')
end)
AddEventHandler('onResourceStart', function(resource)
if resource == GetCurrentResourceName() then
Citizen.Wait(5000)
TriggerClientEvent('esx_policejob:updateBlip', -1)
end
end)