Legacy Reference

Adding Usable Support on an Entity


Players may be able to interact with an entity using a key press ('F' by default). Entities that can be interacted with will be enabled with a special on-screen icon inside the game to inform the player that interaction is possible.

To use this feature, you need to create a script that implements two functions: IsUsable() and OnUsed().

Preparing the Script

The script should look like this:

MakeUsable(NewEntity) function NewEntity:IsUsable(userId) -- code implementation return index; end function NewEntity:OnUsed(userId, index) -- code implementation end

Implementing IsUsable

The IsUsable() function is called when a player is aiming the cross-hairs towards the entity. The function will determine if the entity can be interacted with by the player doing the aiming. The function only accepts a single parameter: the player's entity ID.

If the player cannot interact with the entity, the function should return 0. This value causes the UI to not render the "USE" icon over the entity.

If the player can interact with the entity, the function should return a positive value. This value will be stored and later used when calling the OnUsed() function.

Implementing OnUsed

The OnUsed() function is called when a player presses interacts with the entity (such as by pressing the Use key when the USE icon is active. This function accepts two parameters: (1) the player's entity ID, and (2) the value returned by IsUsable().