ConsumablesNewFree

Consumables: Installation

Get the portion based food and drink system running on your server, with item definitions and images for ox_inventory and qb-inventory.

v1.0.0Open sourceFreeQBox · QBCore · ESX · Standalone

Before you start

Make sure OneSync is enabled and your server artifact is up to date. The script detects your framework, inventory, target and notification resource on its own and creates its only database table on the first start.

Requirements

ResourceRequiredNotes
ox_libYesCallbacks, key bindings and locales
oxmysqlYesStores the food left on the ground
ox_inventory / ps-inventory / jpr-inventory / qb-inventoryYesOne of them, detected in this order
qbx_core / qb-core / es_extendedOptionalDetected in this order, otherwise the script runs standalone
ox_target / qb-targetOptionalNeeded to inspect and pick up food on the ground
okokNotify / ps-ui / ox_libOptionalNotifications, see Notifications in the config

Inventory and framework combinations

qb style inventories (qb-inventory, ps-inventory, jpr-inventory) only run on qb-core. ESX and standalone servers need ox_inventory. Without a supported inventory the resource stops with No supported inventory found.

See Dependencies for download links and the start order.

Setup

Download the resource

The script is free and open source (MIT). Get it from GitHub, see Free scripts.

Keep the folder name

The folder must be named hype-consumables. The ox_inventory item definitions call hype-consumables.useFood, and the interface and exports resolve through this name.

config.lua
foods.lua
install.sql
ox_inventory.md
qb_inventory.md
fxmanifest.lua

The interface ships prebuilt in web/build. You only need Node.js if you want to change it (see the FAQ).

Add the items

Apply only one of these, depending on your inventory. The item names must match the keys in config/foods.lua. The 13 included items are burger, sandwich, hotdog, taco, fries, donut, chips, egobar, water, sprunk, ecola, coffee and grapejuice.

Add the contents of INSTALL/ox_inventory.md (Lua item definitions) to the return { ... } table in ox_inventory/data/items.lua. burger, sprunk, water, sandwich, coffee and grapejuice already exist there: delete their current definitions and replace them with the ones from the file. Every item follows the same shape:

ox_inventory/data/items.lua
['burger'] = {
    label = 'Burger',
    weight = 20,
    stack = true,
    close = true,
    consume = 0,
    description = 'Freshly made burger. Eaten bite by bite.',
    client = {
        export = 'hype-consumables.useFood',
    },
    buttons = {
        { label = 'Give to someone', action = function(slot) exports['hype-consumables']:giveFood(slot) end },
        { label = 'Put on the ground', action = function(slot) exports['hype-consumables']:dropFood(slot) end },
    },
},
FieldWhy
weightPackaging only. The remaining grams / ml are added through the metadata, so half a burger is lighter
consume = 0ox_inventory does not remove the item itself, the script handles every bite
client.exportItem use is handed to the script, framework consumable registrations are never reached
buttonsRight click menu in the inventory: give to a player or put on the ground

Copy INSTALL/item-images/*.png to ox_inventory/web/images/.

Both files also contain an optional spoiled_food item. Add it only if you set Spoilage.spoiledItem to 'spoiled_food' (see Spoilage).

Database

Nothing to do in most cases. On the first start the script creates its only table, hype_consumables_drops, which keeps the food left on the ground across restarts. If your database user has no CREATE permission, run INSTALL/install.sql by hand once:

INSTALL/install.sql
CREATE TABLE IF NOT EXISTS `hype_consumables_drops` (
    `id` VARCHAR(32) NOT NULL,
    `item` VARCHAR(64) NOT NULL,
    `metadata` LONGTEXT NOT NULL,
    `x` FLOAT NOT NULL,
    `y` FLOAT NOT NULL,
    `z` FLOAT NOT NULL,
    `heading` FLOAT NOT NULL DEFAULT 0,
    `owner` VARCHAR(64) NULL DEFAULT NULL,
    `created_at` INT NOT NULL,
    PRIMARY KEY (`id`)
);

Hunger, thirst, remaining amounts and expiry dates live in the item metadata and your framework, not in this table.

Start the resource

Add it to server.cfg after its dependencies, and set the language.

server.cfg
ensure ox_lib
ensure oxmysql
ensure qbx_core          # or qb-core / es_extended (optional)
ensure ox_inventory      # or qb-inventory / ps-inventory / jpr-inventory
ensure ox_target         # or qb-target

# HypeScripts
ensure hype-consumables

setr ox:locale "en"      # "en" and "tr" are included

Set the basics

The defaults work out of the box. Open config/config.lua to check the keys, spoil times and drop limits, and config/foods.lua to tune the foods. See Configuration for every option.

Start order matters

If hype-consumables starts before your inventory, it prints No supported inventory found and stops. If it starts before your framework, it falls back to standalone mode and hunger and thirst are not applied.

Verify

Set Debug = true in the config and start the server. Look for these lines in the console:

[DEBUG:SERVER] [INFO] Framework detected: qbx_core
[DEBUG:SERVER] [INFO] Inventory detected: ox_inventory
[hype-consumables] Loaded 0 food drops
[DEBUG:SERVER] [INFO] 13 foods loaded (framework: qbx_core)

If an item is missing from your inventory, the console lists it: These foods are not registered in ox_inventory (see INSTALL): ...

Give yourself a burger and use it. The first bite is taken right away and a small panel opens in the bottom right corner. Press E for more bites and watch the remaining grams go down in the panel and in the inventory.

Press X to put the rest away, then use the burger again: it continues where you left off. Press Q to put it on the ground, then use Inspect and Pick up on it with your target.

With a second player next to you, press H while eating, then Y to send the offer. The other player accepts with Y. When everything works, set Debug = false again.

How it works

  • Bite by bite: a 200 g burger is eaten in 10 bites of 20 g. After 4 bites the inventory and the panel show 120 g. Bites are never taken automatically; every bite is one key press.
  • Put away and continue: stop at any time. The rest stays in the inventory, and using the item again continues where you left off.
  • Sealed and opened: new food is a sealed package. Sealed packages created together stack. The first bite opens the package, gives it a unique id and moves it to its own slot, so you need one free slot to start eating from a stack.
  • Give to players: offer the food to a nearby player. The item is locked until the offer is answered and is moved on the server once accepted.
  • Food on the ground: dropped food stays in the world as a prop, can be inspected and picked up, and survives server restarts.
  • Real time spoilage: food spoils by category in real time, even while the server is off. Spoiled food is marked in the inventory and cannot be eaten by default.
  • Hunger and thirst: every bite adds its share of hunger and thirst through your framework. A smaller last bite counts proportionally.
  • Server side: every amount, expiry date and nutrition value is calculated on the server. The interface only displays them.

Controls

The panel uses no mouse or cursor; every action is a key and shown as a hint.

KeyAction
Use the itemStart eating (the first bite is taken right away)
ETake a bite / sip (using the same item again does the same)
QPut it on the ground
XStop and put the rest away
HGive to someone: opens the nearby player list, again selects the next player
Y / NSend / cancel an offer, accept / decline an incoming one
Right click in inventoryGive / drop (ox_inventory only)
TargetInspect / Pick up food on the ground

The eating keys are GTA controls. While you eat or pick a player they are blocked every frame, so game actions on the same key (cover, horn, headlights) cannot interfere; the rest of the time they belong to the game. Y and N are key bindings that players can change under Settings → Key Bindings → FiveM.

Inventories

ox_inventoryqb-inventory / ps-inventory / jpr-inventory
Item useclient.export of the item definitionQBCore.Functions.CreateUseableItem
MetadataItem metadataItem info
StackingSealed packages stack, opened food gets its own slotEvery food is unique
New itemsMetadata is written right away by the createItem hookMetadata is written on first use or when the player joins
LocksMoving an offered item is blocked; moving the eaten food out of your inventory ends eatingNo hooks; changes are caught when the offer is accepted or on the next bite
ExtrasRemaining weight, percentage bar, right click give / drop buttonsGive / drop with the keys while eating

Frameworks

FrameworkHunger / thirstIdentifier
qbx_corePlayer state bag and metadatacitizenid
qb-coreMetadata and hud:client:UpdateNeedscitizenid
es_extendedesx_status:add / esx_status:removeidentifier
StandaloneServer event hype-consumables:server:addStatuslicense2 / license

Standalone servers have no built-in hunger and thirst. Apply the values from your own status or HUD resource with the hype-consumables:server:addStatus event.

Next steps

On this page