addLocalEntity
Registers an interaction for a local (non-networked) entity in the game. This allows players to interact with specified local entities within a defined distance, offering customizable interaction options.
Parameters
data(LocalEntityData): A table containing the interaction data. It must include:id(string | number): A unique identifier for the interaction.entity(number): The entity handle of the local entity.offset?(vec3): The offset from the entity's position where the interaction is located.bone?(string or string[]): name of the bone to interact with or an array of bones. will use the first valid bone for the entity from the arrayallowInVehicle?(boolean): wether or not you can use this interaction in a car (default:false).options(table): A list of options for the interaction. Each option is a table with the following fields:label(string): The text displayed for the option.icon(string): The simple FontAwesome icon name displayed for the option (e.g., "hand").groups?(table<string, number>): table of allowed jobs and minimum grades for this Optionitems?(string or string[] or table<string, number>): An item, array of items, or pairs of items-count required to show the option.anyItem?(boolean): Only require a single item from the items table to exist.remove?(boolean): when true, the entire interaction will destroy when this option is selectedcanInteract?(function(entity?: number, distance: number, coords: vec3, id: string | number)): A function that determines if the option can be interacted with.onSelect?(function(id: string | number, entity?: number, coords: vec3, distance: number)): function that gets called when the option is selectedexport?(string): export that gets called when the option is selected.event?(string): client event that gets called when the option is selected.serverEvent?(string): server event that gets called when the option is selected.command?(string): command that gets called when the option is selected.
renderDistance?(number): distance at which the interaction indicator is visible. Defaults to5.0.activeDistance?(number): distance at which the interaction menu is visible. Defaults to1.0.cooldown?(number): The cooldown time in milliseconds between interactions to prevent spamming. Defaults to1000.removeWhenDead?(boolean): If this is set to true the interaction will be removed when the entity is dead. if it is a global interation, it will prevent the interaction from being added again while deadsprite?(table) a table of override data for the indicator sprite (small circle by default in config)dict?(string) texture dictionarytxt?(string) texture namecolor?(vec4) color
Returns
id(string | number): The unique identifier for the interaction that was added.
Example
interact.addLocalEntity({
id = "uniqueLocalEntityId",
entity = 123456, -- Example entity handle
options = {
{
label = "Local Interact Option",
icon = "hand", -- Example simple FA icon name
groups = {['police'] = 1},
items = {['money'] = 100},
onSelect =function(data) print("Local entity action triggered") end,
canInteract = function(entity, distance, coords, id)
return true
end
}
},
renderDistance = 10.0,
activeDistance = 2.0,
cooldown = 1500
})
export
exports.sleepless_interact:addLocalEntity(data)