World Interactions
Create interaction points in the world with selectable options adapted for RedM. This system allows for fine-grained access control using job requirements at multiple levels.
Requirements & Credits
- Requirement: ox_lib
- Original Repo: darktrovx/interact
- RedM Adaptation: ChatDisabled, Devyn, Zoo, Snipe
Options Format
Each option within an interaction can be configured as follows:
lua
{
label = 'Hello World!',
jobs = { "police", "doctor" }, -- Optional: Only these jobs see this specific option
canInteract = function(entity, coords, args)
return true
end,
action = function(entity, coords, args)
print("Action triggered!", entity)
end,
serverEvent = "server:Event",
event = "client:Event",
args = {
value1 = 'foo',
}
}
Exports
1. Coordinate Interaction
Add a point at a specific vector3 location.
lua
exports.murphy_interact:AddInteraction({
coords = vec3(425.1, -1020.2, 12.0),
distance = 8.0,
interactDst = 1.0,
id = 'unique_interaction_id',
jobs = { "testJob" }, -- Optional: Only these jobs see the interaction at all
options = {
{
label = 'Job Specific Option',
jobs = { "testJob" }, -- Optional: Double-check or sub-job filter
action = function(entity, coords, args)
print("Hello Job!")
end,
},
{
label = 'Public Option',
action = function(entity, coords, args)
print("Hello Everyone!")
end,
},
}
})
2. Local & Networked Entity Interaction
Apply interactions to specific entities (peds, objects, vehicles).
lua
-- For a local entity (non-networked)
exports.murphy_interact:AddLocalEntityInteraction({
entity = entityId,
id = 'local_entity_check',
jobs = { "miner" },
options = {
{
label = 'Mine Ore',
action = function() print("Mining...") end,
},
}
})
-- For a networked entity (using NetID)
exports.murphy_interact:AddEntityInteraction({
netId = networkId,
id = 'net_entity_check',
jobs = { "police" },
options = {
{
label = 'Search Search',
action = function() print("Searching...") end,
},
}
})
3. Global Interactions (Models, Vehicles, Players)
Apply interactions to every instance of a model or all players.
lua
-- All vehicles or specific models
exports.murphy_interact:AddGlobalVehicleInteraction({
id = 'global_veh_menu',
jobs = { "mechanic" },
options = {
{
label = 'Repair Vehicle',
action = function(entity) SetVehicleFixed(entity) end,
},
}
})
-- All players
exports.murphy_interact:addGlobalPlayerInteraction({
id = 'player_interaction',
jobs = { "medic" },
options = {
{
label = 'Heal Player',
action = function(entity, _, _, serverId)
TriggerServerEvent('hospital:heal', serverId)
end,
},
}
})
4. Dynamic Options
Add an option to an existing interaction ID later.
lua
-- Assuming 'ped_123' was created via AddInteraction
exports.murphy_interact:AddOption('ped_123', {
label = 'Dynamic Job Task',
jobs = { "woodcutter" },
action = function()
print("Dynamic action triggered")
end,
})
Removal Functions
To remove an interaction, use the corresponding function with the unique id or netId/model used during creation.
| Function | Required Parameters |
|---|---|
RemoveInteraction | id |
RemoveLocalEntityInteraction | entity, id |
RemoveEntityInteraction | netId, id |
RemoveModelInteraction | model, id |
RemoveGlobalVehicleInteraction | id |
RemoveGlobalPlayerInteraction | id |
Docs