Custom Inventory

This guide is intended for developers who want to use a custom inventory system that is not natively supported by the phone. You must have basic Lua knowledge to complete these steps.

Custom Inventory Integration Guide

This guide describes how to integrate your custom inventory system with GKSPHONE v2.

1. Configuration Changes

Tell the phone to use the "custom" inventory setting.

1

Configuration edit

Open gksphone/config/config.lua, find the Config.Inventory setting and set it to:

Config.Inventory = "custom"

2. Server-Side Integration

You need to create a bridge file to handle server-side inventory actions. The phone checks Config.Inventory. When set to "custom", the phone expects you to handle the logic. You may need to add your new server script to fxmanifest.lua or ensure it's loaded via existing mechanisms.

1

Create server file

Navigate to gksphone/server/inventory/ and create custom.lua (or modify an existing server script). Ideally, add your custom logic in gksphone/server/inventory/.

The phone expects the following server-side functions to be available (either globally or via the phone calling them). Implement these functions so the phone can interact with your inventory.

Required Functions

SearchPhoneItems(source)

Searches the player's inventory for the phone item(s). Return a table with item data (or an empty table).

--- Searches the player's inventory for the specified item.
--- @param source number The player's source ID.
--- @return table item data if found, an empty table otherwise.
function SearchPhoneItems(source)
    local itemData = {}
    -- Your Custom Inventory Logic Here
    -- Example (Pseudo-code):
    -- local playerItems = exports['my-inventory']:GetPlayerItems(source)
    -- for _, item in pairs(playerItems) do
    --     if Config.ItemName[item.name] then
    --         table.insert(itemData, item)
    --     end
    -- end
    return itemData
end

SetItemData(source, item, data)

Set the metadata of the phone item for a player.

UpdateItemData(source, item, datatype, data)

Update a specific key in the metadata.

RegisterUsableItem

Register phone items as usable so they open when clicked. Use your framework's registration method; if unavailable, use the phone-provided wrapper.

3. Client-Side Integration

If your inventory supports standard ESX/QB item usage events, integration may be automatic. If your inventory uses custom events for adding/removing items, add listeners on the client.

1

Client file

Navigate to gksphone/client/inventory/ and create custom.lua or modify client.lua to listen for your inventory events.

Handling Item Removal

If the phone item is removed (dropped, used up, etc.), the phone UI should close. Example:

Handling Item Addition

If a player receives a phone, optionally force an update or open it.

Checklist

Reference Example (Based on ox_inventory)

If your custom inventory uses export-based methods similar to ox_inventory, you can structure your server/client code like the examples below.

Server-Side Example (server/inventory/custom.lua)

Client-Side Example (client/inventory/custom.lua)

Last updated