Server

You don't need to change functions like AddItem, RemoveItem, GetItemByName or etc in your other scripts, you can use qb's and esx's functions

GetPlayerItems

exports["tgiann-inventory"]:GetPlayerItems(src)

Return :

valuetype

player items

table

Parameters :

NameTypeDescription

src*

int

Player Source

Example

local src = source
local playerItems = exports["tgiann-inventory"]:GetPlayerItems(src)

GetPlayerClotheItems

exports["tgiann-inventory"]:GetPlayerClotheItems(src)

Return :

valuetype

Player clothe items

table

Parameters :

NameTypeDescription

src*

int

Player Source

Example

local src = source
local playerClotheItems = exports["tgiann-inventory"]:GetPlayerClotheItems(src)

GetTotalWeight

exports["tgiann-inventory"]:GetTotalWeight(items)

Return :

valuetype

weight

int

Parameters :

NameTypeDescription

items*

table

İtem list with amount

Example

local items = {
    ["1"] = { item = "bandage", amount = 5},
    ["4"] = { item = "arrow", amount = 2},
}
local weight = exports["tgiann-inventory"]:GetTotalWeight(items)
return weight < 10

AddItem

exports["tgiann-inventory"]:AddItem(source, item, amount, slot, metadata, isClotheSlot)

Return :

valuetype

success

boolen

Parameters :

NameTypeDescription

source*

table

Player source

item*

string

item spawn name

amount*

int

the amount of item to add

slot

int

slot number

metadata

table

metadata of the item modify

isClotheSlot

boolen

adds item to clothe slots

Example

local src = source
local metadata = {
    level = 2
}
local success = exports["tgiann-inventory"]:AddItem(src, "bandage", 2, nil, metadata, false)
if success then
    print("item added")
end

RemoveItem

exports["tgiann-inventory"]:RemoveItem(source, item, amount, keyName)

Return :

valuetype

success

boolen

Parameters :

NameTypeDescription

source*

table

Player source

item*

string

item spawn name

amount*

int

the amount of item to add

slot

iny

slot number

Example

local src = source
local itemData = exports["tgiann-inventory"]:GetItemByName(src, "bandage")
if itemData.amount > 0 then
    local success = exports["tgiann-inventory"]:RemoveItem(src, "bandage", 1, itemData.key)
    if success then
        print("item added")
    end
end

CanGiveItems

exports["tgiann-inventory"]:CanGiveItems(source, item, amount)

Return :

valuetype

success

boolen

Parameters :

NameTypeDescription

source

int

Player source

item*

string

item spawn name

amount*

int

the amount of item to check

Example

local src = source
local canGive = exports["tgiann-inventory"]:CanGiveItems(src, "bandage", 100)
if canGive then
    exports["tgiann-inventory"]:AddItem(src, "bandage", 100)
end

ClearInventory

exports["tgiann-inventory"]:ClearInventory(source)

Return : None

Parameters :

NameTypeDescription

source

int

Player source


GetItemByName

exports["tgiann-inventory"]:GetItemByName(source, item)

Return :

valuetype

Player Items

table

Parameters :

NameTypeDescription

source

int

Player source

item

string

Item spawn name

Example

local src = source
local itemData = exports["tgiann-inventory"]:GetItemByName(src, "bandage")
if itemData.amount > 0 then
    exports["tgiann-inventory"]:RemoveItem(src, "bandage", itemData.amount)
end

GetItemBySlot

exports["tgiann-inventory"]:GetItemBySlot(source, slot)

Return :

valuetype

Player Items

Table

Parameters :

NameTypeDescription

source

int

Player source

slot

int

Slot number

Example

local src = source
local keyName = "tgi_001_bandage"
local itemData = exports["tgiann-inventory"]:GetItemBySlot(src, slot)
if itemData.amount > 0 then
    exports["tgiann-inventory"]:RemoveItem(src, itemData.name, itemData.amount)
end

HasItem

exports["tgiann-inventory"]:HasItem(src, items, amount)

Return :

valuetype

Player has the item

boolen

Parameters :

NameTypeDescription

src*

int

Player source

items*

table or string

The items to check, either a string, array of strings or a key-value table of a string and number with the string representing the name of the item and the number representing the amount

amount

int

The amount of the item to check for, this will only have effect when items is a string or an array of strings

Example

local src = source
local has1 = exports["tgiann-inventory"]:HasItem(src, "bandage", 2)
local has2 = exports["tgiann-inventory"]:HasItem(src, {"bandage", "armor"}, 2)

RepairWeapon

exports["tgiann-inventory"]:RepairWeapon(src, slot, value)

Return :

valuetype

Is success

boolen

Parameters :

NameTypeDescription

src*

int

Player source

slot*

int

Slot number

value

int

Repair values. Mix: 0, Max 100

Example

local src = source
local playerItems = exports["tgiann-inventory"]:GetPlayerItems(src)
for slot, itemData in pairs(playerItems) do
    if item.name == "weapon_pistol" then
        exports["tgiann-inventory"]:RepairWeapon(src, slot, 100)
    end
end

CreateCustomStashWithItem

Custom creates stash inventory

exports["tgiann-inventory"]:createCustomStashWithItem(stashUniqId, items)

Return :

valuetype

stashUniqId

string

items

item list

Parameters :

NameTypeDescription

stashUniqId

string

Stash name

items

table

item list

Example

--Server
local items = {
    {
        name = "bandage"
        amount = 2,
    },
    {
        name = "waeapon_pistol"
        amount = 2,
        info = {
            ammo = 500
        }
    },
}
exports["tgiann-inventory"]:createCustomStashWithItem("airdrop_1", items)

--Client
TriggerServerEvent("tgiann-inventory:server:OpenInventory", "stash", "airdrop_1")

GetItemByNameFromSecondInventory

Returns the data of the item in the stash

exports["tgiann-inventory"]:GetItemByNameFromSecondInventory(source, item)

Return :

valuetype

Stash Items

table

Parameters :

NameTypeDescription

stashId*

string

Stash uniq name

item

string

Item spawn name

Example

local src = source
local itemData = exports["tgiann-inventory"]:GetItemByNameFromSecondInventory("airdrop_01", "bandage")
return itemData.amount > 0

RemoveItemFromSecondInventory

Deletes items from stash

exports["tgiann-inventory"]:RemoveItemFromSecondInventory(stashId, item, amount, slot)

Return :

valuetype

success

boolen

Parameters :

NameTypeDescription

stashId*

string

Stash uniq name

item*

string

item spawn name

amount*

int

the amount of item to add

slot

int

Slot number

Example

local src = source
local stashId = "airdrop_01"
local itemData = exports["tgiann-inventory"]:GetItemByNameFromSecondInventory(stashId, "bandage")
if itemData.amount > 0 then
    local success = exports["tgiann-inventory"]:RemoveItemFromSecondInventory(stashId, "bandage", 1, itemData.slot)
    if success then
        print("item added")
    end
end

UpdateItemMetadata

Updates the item's info data

exports["tgiann-inventory"]:UpdateItemMetadata(src, item, slot, metadata)

Return : None

Parameters :

NameTypeDescription

src*

string

Stash uniq name

item*

string

item spawn name

slot*

string

Slot number

metadata*

table

Item new metadata

Example

local src = source
local itemData = exports["tgiann-inventory"]:GetItemByName(src, "weapon_pistol")
local newMetadata = {
    ammo = 200
}
exports["tgiann-inventory"]:UpdateItemMetadata(src, "weapon_pistol", itemData.slot, newMetadata)

DeleteInventory

deletes all data of the inventory

exports["tgiann-inventory"]:DeleteInventory(invType, invId)

Return : None

Parameters :

NameTypeDescription

invType*

string

trunk, glovebox, stash

invId*

string

Inventory uniq name or plate

Example

exports["tgiann-inventory"]:DeleteInventory("stash", "airdrop_01")
exports["tgiann-inventory"]:DeleteInventory("glovebox", "TL001TL")

GiveClotheItem

exports["tgiann-inventory"]:GiveClotheItem(src, model, itemName, data, isClotheSlot)

Return : None

Parameters :

NameTypeDescription

src*

int

Player source

model*

int

Player model (joaat("mp_f_freemode_01") or joaat("mp_m_freemode_01") )

itemName*

string

Clothe items

data*

table

Clothes data

isClotheSlot

bool

Add the item to the clothing slot

Example

local src = source
local model = joaat("mp_f_freemode_01")

--[[
    1: Mask 
    3: Arms
    4: Pants
    5: bag 
    6: Shoes 
    7: Accessory 
    8: Tshirt
    9: Kevlar 
    10: Decals 
    11: Torso
]]--

exports["tgiann-inventory"]:GiveClotheItem(src, model, "c_shoes", {
    ["6"] = { --shoes
        Prop = 26,
        Texture = 0
    }
}, false)

cexports["tgiann-inventory"]:GiveClotheItem(src, model, "c_torso", {
    ["3"] = { --arms
        Prop = 3,
        Texture = 0
    },
    ["8"] = { --Tshirt
        Prop = 14,
        Texture = 0
    },
    ["11"] = { --Torso
        Prop = 60,
        Texture = 0
    }
}, false)

exports["tgiann-inventory"]:GiveClotheItem(src, model, "c_pants", {
    ["4"] = { --pants
        Prop = 39,
        Texture = 0
    },
}, false)

Last updated