From 72e26d64e7d911e74592e063b336057e7eb82c65 Mon Sep 17 00:00:00 2001 From: Linden Date: Thu, 22 Jul 2021 10:19:12 +1000 Subject: [PATCH] fix(police): Add events for playerLoaded/onPlayerLogout; SetTimeout on restart --- [esx_addons]/esx_policejob/client/main.lua | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/[esx_addons]/esx_policejob/client/main.lua b/[esx_addons]/esx_policejob/client/main.lua index 26ffe26c..6266689c 100644 --- a/[esx_addons]/esx_policejob/client/main.lua +++ b/[esx_addons]/esx_policejob/client/main.lua @@ -3,10 +3,17 @@ local HasAlreadyEnteredMarker, isDead, isHandcuffed, hasAlreadyJoined, playerInS local LastStation, LastPart, LastPartNum, LastEntity, CurrentAction, CurrentActionMsg dragStatus.isDragged, isInShopMenu = false, false -if ESX.PlayerLoaded and ESX.PlayerData.job == 'police' then - Citizen.Wait(1000) - TriggerServerEvent('esx_policejob:forceBlip') -end +RegisterNetEvent('esx:playerLoaded') +AddEventHandler('esx:playerLoaded', function(xPlayer) + ESX.PlayerData = xPlayer + ESX.PlayerLoaded = true +end) + +RegisterNetEvent('esx:onPlayerLogout') +AddEventHandler('esx:onPlayerLogout', function() + ESX.PlayerLoaded = false + ESX.PlayerData = {} +end) function cleanPlayer(playerPed) SetPedArmour(playerPed, 0) @@ -1562,3 +1569,9 @@ function ImpoundVehicle(vehicle) ESX.ShowNotification(_U('impound_successful')) currentTask.busy = false end + +if ESX.PlayerLoaded and ESX.PlayerData.job == 'police' then + SetTimeout(1000, function() + TriggerServerEvent('esx_policejob:forceBlip') + end) +end \ No newline at end of file