addGlobalPlayer
Registers a global interaction for players in the game. This function enables interactions with players, using customizable options for each interaction that can be triggered based on specified conditions.
Parameters
data
(PedInteractionData
): A table containing the interaction data. It must include:id
(string | number
): A unique identifier for the interaction.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.
offset?
(vec3
): The offset from the player's position where the interaction is located.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.addGlobalPlayer({
id = "uniquePlayerInteractionId",
options = {
{
label = "Interact with Player",
icon = "hand", -- Example simple FA icon name
groups = {['police'] = 1},
items = {['money'] = 100},
onSelect =function(data) print("Player interaction triggered") end,
canInteract = function(entity, distance, coords, id)
return true
end
}
},
offset = vec3(0, 0, 1.0),
bone = "head",
renderDistance = 10.0,
activeDistance = 2.0,
cooldown = 1500
})
export
exports.sleepless_interact:addGlobalPlayer(data)