Functions

Exports to use to add or remove interactions.

AddInteractionEntity

The AddInteractionEntity function allows you to add a single interaction point to a specific entity, such as a npc (ped), object (object), or vehicle (vehicle). This is useful for scenarios where you want to associate specific actions with a particular entity.

Syntax

exports["inside-interaction"]:AddInteractionEntity(entity, {...})

Options

  • entity: The entity to which the interaction is being added. It can be a npc (ped), object (object), or vehicle (vehicle).

Interaction Configuration

  • distance (optional): The maximum distance at which the interaction is possible.

  • offset (optional): Adjust the positions of the interaction label and target.

  • checkVisibility (optional): A boolean determining if the interaction should only be available when the coordinates are visible.

Interaction Options

Each option in the interaction table is itself a table with several key-value pairs:

  • name: A unique identifier for the interaction option. This is used to refer to the specific interaction later if needed, like for removing it.

  • icon: An icon representing the interaction, specified using FontAwesome icons. Make sure to use icons from the FontAwesome Free collection.

  • label: The text label that will be displayed for this interaction option.

  • key: The keyboard key that the player needs to press to activate this interaction (e.g., "E").

  • duration: The duration in milliseconds that the key needs to be pressed.

  • action: A function that defines what will happen when the interaction is activated.

Example Usage

local ped = CreatePed(...)
local object = CreateObject(...)
local vehicle = CreateVehicle(...)

local entity = ped -- or object or vehicle, it's just an example


-- EXAMPLE 1
exports["inside-interaction"]:AddInteractionEntity(entity, {
    distance = 10.0,
    checkVisibility = true,
    {
        name = "Question",
        icon = "fa-regular fa-circle-up",
        label = "Ask about a job",
        key = "E",
        duration = 1000,
        action = function()
            print("We are not looking for employees at the moment")
        end
    }
})


-- EXAMPLE 2
questionInteraction = exports["inside-interaction"]:AddInteractionEntity(entity, {
    distance = 10.0,
    checkVisibility = true,
    offset = {
        label = {x = 0.0, y = 2.0, z = 0.4},
        target = {x = 0.0, y = 2.0, z = 0.0}
    },
    {
        name = "Question",
        icon = "fa-regular fa-circle-up",
        label = "Ask about a job",
        key = "E",
        duration = 1000,
        action = function()
            print("We are not looking for employees at the moment")
        end
    },
    {
        name = "Shop",
        icon = "fa-regular fa-circle-up",
        label = "Got something to sell?",
        key = "E",
        duration = 1000,
        action = function()
            TriggerEvent("openShop")
        end
    }
})

AddInteractionEntityMultiple

The AddInteractionEntityMultiple function is designed to add multiple interaction points to a single entity, allowing for different interactions at different locations or contexts.

Syntax

exports["inside-interaction"]:AddInteractionEntityMultiple(entity, {...})

Options

  • entity: The entity to which the interactions are being added.

Interaction Configuration

An array of interaction configurations, each containing:

  • distance (optional): The maximum distance at which the interaction is possible.

  • checkVisibility (optional): A boolean determining if the interaction should only be available when the coordinates are visible.

Individual Interactions

An array of individual interactions, each with its settings:

  • offset: Positions for the label and target of the interaction.

  • name: Unique identifier for the interaction.

  • icon: Icon representing the interaction, using FontAwesome.

  • label: Text displayed for the interaction.

  • key: Keyboard key to activate the interaction.

  • duration: How long the key needs to be pressed.

  • action: Function executed upon interaction.

Example Usage

local ped = CreatePed(...)
local object = CreateObject(...)
local vehicle = CreateVehicle(...)

local entity = ped -- or object or vehicle, it's just an example


-- EXAMPLE 1
exports["inside-interaction"]:AddInteractionEntityMultiple(entity, {
    { 
        distance = 10.0,
        checkVisibility = true,
        offset = {
            label = {x = 0.0, y = 2.0, z = 0.9},
            target = {x = 0.0, y = 2.0, z = 0.5}
        },
        interaction = {
            {
                name = "hood",
                icon = "fa-regular fa-circle-up",
                label = "Open Hood",
                key = "E",
                duration = 1000,
                action = function()
                    print("Test Print")
                end
            },
            {
                name = "hood2",
                icon = "fa-regular fa-circle-up",
                label = "Check Engine Temperature",
                key = "E",
                duration = 1000,
                action = function()
                    print("Test Print2")
                end
            }
        }
    }
})

-- EXAMPLE 2
trunkInteraction = exports["inside-interaction"]:AddInteractionEntityMultiple(entity, {
    { 
        distance = 10.0,
        checkVisibility = true,
        offset = {
            label = {x = 0.0, y = 2.0, z = 0.9},
            target = {x = 0.0, y = 2.0, z = 0.5}
        },
        interaction = {
            { -- Interaction 1
                name = "hood",
                icon = "fa-regular fa-circle-up",
                label = "Open Hood",
                key = "E",
                duration = 1000,
                action = function()
                    print("Test Print")
                end
            },
            { -- Interaction 2
                name = "hood2",
                icon = "fa-regular fa-circle-up",
                label = "Check Engine Temperature",
                key = "E",
                duration = 1000,
                action = function()
                    print("Test Print2")
                end
            }
        }
    },
    { 
        distance = 10.0,
        checkVisibility = true,
        offset = {
            label = {x = 0.0, y = -2.0, z = 0.9},
            target = {x = 0.0, y = -2.0, z = 0.5}
        },
        interaction = {
            {
                name = "trunk",
                icon = "fa-regular fa-circle-up",
                label = "Open Trunk",
                key = "E",
                duration = 1000,
                action = function()
                    print("Test Print")
                end
            }
        }
    }
})

AddInteractionCoords

The AddInteractionCoords function allows you to add a single interaction point to specific coordinates. This is useful for scenarios where you want to associate specific actions with a particular location in the game.

Syntax

local Coords = exports["inside-interaction"]:AddInteractionCoords(coords, {...})

Options

  • coords: The coordinates where the interaction is being added. These should be provided as a vector3(x, y, z).

Interaction Configuration:

  • distance (optional): The maximum distance at which the interaction is possible.

  • offset (optional): Adjust the positions of the interaction label and target.

  • checkVisibility (optional): A boolean determining if the interaction should only be available when the coordinates are visible.

Interaction Options:

Each option within the interaction array is itself an object with several key-value pairs:

  • name: A unique identifier for the interaction option. This is used to refer to the specific interaction later if needed, like for removing it.

  • icon: An icon representing the interaction, specified using FontAwesome icons. Ensure you use icons from the FontAwesome Free collection.

  • label: The text label that will be displayed for this interaction option.

  • key: The keyboard key that the player needs to press to activate this interaction (e.g., "E").

  • duration: The duration in milliseconds that the key needs to be pressed.

  • action: A function that defines what will happen when the interaction is activated.

Example Usage

local coords = vector3(100.0, 100.0, 100.0)

CoordsInteraction = exports["inside-interaction"]:AddInteractionCoords(coords, {
    distance = 10.0,
    checkVisibility = true,
    offset = {
        label = 0.4,
        target = 0.0
    },
    {
        name = "coords",
        icon = "fa-regular fa-circle-up",
        label = "Coordinates",
        key = "E",
        duration = 1000,
        action = function()
            print("coords")
        end
    }
})

RemoveInteraction

The RemoveInteraction function is used to remove interactions from a specific entity.

Options

  • entity: The entity from which you are removing the interaction(s).

  • interactionName (optional): The name of the specific interaction to remove. This is the same name you assigned when creating the interaction.

Example Usage

AddInteractionEntity, AddInteractionEntityMultiple

-- Removes all interactions from Entity

  -- EXAMPLE 1
  exports["inside-interaction"]:RemoveInteraction(entity)

  -- EXAMPLE 2
  trunkInteraction = exports["inside-interaction"]:AddInteractionEntityMultiple(entity, {...})
  
  exports["inside-interaction"]:RemoveInteraction(trunkInteraction )


-- Removes interaction with specific name from Entity

  -- EXAMPLE 1
  exports["inside-interaction"]:RemoveInteraction(entity, "Question")

  -- EXAMPLE 2
  questionInteraction = exports["inside-interaction"]:AddInteractionEntity(entity, {...})
  
  exports["inside-interaction"]:RemoveInteraction(questionInteraction, "Question")

AddInteractionCoords

-- Removes all interactions from Coordinates

coordsInteraction = exports["inside-interaction"]:AddInteractionCoords(...)

exports["inside-interaction"]:RemoveInteraction(coordsInteraction)

-- Removes interaction with specific name from Coordinates

coordsInteraction = exports["inside-interaction"]:AddInteractionCoords(...)

exports["inside-interaction"]:RemoveInteraction(coordsInteraction, "Question")

Last updated