Unique phones

Unique Phones

Unique phones is a feature on LB Phone that allows you to make each phone item have a unique phone number. This allows people to steal and share their phones, but requires an inventory with metadata support.

Supported inventories

An inventory with metadata is enough, but not all inventories are supported out of the box. If your inventory is not supported, see custom inventory for a guide on how to implement it yourself.

ox_inventory

ox_inventory (opens in a new tab) is the recommended inventory for unique phones.

Update config

Set Config.Item.Unique to true in the LB Phone config. Optionally set Config.Item.Inventory to "ox_inventory".

Add item to ox_inventory

Add the following to ox_inventory/data/items.lua. If you already have an item called "phone", replace the data.

⚠️
Do not add this if you don't use unique phones
ox_inventory/data/items.lua
["phone"] = {
    label = "Phone",
    weight = 190,
    stack = false,
    consume = 0,
    client = {
        export = "lb-phone.UsePhoneItem",
        remove = function()
            TriggerEvent("lb-phone:itemRemoved")
        end,
        add = function()
            TriggerEvent("lb-phone:itemAdded")
        end
    }
},

qb-inventory

This guide is for qb-inventory 2.0.0

Update config

Set Config.Item.Unique to true in the LB Phone config. Optionally set Config.Item.Inventory to "qb-inventory".

Update items data

Open qb-core/shared/items.lua and search for phone. Replace it with the following:

qb-core/shared/items.lua
phone = {
    name = 'phone',
    label = 'Phone',
    weight = 190,
    type = 'item',
    image = 'phone.png',
    unique = true,
    useable = true,
    shouldClose = true,
    description = 'LB Phone'
},

Screenshot of before and after.

Add item events

Go to qb-inventory/server/main.lua and find the AddItem function. Add the following to the end of the function, before return true:

qb-inventory/server/main.lua
if player and item == "phone" then
    TriggerClientEvent('lb-phone:itemAdded', player.PlayerData.source)
end

Then find the RemoveItem function and add the following to the end of the function, before return true:

qb-inventory/server/main.lua
if player and item == "phone" then
    TriggerClientEvent('lb-phone:itemRemoved', player.PlayerData.source)
end

Screenshot of before and after.

Custom inventory

⚠️
This guide requires coding experience. We will not assist you in adding custom inventories.
Replace inventory-name with the name of your inventory

We recommend looking at the ox_inventory.lua files for reference.

Update config

Set Config.Item.Unique to true in the LB Phone config, and set Config.Item.Inventory to "inventory-name".

Create files

Create a file called inventory-name.lua in lb-phone/client/custom/uniquePhones/ and lb-phone/server/custom/uniquePhones/

Check if enabled

Add the following to the top of both files:

if Config.Item.Inventory ~= "inventory-name" or not Config.Item.Unique or not Config.Item.Require then
    return
end

Implement client functions

The following functions need to be implemented in the client file:

  • GetFirstNumber() - Returns the first phone number in the player's inventory, or nil
  • HasPhoneNumber(number) - Checks if the user has a phone item with the given number. Return true or false.

Implement client item logic

When using a phone item, call SetPhone(number, true) to set the phone number. Then call ToggleOpen(not phoneOpen)

When a phone item is removed from the player's inventory, check if it is the currently equipped phone. If it is, call SetPhone().

if currentPhone and not HasPhoneItem(currentPhone) then
    SetPhone()
end

When a phone item is added to the player's inventory and the player doesn't have a phone, call SetPhone(number, true).

if currentPhone then
    return
end
 
local firstNumber = GetFirstNumber()
 
SetPhone(firstNumber, true)

Implement server functions

The following functions need to be implemented in the server file:

  • HasPhoneNumber(source, phoneNumber) - Check if the source has an item with the specificied number. Return true or false.
  • SetPhoneNumber(source, phoneNumber) - Set the number of a player's empty phone item. Return true or false
  • SetItemName(source, phoneNumber, name) - (optional) Here you can add metadata to the phone item to show the name and phone number.