Throw & Place
Usage

Usage

To allow players to use the throw/place feature, you'll need to add a button or option to the item's context menu within your inventory. This option will then trigger our script's export function.

Example for ox_inventory

Locate the file where you configure your inventory's items (e.g., data/items.lua or similar) and add a button to the desired item's definition, like so:

['money'] = {
    label = 'Money',
    buttons = {
        {
            label = 'Hold', -- You can customize this button's text
            action = function(slot)
                -- This line triggers the script's core functionality
                exports.caue_throw_n_place:StartThrowing('money', slot)
            end
        },
    },
},

Example with Optional Config Parameters

You can also provide specific configuration for an item directly within the export, overriding any settings in config.lua. This is useful for unique items or dynamic behaviors.

['money'] = {
    label = 'Money',
    buttons = {
        {
            label = 'Hold',
            action = function(slot)
                exports.caue_throw_n_place:StartThrowing('money', slot, {
                    model = `prop_anim_cash_pile_01`,  -- The 3D prop model for this specific item.
                    throwForce = 1.0, -- A multiplier for the force applied when throwing this item. (recommended range: 0.1 - 1.0).
                    handPosition = vector3(0, 0, 0), -- A vector3(x, y, z) offset to adjust the item's position in the player's hand.
                    handRotation = vector3(0, 90, 0), -- A vector3(x, y, z) rotation to adjust the item's orientation in the player's hand.
                    handRotationOrder = 2, -- Changes the order rotations are applied (XYZ, YZX, etc.) to fix orientation issues.
                    disablePlace = true, -- When is set to true, it prevents the item from being placed in the environment.
                })
            end
        },
    },
},
āš ļø

The syntax above is specific to ox_inventory. If you use qb-inventory, ps-inventory, or others, consult their documentation on how to add custom action buttons and apply the same export-calling logic.

Understanding the Export Function

exports.caue_throw_n_place:StartThrowing(...)

  • Parameters:
    • item: This is the item's unique name (string) from your inventory. It must match the item's key exactly.
    • slot: This variable is typically provided by your inventory system and contains the item's slot information.
    • config (Optional): An optional Lua table where you can directly provide custom configuration for the item. These settings will override any default or items table settings defined in config.lua for this specific action.