Drag Craft

A simple crafting system using ox_inventory drag-and-drop hooks. Players craft items by dragging one item onto another in their inventory.

Configuration

Recipes are defined in dragcraft/config.lua. Each recipe key is a pair of item names separated by a space — these are the two items the player drags onto each other.

Recipe Properties

PropertyTypeRequiredDescription
durationnumberYesDuration in milliseconds for the craft to complete
clienttableNoClient-side callbacks (before and after)
servertableNoServer-side callbacks (before and after)
coststableYesItems required and whether they are consumed
resulttableYesArray of resulting items from the craft

Cost Properties

Each entry in the costs table is keyed by item name:

PropertyTypeDescription
neednumberQuantity required. If between 0.0 and 1.0, removes that percentage of durability instead.
removebooleanWhether the item should be removed/consumed upon completion

A need value of 0.1 with remove = true removes 10% durability per craft, allowing up to 10 uses before the item breaks.

Result Properties

Each entry in the result array:

PropertyTypeRequiredDescription
namestringYesItem name to give the player
amountnumberNoFixed quantity to give (use this or min/max)
minnumberNoMinimum random quantity
maxnumberNoMaximum random quantity

Callback Functions

Both client and server tables support before and after callbacks:

CallbackDescription
before(recipeData)Runs before crafting starts. Return false to cancel the craft. Returning true or nil continues normally.
after(recipeData)Runs after crafting completes successfully.
⚠️

The recipeData parameter passed to callbacks contains all the properties defined for that specific recipe.

Complete Example

RECIPES = {
    ['garbage scrapmetal'] = {
        duration = 2000,
        client = {
            before = function(recipeData)
                -- Client logic before crafting
                -- Return false to cancel the craft
            end,
            after = function(recipeData)
                -- Client logic after successfully crafting
            end,
        },
        server = {
            before = function(recipeData)
                -- Server logic before crafting
                -- Return false to cancel the craft
            end,
            after = function(recipeData)
                -- Server logic after successfully crafting
            end,
        },
        costs = {
            ['garbage'] = { need = 1, remove = true },
            ['scrapmetal'] = { need = 0.1, remove = true },
        },
        result = {
            { name = 'lockpick', amount = 1 },
        },
    },
}

Exports

addRecipe

Register a recipe externally from another resource. Available on both the client and server.

exports.ox_inventory_addons:addRecipe(key, data)

Parameters

ParameterTypeDescription
keystringThe recipe key — two item names separated by a space (e.g., 'garbage scrapmetal')
datatableThe recipe data (same structure as config recipes)
⚠️

When using this export, you may only register callbacks for the context you call it in. A client-side call can only register client callbacks, and a server-side call can only register server callbacks.

exports.ox_inventory_addons:addRecipe('garbage scrapmetal', {
    duration = 2000,
    client = {
        before = function(recipeData)
            -- Client logic before crafting
            -- Return false to cancel
        end,
        after = function(recipeData)
            -- Client logic after crafting
        end,
    },
    costs = {
        ['garbage'] = { need = 1, remove = true },
        ['scrapmetal'] = { need = 0.1, remove = true },
    },
    result = {
        { name = 'lockpick', amount = 1 },
    },
})