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.

We recommend using ox_inventory (opens in a new tab) or qb-inventory (opens in a new tab).

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

Update config

Set Config.Item.Unique and Config.Item.Require to true in the LB Phone config.

Optionally set Config.Item.Inventory to "ox_inventory".

Add the phone item to ox_inventory

⚠️
If you already have an item called phone, you have to replace it

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

ox_inventory/data/items.lua
["phone"] = {
    label = "Phone",
    weight = 190,
    stack = false,
    consume = 0
},

Remove the npwd integration

Open ox_inventory/items/client.lua and search for Item('phone'.

Remove the following code block:

Item('phone', function(data, slot)
	local success, result = pcall(function()
		return exports.npwd:isPhoneVisible()
	end)
 
	if success then
		exports.npwd:setPhoneVisible(not result)
	end
end)

Restart your server

Restart your server to apply the changes.

qb-inventory

This guide is for qb-inventory 2.0.0

Update config

Set Config.Item.Unique and Config.Item.Require 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'
},

Restart your server

Restart your server to apply the changes.

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
A phone number is always a string

We recommend looking at the ox_inventory.lua files for reference. These can be found in lb-phone/client/custom/uniquePhones/ox_inventory.lua and lb-phone/server/custom/uniquePhones/ox_inventory.lua.

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 unique phones are 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

this will ensure that the code only runs if the inventory is set to inventory-name, unique phones are enabled, and the item is required.

Implement client functions

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

  • GetFirstNumber(): string? - Returns the first phone number in the player's inventory, or nil if no phone with a number is found.
  • HasPhoneNumber(phoneNumber: string?): boolean - Checks if the user has a phone item with the given phone number. If the phoneNumber argument is nil, that means you should check if the player has a phone item without a number assigned to it. Return true or false.

Implement client item logic

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

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(phoneNumber, true).

if currentPhone then
    return
end
 
local firstPhoneNumber = GetFirstNumber()
 
SetPhone(firstPhoneNumber, 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. If the phoneNumber argument is nil, check if the player has a phone item without a number assigned to it. 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.