addGlobalModel
Registers interactions for one or more models in the game. This function enables global interactions with specified models, allowing customizable options for each interaction regardless of the model's specific instances or locations.
Parameters
data
(ModelData
): A table containing the interaction data. It must include:id
(string | number
): A unique identifier for the interaction.models
(table
): A list of models and their interaction settings. Each entry in the list is a table with the following fields:model
(string | number
): The model name or hash for which the interaction is being registered.offset?
(vec3
): The offset from the model'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 array
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
Example
interact.addGlobalModel({
id = "uniqueNetworkedEntityId",
models = {
{model = "prop_vend_snak_01", offset = vec3(0, 0, 1.0)},
{model = "prop_vend_soda_02", offset = vec3(0, 0, 1.0)},
},
options = {
{
label = "Interact with Model",
icon = "hand", -- Example simple FA icon name
groups = {['police'] = 1},
items = {['money'] = 100},
onSelect =function(data) print("Model interaction triggered") end,
canInteract = function(entity, distance, coords, id)
return true
end
}
},
renderDistance = 10.0,
activeDistance = 2.0,
cooldown = 1500
})
export
exports.sleepless_interact:addGlobalModel(data)