# LB Phone

If you are using the **LB Phone** and need to integrate it with the **Origen Inventory**, follow the steps below to ensure a proper integration. Please read carefully and proceed according to the specific information relevant to your setup.

### Step 1 - Installation

To complete the integration, you need to add the following files inside the LB Phone resource.

#### First file:

Go to the folder: `lb-phone/client/custom/uniquePhones`

{% file src="<https://3936778620-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPLI7NdIesJTaEUHH6a2U%2Fuploads%2FuYuo2qByS15RaQKuGRD0%2Forigen_inventory.lua?alt=media&token=dd09c4d3-3d61-4fe2-9bec-c60061d1910e>" %}

#### Second file:

Go to the folder: `lb-phone/server/custom/uniquePhones`

{% file src="<https://3936778620-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPLI7NdIesJTaEUHH6a2U%2Fuploads%2FYX7RhBkl7mqfRwlDcpDf%2Forigen_inventory.lua?alt=media&token=18945775-4a1a-427d-b5f7-aca675204574>" %}

### Step 2 - Integration

#### Client Side

Go to the file `lb-phone/client/custom/frameworks/(yourframework)/item.lua` , find this function `function HasItem(...)` and add this code in this file:

```lua
    elseif GetResourceState("origen_inventory") == "started" then
        return (exports.origen_inventory:Search("count", itemName) or 0) > 0
```

Check if the code looks like this form:

```lua
function HasItem(itemName)
    if GetResourceState("ox_inventory") == "started" then
        return (exports.ox_inventory:Search("count", itemName) or 0) > 0
    elseif GetResourceState("origen_inventory") == "started" then
        return (exports.origen_inventory:Search("count", itemName) or 0) > 0
    end

    return QB.Functions.HasItem(itemName)
end
```

#### Server Side

Go to the file `lb-phone/server/custom/frameworks/(yourframework)/qb.lua` , find this function `function HasItem(...)` and add this code on the file:

```lua
    elseif GetResourceState("origen_inventory") == "started" then
        return (exports.origen_inventory:getItemCount(source, itemName) or 0) > 0
```

Check if the code looks like this form:

```lua
function HasItem(source, itemName)
    if GetResourceState("ox_inventory") == "started" then
        return (exports.ox_inventory:Search(source, "count", itemName) or 0) > 0
    elseif GetResourceState("qs-inventory") == "started" then
        return (exports["qs-inventory"]:GetItemTotalAmount(source, itemName) or 0) > 0
    elseif GetResourceState("origen_inventory") == "started" then
        return (exports.origen_inventory:getItemCount(source, itemName) or 0) > 0
    end

    local qPlayer = QB.Functions.GetPlayer(tonumber(source))

    if not qPlayer then
        debugprint("HasItem: Failed to get player for source:", source)
        return false
    end

    return (qPlayer.Functions.GetItemByName(itemName)?.amount or 0) > 0
end
```

*Thanks for **PolDescomm** to find this solution for the code* :heart:

### Step 3 - Configuratión

Now, go to the file `lb-phone/config.lua` and look for the `Config.Item.Inventory` section. Replace the current inventory value with `origen_inventory` so that the **LB Phone** script can properly detect our inventory system.

```lua
Config.Item = {}
-- If you want to set up multiple items & frame colours, see https://docs.lbscripts.com/phone/configuration/#multiple-items--colored-phones
Config.Item.Require = true -- require a phone item to use the phone
--...(the rest of the code found in config.lua)

Config.Item.Inventory = "origen_inventory" --[[
```

**Now, follow the steps according to your server configuration needs:**

* **uniquePhones Enabled:**\
  When `uniquePhones` is enabled, you can have multiple functional phones in the inventory, each containing different information.\
  If you lose the phone item, you will also lose all the data stored inside it.\
  All information for each phone is saved within its corresponding item.
* **uniquePhones Disabled:**\
  When `uniquePhones` is disabled, any phone item in your inventory will display the same information as the first registered phone.\
  Even if you lose the phone item, your data will remain saved.\
  Once you obtain a new phone item, your previous information will still be accessible.

{% tabs %}
{% tab title="Unique Phones Activated" %}
If you are following this documentation, it means you plan to use the **Unique Phones** feature on your server. Therefore, you need to follow the steps below:

#### 1. Add the Item:

```lua
phone = {
    label = "Phone",
    weight = 190,
    stack = false,
    consume = 0,
    client = {
        export = "lb-phone.UsePhoneItem",
        add = function()
            TriggerEvent("lb-phone:itemAdded")
        end,
        remove = function()
            TriggerEvent("lb-phone:itemRemoved")
        end
    }
},

```

#### **2. Enable Unique Phones:**

Now, you need to enable the Unique Phones option in the `lb-phone/config.lua` file.\
Locate the `Config.Item.Unique` setting and set it to **true**:

```lua
Config.Item.Unique = true
```

Once done, restart your server.
{% endtab %}

{% tab title="Unique Phones Desactivated" %}
If you are following this documentation, it means you plan to don't use the **Unique Phones** feature on your server. Therefore, you need to follow the steps below:

#### 1. Add the Item:

```lua
phone = {
    label = "Phone",
    weight = 190,
    stack = false,
    consume = 0,
    client = {
        add = function()
            TriggerEvent("lb-phone:itemAdded")
        end,
        remove = function()
            TriggerEvent("lb-phone:itemRemoved")
        end
    }
},

```

#### **2. Disable Unique Phones:**

Now, you need to disable the Unique Phones option in the `lb-phone/config.lua` file.\
Locate the `Config.Item.Unique` setting and set it to **False**:

```lua
Config.Item.Unique = false
```

Once done, restart your server.
{% endtab %}
{% endtabs %}

Enjoy!! :smile:
