LGF Interaction
Exports
Exports Ped

Ped Istance

exports.addInteractionPed

---@param data table
exports.LGF_Interaction:addInteractionPed(data)

Description

This function adds an interaction with an NPC in the game. It creates a ped (entity) at specified coordinates, associates it with an interaction.

Parameters

  • data (table): A table that contains the interaction configuration, including position, actions, and any custom settings for the interaction.

Usage

local Ped = {
    { Position = vec4(41.1964, 6448.3623, 31.4144, 274.0062), Model = "a_f_m_fatcult_01", RequiredJob = false, },
    { Position = vec4(60.4139, 6434.2373, 31.2951, 231.5423), Model = "a_f_m_fatcult_01", RequiredJob = "police", }
}
 
for i = 1, #Ped do
    local data = Ped[i]
    exports.LGF_Interaction:addInteractionPed({
        Coords = data.Position,
        model = data.Model,
        pedID = i,
        dataBind = {
            {
                title = "Talk to the Ped",
                icon = "fa-comments",
                description = "This is an interaction with the ped.",
                onClick = function(self)
                    exports.LGF_Interaction:removeInteractionPed(self.pedID, self.id)
                end,
                canInteract = function(distance, interactionid, myPed)
                    -- Check if a specific job is required to interact with the ped
                    -- If `RequiredJob` is false, anyone can interact with the ped
                    -- Otherwise, check if the player's job matches the `RequiredJob` for the ped
 
                    if data.RequiredJob == false then
                        return true  -- No job required, allow interaction
                    end
 
                    -- Check if player's job matches the ped's required job
                    -- Return true only if the player has the required job
                    return LGF.Core:GetJob() == data.RequiredJob
                end
            }
        },
        distance = 10,
        closest = 5.0,
        debug = true,
        onEnter = function(self)
            Shared.debugData("DEBUG", self)
        end,
        onExit = function(self)
        end,
        nearby = function(self)
        end
    })
end

exports.removeInteractionPed

---@param pedID string|number The identifier of The ped
---@param interactionID string The InteractionID of the Zone
exports.LGF_Interaction:removeInteractionPed(pedID, interactionID)

Description

This function is used to permanently remove both the Ped (pedestrian) and the associated interaction DUI from the game world.

Parameters

  • pedID (string | number): The identifier of the Ped. This unique ID is used to reference and identify a specific Ped in the game world.
  • interactionID (string | number): The InteractionID of the zone or interaction associated with the Ped. This ID ties the Ped to the specific interaction, and removing the interaction ID will disable all related functionalities, such as interaction menus or actions tied to the Ped.

Purpose

This function is typically used when you want to clean up or remove the Ped and interaction after they are no longer needed, or when the Ped should be removed due to game events (e.g., NPC leaving the scene, mission completion, etc.).

Usage

dataBind = {
    {
        title = "Talk to the Ped",
        icon = "fa-comments",
        description = "This is an interaction with the ped.",
        onClick = function(self)
            -- Retrieve instance data from self
            -- Use self.pedID to get the Ped ID for the current interaction
            -- Use self.id to get the current Zone ID associated with the interaction
            exports.LGF_Interaction:removeInteractionPed(self.pedID, self.id)
        end,
        canInteract = function(distance, interactionid, myPed)
            -- Add your conditions for when the interaction is allowed
            return true  -- Example: Always allow interaction
        end
    }
},

exports.removePed

---@param pedID string|number The identifier of The ped
exports.LGF_Interaction:removePed(pedID)

Description

This function removes the specified Ped (pedestrian) from the game world, using the provided pedID. Unlike removeInteractionPed, this function only removes the Ped entity itself and does not affect any associated interaction DUI or interaction zone.

Parameters

  • pedID (string | number): The identifier of the Ped. This unique ID is used to reference and identify a specific Ped in the game world.

Purpose

Use this function when you need to remove the visual presence or behavior of a Ped in the game world, but you want to keep the interaction DUI or zone associated with that Ped active. This can be useful in scenarios where:

  • You want the interaction to persist even after the Ped leaves.
  • The interaction zone might apply to different Peds or objects in the future.

Usage

dataBind = {
    {
        title = "Remove Ped",
        icon = "fa-user-slash",
        description = "This action will remove the Ped without affecting the interaction zone.",
        onClick = function(self)
            -- Use self.pedID to get the Ped ID for the current interaction
            exports.LGF_Interaction:removePed(self.pedID)
        end,
        canInteract = function(distance, interactionid, myPed)
            -- Define interaction conditions here
            return true  -- Example: always return true for simplicity
        end
    }
},

exports.getInteractionPeds

---@return table|nil
exports.LGF_Interaction:getInteractionPeds()
  • pedArray (table): A table containing all the interaction peds that have been created through the addInteractionPed function.
    • ped: The ped entity itself.
    • position: A table containing the position (coordinates) of the ped.
    • model: The model of the ped (e.g., the specific character model).
    • interactionID: The unique interaction ID for the ped, which ties the ped to an interaction zone.

Description

This function is particularly useful when you want to query all the active NPCs and perform operations such as removing them, updating their positions, or changing their behaviors based on the game’s current state.

Usage

local interactionPeds = exports.LGF_Interaction:getInteractionPeds()
for pedID, pedData in pairs(interactionPeds) do
    print(("Ped ID: %s"):format(pedID))
    print(("Ped Model: %s"):format(pedData.model))
    print(("Ped Position: %s, %s, %s"):format(pedData.position.x, pedData.position.y, pedData.position.z))
end