addCoords
Adds a static coordinates-based interaction to the game. This function registers an interaction at a specific location, allowing players to interact with it when they are within a defined distance.
Parameters
data
(CoordsData
): A table containing the interaction data. It must include:id
(string | number
): A unique identifier for the interaction.coords
(vec3 or vec3[]
): The coordinates where the interaction is located.onEnter
(function(data: CPoint)
) onEnter (opens in a new tab) cb function for an ox_lib pointonExit
(function(data: CPoint)
) onExit (opens in a new tab) cb function for an ox_lib pointnearby
(function(data: CPoint)
) nearby (opens in a new tab) cb function for an ox_lib pointoptions
(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 remove 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
.sprite?
(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.
Examples
single
local function onEnter(point)
print('Hello')
end
local function onExit(point)
print('Goodbye')
end
local function nearby(point) --- runs every frame when inside the render distance
print('wow')
end
interact.addCoords({
id = "uniqueInteractionId",
coords = vec3(123.4, 567.8, 250.0),
onEnter = onEnter,
onExit = onExit,
nearby = nearby,
options = {
{
label = "Interact Option 1",
icon = "hand", -- Example simple FA icon name
groups = {['police'] = 1},
items = {['money'] = 100},
onSelect =function(data) print("Action 1 triggered") end,
canInteract = function(entity, distance, coords, id)
return distance < 2.0 -- Example condition based on distance
end
}
},
renderDistance = 10.0,
activeDistance = 2.0,
cooldown = 1500
})
multiple
⚠️
when sending a list of coords it will modify the id for eachone by adding the index to the end of the id: "uniqueid:1", "uniqueid:2", etc.
interact.addCoords({
id = "uniqueInteractionId", --id that is stored in variable
coords = {
vec3(123.4, 567.8, 250.0),
vec3(421.4, 567.8, 125.0)
},
options = {
{
label = "Interact Option 1",
icon = "hand", -- Example simple FA icon name
onSelect = function(data) print("Action 1 triggered") end,
canInteract = function(entity, distance, coords, id)
return true
end
}
},
renderDistance = 10.0,
activeDistance = 2.0,
cooldown = 1500
})
export
exports.sleepless_interact:addCoords(data)