Exports
This section lists all client-side and server-side exports in this script. Exports can be called from other scripts to interact with this script functionality.
Note
If you need additional exports for your implementation, please open a ticket on our Discord server.
Client Exports
GetVehicleCapacity
Returns the capacity of a vehicle.
local capacity = exports['hex_4_inventory']:GetVehicleCapacity(spawncode, isGlove)Prop
Type
CloseInventory
Closes the inventory for the player.
exports['hex_4_inventory']:CloseInventory()LockInventory
Locks the inventory for the player. This can be used to prevent to open the inventory.
exports['hex_4_inventory']:LockInventory(state)Prop
Type
OpenTrunk
Trys to open the trunk inventory for the vehicle in front of the player.
exports['hex_4_inventory']:OpenTrunk()OpenGlove
Trys to open the glovebox only works if the player is in a vehicle returning a bool whether the glovebox was opened or not.
local success = exports['hex_4_inventory']:OpenGlove()enableHotbar
Enables or disables the hotbar keys, for example while the player is in a minigame or an event where they should not be able to pull items or weapons.
exports['hex_4_inventory']:enableHotbar(state)Prop
Type
Note
This export only exists when the hotbar addon is turned on in addons/config/hotbar/config.lua.
Server Exports
OpenInventory
Opens the inventory for a player and decides what is shown on each of the two sides.
inventoryData is either a single inventory, which is placed on the right side with the
player's own inventory on the left, or a table with left and right to decide both sides
yourself. A side you leave out always falls back to the player's own inventory, so at least
one of the two has to be something else.
local success = exports['hex_4_inventory']:OpenInventory(playerId, inventoryData)
-- a fraction inventory on the right, the players own inventory on the left
local playerObject = GetPlayerObject(source)
local job = GetPlayerJob(playerObject)
exports['hex_4_inventory']:OpenInventory(playerId, {
id = ('fraction_%s'):format(job.name),
type = 'fraction',
title = ('Fraction Inventory: %s'):format(job.label),
weight = false
})
-- a trunk, plate, title and weight are taken from the vehicle and your config
exports['hex_4_inventory']:OpenInventory(playerId, {
type = 'trunk',
netId = netId
})
-- a trunk on the left and a fraction inventory on the right
exports['hex_4_inventory']:OpenInventory(playerId, {
left = { type = 'trunk', netId = netId },
right = {
id = 'fraction_police',
type = 'fraction',
title = 'Police Storage',
weight = 500
}
})
-- a fraction inventory on the left and the players own inventory on the right
exports['hex_4_inventory']:OpenInventory(playerId, {
left = {
id = 'fraction_police',
type = 'fraction',
title = 'Police Storage',
weight = 500
},
right = { type = 'main' }
})Prop
Type
Inventory fields
These are the fields of a single inventory, no matter whether you pass it directly or as
left / right.
Prop
Type
Inventory types
| Type | Description |
|---|---|
main | The player's own inventory. Only useful in the left / right form to put it on a specific side. |
trunk | The trunk of a vehicle. Address the vehicle with netId, vehicle or the plate, everything else is resolved from it. |
glovebox | Same as trunk, just the glovebox of the vehicle. |
player | Another player's inventory, id is their server id. The distance check of 5.0 still applies. |
| anything else | Your own inventory. It is stored in the database under that type and id, so pick a stable id like fraction_police. |
Note
drop is reserved for items lying on the ground and cannot be opened through this export.
GetInventory
Returns the inventoryData for a specific inventory.
local inventory = exports['hex_4_inventory']:GetInventory(playerObject, inventoryData)Prop
Type
AddItemToInventory
Adds an item to a specific inventory.
local success = exports['hex_4_inventory']:AddItemToInventory(playerId, playerObject, itemData, count, inventoryData)Prop
Type
RemoveItemFromInventory
Removes an item to a specific inventory.
exports['hex_4_inventory']:RemoveItemFromInventory(playerObject, itemData, count, inventoryData, cb)Prop
Type
ChangeInventoryPlate
Changes the plate of a vehicle inventory. This can be used when a player changes the plate of their vehicle to also update the inventory id.
exports['hex_4_inventory']:ChangeInventoryPlate(oldPlate, newPlate)Prop
Type
ClearInventory
Removes everything from an inventory, optionally keeping a few things in it. Returns whether the inventory was found and cleared.
local success = exports['hex_4_inventory']:ClearInventory(inventoryType, inventoryId, itemsToKeep)
-- empty a fraction inventory completely
exports['hex_4_inventory']:ClearInventory('fraction', 'fraction_police')
-- empty the trunk of a vehicle but leave the water and the pistols in it
exports['hex_4_inventory']:ClearInventory('trunk', 'ABC123', {
'water',
'WEAPON_PISTOL'
})Prop
Type
Note
Only inventories that are currently loaded can be cleared, otherwise false is returned. An
inventory is loaded the first time it gets opened after a restart, or as soon as you call
GetInventory for it. Every player who has it open sees the change right away and it is
written to the database the same way a normal change is.
AddHook
Adds a hook to the inventory script. Hooks can be used to cancel certain actions by returning false in the callback function.
Available Hooks
| Event | Arguments | Description |
|---|---|---|
hex_4_inventory:giveInventoryItem | playerId, target, itemType, itemName, itemCount | Triggered when a player tries to give an item to another player via the give button. |
hex_4_inventory:removeItem | playerId, item, count, extraData | Triggered when a player tries to remove an item from an inventory (e.g., by dropping it on the ground if no drop is nearby, or by placing it). |
hex_4_inventory:moveItemToOther | playerId, item, count, invData | Triggered when a player tries to move an item out of their own inventory into the other one. invData is the inventory it goes into. |
hex_4_inventory:moveItemToPlayer | playerId, item, count, invData | Triggered when a player tries to move an item out of the other inventory into their own. invData is the inventory it comes from. |
hex_4_inventory:moveItemBetween | playerId, item, count, fromInv, toInv | Triggered when a player tries to move an item between two inventories where neither of them is their own, e.g. from a trunk into a fraction inventory. |
hex_4_inventory:getOtherInventory | data | Triggered every time the contents of an inventory that is not the player's own one are sent to them. Besides denying it this one can also change what they get to see, see below. |
Note
Which side an inventory is shown on does not decide which hook runs. moveItemToOther and
moveItemToPlayer are about the player's own inventory wherever it sits, and
moveItemBetween only runs when the player's own inventory is not involved at all.
local hookId = exports['hex_4_inventory']:AddHook(hookName, callback)Example:
-- prevent players from dropping weapons on the ground
exports['hex_4_inventory']:AddHook('hex_4_inventory:moveItemToOther', function(playerId, item, count, invData)
if invData.type == 'drop' then
if item.type == 'weapon' then
return false
end
end
return true
end)
exports['hex_4_inventory']:AddHook('hex_4_inventory:removeItem', function(playerId, item, count, extraData)
if item.type == 'weapon' then
return false
end
return true
end)
-- prevent players from moving weapons out of a trunk into a fraction inventory
exports['hex_4_inventory']:AddHook('hex_4_inventory:moveItemBetween', function(playerId, item, count, fromInv, toInv)
if fromInv.type == 'trunk' and toInv.type == 'fraction' then
if item.type == 'weapon' then
return false
end
end
return true
end)hex_4_inventory:getOtherInventory
This hook works differently from the ones above. It gets a single table instead of several arguments, and next to denying the request it can also change what the player gets to see by returning a table with the fields you want to replace. Return nothing to leave everything as it is.
It runs on every fetch, so on opening as well as on every refresh after an item was moved. It never runs for the player's own inventory, which means with a trunk on one side and a fraction inventory on the other it runs once for each of them.
Prop
Type
-- show the fraction inventory of another job as locked instead of its contents
exports['hex_4_inventory']:AddHook('hex_4_inventory:getOtherInventory', function(data)
if data.type ~= 'fraction' then return end
local playerObject = GetPlayerObject(data.source)
local job = GetPlayerJob(playerObject)
if data.id ~= ('fraction_%s'):format(job.name) then
return { locked = true }
end
end)
-- deny the trunk of an impounded vehicle, this closes the inventory for the player
exports['hex_4_inventory']:AddHook('hex_4_inventory:getOtherInventory', function(data)
if data.type == 'trunk' and isVehicleImpounded(data.id) then
return false
end
end)Note
Returning false closes the inventory for the player, locked = true keeps it open and only
hides the contents. Use locked when someone should see that the inventory exists but is not
theirs to open.
RemoveHook
Removes a hook from the inventory script.
local success = exports['hex_4_inventory']:RemoveHook(hookId)Prop
Type