addEntity
Registers an interaction for a networked entity in the game. This function enables players to interact with specified networked entities within a defined distance, with customizable options for each interaction.
Parameters
data
(EntityData
): A table containing the interaction data. It must include:id
(string | number
): A unique identifier for the interaction.netId
(number
): The network ID for the networked 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 arrayoptions
(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 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.addEntity({
id = "uniqueNetworkedEntityId",
netId = 123456, -- Example network ID
options = {
{
label = "Networked Interact Option",
icon = "hand", -- Example simple FA icon name
groups = {['police'] = 1},
items = {['money'] = 100},
onSelect =function(data) print("Networked 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:addEntity(data)