# Installation

## Before Starting

Installation and download processes are straightforward and fixed. After following the specified steps, you can easily complete the installation. <mark style="color:purple;">**Skipping a small step can lead to significant errors in the future!**</mark>

{% hint style="danger" %}
**If you get an error, and if the error located in errors page, support it will take much longer for you to get a reply.**

\
**If you don't modify configurations file, support it will take much longer for you to get a reply.**
{% endhint %}

## Installation

Extract **ls-inventory** from the downloaded folder and install it on your server.

{% hint style="warning" %}
If the downloaded file has a different name than <mark style="color:yellow;">ls-inventory</mark>, rename it to <mark style="color:yellow;">ls-inventory</mark> or it will not work and errors will occur!
{% endhint %}

After installing it on your server, import the SQL database named <mark style="color:yellow;">**"ls\_inventory.sql"**</mark> into your server's database.

{% hint style="warning" %}
*Before starting, make sure you're started <mark style="color:yellow;">ls-</mark>*<mark style="color:yellow;">inventory</mark> *after <mark style="color:yellow;">ls-core</mark> start. If you dont, start <mark style="color:yellow;">ls-</mark>*<mark style="color:yellow;">inventory</mark> *after <mark style="color:yellow;">ls-core</mark>.*
{% endhint %}

## Requirements

{% hint style="danger" %}
Do not skip any requirements. It's will errors in future!
{% endhint %}

First, make sure that the specified resources have been downloaded and installed on your server;

<table><thead><tr><th width="228">Script</th><th>Download</th></tr></thead><tbody><tr><td>ls-core</td><td><a href="https://github.com/LquenS/ls-core">https://github.com/LquenS/ls-core</a></td></tr><tr><td>ls-weapons</td><td><a href="https://github.com/LquenS/ls-weapons">https://github.com/LquenS/ls-weapons</a></td></tr></tbody></table>

## Framework

### QB-CORE

{% hint style="success" %}
If you're using newest qb-core, replace all <mark style="color:yellow;">\["qb-inventory"]</mark> exports with <mark style="color:yellow;">\["ls-inventory"]</mark> and, locate <mark style="color:yellow;">"self.Functions.SetPlayerData"</mark> and replace whole function with,

{% code overflow="wrap" %}

```lua
function self.Functions.SetPlayerData(key, val)
        if not key or type(key) ~= 'string' then return end
        self.PlayerData[key] = val
        if key == 'items' then exports["ls-inventory"]:SetMainItems(self.PlayerData.source, val) end
        self.Functions.UpdatePlayerData()
end
```

{% endcode %}

<mark style="color:yellow;">Thats it, there is no more requirements for change!</mark>
{% endhint %}

If you're using old qb-core version <mark style="color:yellow;">"before inventory update"</mark>, find <mark style="color:yellow;">**qb-core/server/player.lua**</mark>**&#x20;after that locate these functions.**

<details>

<summary><mark style="color:yellow;"><strong>Functions Required Change</strong></mark></summary>

Locate <mark style="color:yellow;">"self.Functions.AddItem"</mark> and replace whole function with,

```lua
function self.Functions.AddItem(item, amount, slot, info)
    return exports["ls-inventory"]:AddItem(self.PlayerData.source, item, amount, slot, info)
end
```

Locate <mark style="color:yellow;">"self.Functions.RemoveItem"</mark> and replace whole function with,

```lua
function self.Functions.RemoveItem(item, amount, slot)
    return exports["ls-inventory"]:RemoveItem(self.PlayerData.source, item, amount, slot)
end
```

Locate <mark style="color:yellow;">"self.Functions.GetItemBySlot"</mark> and replace whole function with,

```lua
function self.Functions.GetItemBySlot(slot)
    return exports["ls-inventory"]:GetItemBySlot(self.PlayerData.source, slot)
end
```

Locate <mark style="color:yellow;">"self.Functions.GetItemByName"</mark> and replace whole function with,

```lua
function self.Functions.GetItemByName(item)
    return exports["ls-inventory"]:GetItemByName(self.PlayerData.source, item)
end
```

Locate <mark style="color:yellow;">"self.Functions.GetItemsByName"</mark> and replace whole function with,

```lua
function self.Functions.GetItemsByName(item)
    return exports["ls-inventory"]:GetItemsByName(self.PlayerData.source, item)
end
```

Locate <mark style="color:yellow;">"self.Functions.ClearInventory"</mark> and replace whole function with,

```lua
function self.Functions.ClearInventory()
    exports["ls-inventory"]:ClearInventory(self.PlayerData.source)
end
```

Locate <mark style="color:yellow;">"self.Functions.SetInventory"</mark> and replace whole function with,

```lua
function self.Functions.SetInventory(items)
    -exports["ls-inventory"]:SetInventory(self.PlayerData.source, items)
end
```

</details>

<figure><img src="https://659240559-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FczUkA5Hbzqn9UHvFLUEY%2Fuploads%2F5zLMUxIE0UF3Y74jnGs6%2Fimage.png?alt=media&#x26;token=35412e9e-bda6-4d77-bc78-fab43b4d1c39" alt=""><figcaption><p>After doing changes, its needs to look like.</p></figcaption></figure>

{% hint style="success" %}
After doing these steps everything is done!
{% endhint %}

### ESX

ESX, installation is really basic, first find <mark style="color:yellow;">**es\_extended/server/classes/player.lua**</mark>**&#x20;after that locate these functions.**

<details>

<summary><mark style="color:yellow;"><strong>Functions Required Change</strong></mark></summary>

Locate <mark style="color:yellow;">"self.addInventoryItem"</mark> and replace whole function with,

```lua
function self.addInventoryItem(name, count, metadata, slot)
    return exports["ls-inventory"]:AddItem(self.source, name, count, slot, metadata)
end
```

Locate <mark style="color:yellow;">"self.removeInventoryItem"</mark> and replace whole function with,

```lua
function self.removeInventoryItem(name, count, metadata, slot)
    return exports["ls-inventory"]:RemoveItem(self.source, name, count, slot)
end
```

Locate <mark style="color:yellow;">"self.getInventoryItem"</mark> and replace whole function with,

```lua
function self.getInventoryItem(name, metadata)
    return exports["ls-inventory"]:GetItemByName(self.source, name)
end
```

Locate <mark style="color:yellow;">"self.hasItem"</mark> and replace whole function with,

```lua
function self.hasItem(item)
    return exports["ls-inventory"]:HasItem(self.source, item, 1)
end
```

</details>

<figure><img src="https://659240559-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FczUkA5Hbzqn9UHvFLUEY%2Fuploads%2FyDuB3F34OyIqNemcTzuz%2Fimage.png?alt=media&#x26;token=2370cf1b-1e2d-4609-86d7-cdc376a3720c" alt=""><figcaption><p>After doing changes, its needs to look like.</p></figcaption></figure>

{% hint style="danger" %}
Newest ESX versions added item check to their code. This means if you use newest version of ESX you cannot use most items if you want to use all items,

Find <mark style="color:yellow;">**es\_extended/server/functions.lua**</mark>**&#x20;after that l**ocate <mark style="color:yellow;">"ESX.UseItem"</mark> and replace whole function with,

{% code overflow="wrap" %}

```lua
function ESX.UseItem(source, item, ...)
  --if ESX.Items[item] then
    local itemCallback = Core.UsableItemsCallbacks[item]

    if itemCallback then
      local success, result = pcall(itemCallback, source, item, ...)

      if not success then
        return result and print(result) or
                 print(('[^3WARNING^7] An error occured when using item ^5"%s"^7! This was not caused by ESX.'):format(item))
      end
    end
  --else
  --  print(('[^3WARNING^7] Item ^5"%s"^7 was used but does not exist!'):format(item))
  --end
end
```

{% endcode %}
{% endhint %}

<figure><img src="https://659240559-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FczUkA5Hbzqn9UHvFLUEY%2Fuploads%2FskaPLFauqXnB56IvE759%2Fimage.png?alt=media&#x26;token=461ac5d5-2375-4bd1-925b-f9ead452f56f" alt=""><figcaption><p>After doing changes, its needs to look like.</p></figcaption></figure>

{% hint style="success" %}
After doing these steps everything is done!
{% endhint %}
