For the complete documentation index, see llms.txt. This page is also available as Markdown.

Creating a Custom Item Behavior

Item behaviors allow you to create completely custom interaction logic for items registered in Config.Items.

A behavior can define available controls, spawned objects, placement support, placed-object actions, primary interactions, custom actions, and cancellation logic.

Behavior files are located in: shared/behaviors/

After creating a behavior, register it using RegisterBehavior and assign its name to the item’s behavior option.


1. Create the Behavior

local CustomBehavior = {}

A behavior is a Lua table containing the methods used by VMS Needs during the item interaction lifecycle.

Method
Required
Purpose

GetControls

No

Defines the available interaction controls and item description.

PrimaryAction

No

Handles the primary use action.

HandleAction

No

Handles additional named controls.

GetObjects

No

Defines which objects should be spawned and attached.

CanPlace

No

Determines whether the item can currently be placed.

PlacedActions

No

Adds actions to an item after it has been placed.

CancelAction

No

Defines what happens when the player cancels item usage.

Only implement the methods required by your custom interaction.

2. GetControls

Returned values
Value
Description

controls

List of controls available for the current item.

description

Optional text displayed alongside the controls.

Control fields
Field
Description

key

Keyboard key displayed and listened for by the controls system.

label

Text displayed to the player. Use TRANSLATE(...) for localized labels.

name

Internal action identifier passed to the behavior.

The action named use calls PrimaryAction. Other action names are passed to HandleAction.

3. PrimaryAction

PrimaryAction is called when the player activates the control with the action name use.

For consumable items, you can call the internal ConsumeItem function to use the configured animations and status changes.

4. HandleAction

HandleAction receives all named controls other than the primary use action.

The action value matches the name configured in GetControls.

5. GetObjects

GetObjects defines the objects spawned while the item is being used.

Parameters
Field
Description

data.name

Current item name.

data.metadata

Current item metadata.

data.visualState

Optional visual state requested by the behavior.

Returned object fields
Field
Description

model

Model name or hash to spawn.

attach

Attachment configuration used for the object.

Advanced Example - Dynamic Model

This example changes the model according to item metadata and remaining item size.

6. CanPlace

CanPlace determines whether the currently used item can be placed in the world.

Return true to allow placement or false to prevent it.

7. PlacedActions

PlacedActions defines the interactions available after the item has been placed in the world.

allowDefault
Field
Description

take

Enables the built-in action for picking up the placed item.

pour

Enables the built-in pouring action when supported.

Custom option fields
Field
Description

name

Unique action identifier.

icon

Target-system icon.

label

Translation suffix used by the target and 3D Text modules.

actionControl

Key used for the 3D Text interaction.

distance

Maximum interaction distance.

action

Function executed after selecting the action.

canInteract

Optional function determining whether the action is currently available.

For label = 'sweep_away', the system uses target.sweep_away or 3dtext.sweep_away, depending on the active interaction system.

8. PackClientMetadata

PackClientMetadata allows a behavior to send only the metadata required on the client after a placed item is synchronized.

By default, VMS Needs does not send the complete metadata of placed items to clients in order to minimize the amount of data transferred during the initial synchronization. If your behavior requires specific metadata on the client (for example, to determine available interactions in PlacedActions), return only the required values from this function.

Return a table containing only the metadata required by the client, or nil if no metadata needs to be synchronized.

9. CancelAction

CancelAction defines what happens when the player closes or cancels the current item interaction.

CancelUsage() hides or returns the item according to its current state and configured item behavior.

Use ThrowItem() when the item should be discarded instead of returned to the inventory.

10. Register the Behavior

The registration name must match the behavior option configured for the item.

11. Complete Example

Behavior-specific configuration

A custom behavior decides which entries are required inside models, attaches, animation, and particles. When creating a new behavior, you are responsible for reading and using those configuration entries inside the behavior file.

We recommend copying the built-in behavior closest to your intended interaction and using it as a starting point.

Last updated