From 01117cc29a44d40caa9a7f2257a37999973f73eb Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Mon, 25 Mar 2024 20:05:47 +0100 Subject: [PATCH] refactor: (bpt_ballasjob) await callbacks --- .../[bpt_addons]/bpt_ballasjob/client/main.lua | 13 +++++-------- .../[bpt_addons]/bpt_ballasjob/server/main.lua | 6 ++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/server-data/resources/[bpt_addons]/bpt_ballasjob/client/main.lua b/server-data/resources/[bpt_addons]/bpt_ballasjob/client/main.lua index 0989b9ca1..54daffe87 100644 --- a/server-data/resources/[bpt_addons]/bpt_ballasjob/client/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_ballasjob/client/main.lua @@ -2,20 +2,17 @@ local HasAlreadyEnteredMarker local CurrentAction, CurrentActionMsg = 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) @@ -120,7 +117,7 @@ function OpenMobileBallasActionsMenu() end) end -AddEventHandler("bpt_ballasjob:hasEnteredMarker", function(zone) +RegisterNetEvent("bpt_ballasjob:hasEnteredMarker", function(zone) if zone == "BallasActions" then CurrentAction = "ballas_actions_menu" CurrentActionMsg = _U("press_to_open") @@ -128,7 +125,7 @@ AddEventHandler("bpt_ballasjob:hasEnteredMarker", function(zone) end end) -AddEventHandler("bpt_ballasjob:hasExitedMarker", function() +RegisterNetEvent("bpt_ballasjob:hasExitedMarker", function() ESX.CloseContext() CurrentAction = nil end) diff --git a/server-data/resources/[bpt_addons]/bpt_ballasjob/server/main.lua b/server-data/resources/[bpt_addons]/bpt_ballasjob/server/main.lua index 21968dffb..3c5ad8552 100644 --- a/server-data/resources/[bpt_addons]/bpt_ballasjob/server/main.lua +++ b/server-data/resources/[bpt_addons]/bpt_ballasjob/server/main.lua @@ -11,8 +11,7 @@ ESX.RegisterServerCallback("bpt_ballasjob:getPlayerInventory", function(source, }) end) -RegisterNetEvent("bpt_ballasjob:getStockItem") -AddEventHandler("bpt_ballasjob:getStockItem", function(itemName, count) +RegisterNetEvent("bpt_ballasjob:getStockItem", function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) if xPlayer.job.name == "ballas" then @@ -44,8 +43,7 @@ ESX.RegisterServerCallback("bpt_ballasjob:getStockItems", function(_, cb) end) end) -RegisterNetEvent("bpt_ballasjob:putStockItems") -AddEventHandler("bpt_ballasjob:putStockItems", function(itemName, count) +RegisterNetEvent("bpt_ballasjob:putStockItems", function(itemName, count) local xPlayer = ESX.GetPlayerFromId(source) local sourceItem = xPlayer.getInventoryItem(itemName)