From 4b783dbffd95fe69b465582356fd025dbedf0baf Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Mon, 25 Mar 2024 19:58:34 +0100 Subject: [PATCH] refactor: (bpt_bakerjob) await callbacks --- .../[bpt_addons]/bpt_bakerjob/client/main.lua | 13 +++++-------- .../[bpt_addons]/bpt_bakerjob/server/main.lua | 6 ++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/server-data/resources/[bpt_addons]/bpt_bakerjob/client/main.lua b/server-data/resources/[bpt_addons]/bpt_bakerjob/client/main.lua index 3e4bc2a26..527269352 100644 --- a/server-data/resources/[bpt_addons]/bpt_bakerjob/client/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_bakerjob/client/main.lua @@ -2,20 +2,17 @@ local HasAlreadyEnteredMarker local CurrentAction, CurrentActionMsg, CurrentActionData = nil, "", {} local LastZone -RegisterNetEvent("esx:playerLoaded") -AddEventHandler("esx:playerLoaded", function(xPlayer) +RegisterNetEvent("esx:playerLoaded", function(xPlayer) ESX.PlayerData = xPlayer ESX.PlayerLoaded = true end) -RegisterNetEvent("esx:onPlayerLogout") -AddEventHandler("esx:onPlayerLogout", function() +RegisterNetEvent("esx:onPlayerLogout", function() ESX.PlayerLoaded = false ESX.PlayerData = {} end) -RegisterNetEvent("esx:setJob") -AddEventHandler("esx:setJob", function(job) +RegisterNetEvent("esx:setJob", function(job) ESX.PlayerData.job = job end) @@ -255,7 +252,7 @@ function IsInAuthorizedVehicle() return false end -AddEventHandler("bpt_bakerjob:hasEnteredMarker", function(zone) +RegisterNetEvent("bpt_bakerjob:hasEnteredMarker", function(zone) if zone == "VehicleSpawner" then CurrentAction = "vehicle_spawner" CurrentActionMsg = _U("spawner_prompt") @@ -282,7 +279,7 @@ AddEventHandler("bpt_bakerjob:hasEnteredMarker", function(zone) end end) -AddEventHandler("bpt_bakerjob:hasExitedMarker", function() +RegisterNetEvent("bpt_bakerjob:hasExitedMarker", function() ESX.CloseContext() CurrentAction = nil end) diff --git a/server-data/resources/[bpt_addons]/bpt_bakerjob/server/main.lua b/server-data/resources/[bpt_addons]/bpt_bakerjob/server/main.lua index ca2c119a4..a615abf94 100644 --- a/server-data/resources/[bpt_addons]/bpt_bakerjob/server/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_bakerjob/server/main.lua @@ -28,8 +28,7 @@ ESX.RegisterServerCallback("bpt_bakerjob:SpawnVehicle", function(source, cb, mod cb() end) -RegisterNetEvent("bpt_bakerjob:getStockItem") -AddEventHandler("bpt_bakerjob:getStockItem", function(itemName, count) +RegisterNetEvent("bpt_bakerjob:getStockItem", function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) if xPlayer.job.name == "baker" then @@ -61,8 +60,7 @@ ESX.RegisterServerCallback("bpt_bakerjob:getStockItems", function(_, cb) end) end) -RegisterNetEvent("bpt_bakerjob:putStockItems") -AddEventHandler("bpt_bakerjob:putStockItems", function(itemName, count) +RegisterNetEvent("bpt_bakerjob:putStockItems", function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) local sourceItem = xPlayer.getInventoryItem(itemName)