From ce1b505c0a2a273a62067e0b97bb32364258eed0 Mon Sep 17 00:00:00 2001 From: Maximus7474 Date: Sat, 21 Dec 2024 19:41:46 +0100 Subject: [PATCH] rf: use callback to set the players phone number -> avoids removing item if failed --- client/main.lua | 6 ++++-- server/main.lua | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/client/main.lua b/client/main.lua index 733d248..64572ba 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,6 +1,6 @@ local lbphone = exports['lb-phone'] -RegisterNetEvent('lbphonesim:changingsimcard', function (newNumber) +lib.callback.register('lbphonesim:changingsimcard', function (newNumber) if lbphone:IsOpen() then lbphone:ToggleOpen(false, false) end @@ -11,7 +11,7 @@ RegisterNetEvent('lbphonesim:changingsimcard', function (newNumber) end) if not status then lib.print.error(T('DEBUG.SETTING_NUMBER_FAILED'), err) - return + return err end lbphone:SendNotification({ @@ -19,4 +19,6 @@ RegisterNetEvent('lbphonesim:changingsimcard', function (newNumber) title = T('NOTIFICATIONS.NUMBER_CHANGED.TITLE'), content = T('NOTIFICATIONS.NUMBER_CHANGED.DESCRIPTION', {number = lbphone:FormatNumber(newNumber)}), }) + + return true end) \ No newline at end of file diff --git a/server/main.lua b/server/main.lua index f96bdfa..7698b50 100644 --- a/server/main.lua +++ b/server/main.lua @@ -13,8 +13,6 @@ if Inventory.RegisterItemCB then if Config.SimCard.ReplaceSimCardNumber then Inventory.UpdateSimCardNumber(source, slot, currentNumber) - elseif Config.SimCard.DeleteSimCard then - Inventory.RemoveItem(source, slot) end local success = false if Config.Item.Unique then @@ -36,7 +34,18 @@ if Inventory.RegisterItemCB then success = rows == 1 end - if success then TriggerClientEvent('lbphonesim:changingsimcard', source, newNumber or Utils.GenerateNewNumber()) end + if not success then return end + + lib.callback('lbphonesim:changingsimcard', source, function (response) + if response == true then + if Config.SimCard.DeleteSimCard then + Inventory.RemoveItem(source, slot) + end + return + end + + lib.print.error('Unable to change phone number for ' .. source .. ', failed with error:', response) + end, newNumber or Utils.GenerateNewNumber()) end ) elseif Framework.RegisterUsableItem then