Skip to content

Commit

Permalink
rf: use callback to set the players phone number
Browse files Browse the repository at this point in the history
-> avoids removing item if failed
  • Loading branch information
Maximus7474 committed Dec 21, 2024
1 parent 820ec26 commit ce1b505
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,12 +11,14 @@ 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({
app = "Settings",
title = T('NOTIFICATIONS.NUMBER_CHANGED.TITLE'),
content = T('NOTIFICATIONS.NUMBER_CHANGED.DESCRIPTION', {number = lbphone:FormatNumber(newNumber)}),
})

return true
end)
15 changes: 12 additions & 3 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ce1b505

Please sign in to comment.