# Usage

### Manual Export Function

```lua
exports["petris-lootbags"]:DropPlayerLootBag(playerId, bypass)
```

{% hint style="info" %}
The bypass parameter should be a boolean value. If true, it bypasses the whitelisted/blacklisted areas & IsPlayerLootable open function restrictions.
{% endhint %}

### Blacklisted Items Configuration

```lua
BlacklistedItems = {
        ["Items"] = {
            "id_card", 
            "driver_license",
        },
        ["Money"] = {
            "bank",
        },
        ["Weapons"] = {
            "WEAPON_STUNGUN",
        }
    },
```

{% hint style="info" %}
You can put any items/money types and weapons in your blacklisted inventory items list.
{% endhint %}

### Whitelisted/Blacklisted Areas Configuration

```lua
Locations = {
        ["System"] = "blacklisted", -- Possible Values: whitelisted | blacklisted (Define if you want to blacklisted areas and whitelist the other map locations or whitelist areas and block the other map locations)

        ["WhitelistedLocations"] = { -- The only locations where loot bags can be dropped
            { AreaName = "Test1", AreaCoordinates = vector3(0.0, 0.0, 0.0), AreaRange = 10.0 }, -- Area Name is not used, but it is recommended to fill so you know which areas are whitelisted.
            { AreaName = "Test2", AreaCoordinates = vector3(0.0, 0.0, 0.0), AreaRange = 5.0 } -- Area Name is not used, but it is recommended to fill so you know which areas are whitelisted.
        },

        ["BlacklistedLocations"] = { -- Location that loot bags won't be dropped even if the function is triggered.
            { AreaName = "Test1", AreaCoordinates = vector3(0.0, 0.0, 0.0), AreaRange = 10.0 }, -- Area Name is not used, but it is recommended to fill so you know which areas are blacklisted.
            { AreaName = "Test2", AreaCoordinates = vector3(0.0, 0.0, 0.0), AreaRange = 5.0 } -- Area Name is not used, but it is recommended to fill so you know which areas are blacklisted.
        },
    },
```

{% hint style="info" %}
Firstly, you must select how the location restriction system will work.\
\
In <mark style="background-color:red;">\["System"]</mark> value, change between <mark style="color:purple;">whitelisted</mark> and <mark style="color:purple;">blacklisted</mark> values.\
\
Then, you will add your own blacklisted/whitelisted locations just like the examples above.
{% endhint %}

### Define Lootable Players

```lua
IsPlayerLootable = function(playerId)
        --[[if Config["Framework"] == "ESX" then -- ESX Example: if player is not a simple user and has a permission group then don't drop his loot bag
            local xPlayer = ESX.GetPlayerFromId(playerId)
            if xPlayer.getGroup() ~= 'user' then
                return false
            end
        elseif Config["Framework"] == "QBCore" then -- QBCore Example: if player's permission is admin then don't drop his loot bag
            if QBCore.Functions.HasPermission(playerId, 'admin') then
                return false
            end
        end--]]
        return true
    end,
```

{% hint style="info" %}
There is already a built-in check which checks if the player is staff. So, when the player is a server's staff the loot bag will not spawn upon his death. You can add your own restrictions there, freely.
{% endhint %}

### Allow/Block Players From Collecting

```lua
CanPlayerCollectBag = function()
        if Config["Framework"] == "ESX" then -- ESX Example: if player is working for ambulance, he can't pick-up the bag.
            if ESX.PlayerLoaded then
                if ESX.PlayerData.job and ESX.PlayerData.job.name == "ambulance" then
                    return false
                end
            end 
        elseif Config["Framework"] == "QBCore" then -- QBCore Example: if player is working for ambulance, he can't pick-up the bag.
            local PlayerData = QBCore.Functions.GetPlayerData()
            local jobName = PlayerData.job.name
            if jobName == 'ambulance' then
                return false
            end
        end
        return true
    en
```

{% hint style="info" %}
There is already a built-in check which checks if the player is working for the ambulance. You can freely remove or change this restriction as was added as an example.
{% endhint %}
