Skip to content

Ped Interactions

Ped Interactions is a client-side system built into the bridge for spawning NPC peds with target options. Peds are created when a player enters a radius and removed when they leave, keeping entity count low.

How it works

  1. You register a ped interaction with a unique ID, model, position, and target options.
  2. When a player enters the radius, the ped spawns with the configured appearance, animation, and options.
  3. When the player leaves the radius, the ped is removed and options are cleared.
  4. When the resource that registered the interaction stops, all its ped interactions are cleaned up automatically.

ox_lib points

Ped interactions use lib.points from ox_lib for radius checks. The ped only exists while a player is nearby.

Client exports

AddPedInteraction

Registers a new ped interaction.

lua
exports["prp-bridge"]:AddPedInteraction(id, payload)
ParameterTypeDescription
idstringUnique identifier for this ped.
payloadPedInteractionPayloadConfig (see below).

Returns: boolean, string?

  • true on success
  • false, "missing" if id or payload is nil
  • false, "exists" if that id is already registered

RemovePedInteraction

Removes a registered ped and deletes the ped if it exists.

lua
exports["prp-bridge"]:RemovePedInteraction(id)
ParameterTypeDescription
idstringID used when the ped was created.

Returns: booleantrue if removed, false if not found.

Payload

FieldTypeRequiredDescription
modelnumber | stringYesPed model hash or name (e.g. "s_m_y_dealer_01").
coordsvector3YesWorld position.
headingnumberYesFacing direction (0–360).
radiusnumberNoSpawn/despawn distance. Default 100.0.
optionstable[]YesTarget options (see below).
scenariostringNoAmbient scenario (e.g. "WORLD_HUMAN_GUARD_STAND").
animtableNoAnimation (see Animation).
componenttableNoPed component variation.
weaponnumberNoWeapon hash.

Scenario vs anim

Use either scenario or anim, not both. If both are set, the animation is used.

Target options

Each entry in options follows the usual target option shape. The name field is set automatically.

FieldTypeRequiredDescription
labelstringYesText in the target menu.
iconstringNoFont Awesome icon (e.g. "fas fa-hand").
distancenumberNoMax distance to show the option.
groupsstring | string[] | tableNoJob/group restriction.
itemsstringNoRequired item.
canInteractfunctionNoReturn true to show the option.
onSelectfunctionNoCalled when the option is selected.
eventstringNoClient event on select.
serverEventstringNoServer event on select.

Animation

FieldTypeDefaultDescription
animDictstringAnimation dictionary.
animstringAnimation clip.
blendInnumber8.0Blend in speed.
blendOutnumber8.0Blend out speed.
durationnumber-1Duration (ms); -1 = loop.
flagnumber1Animation flag.
playbacknumber0Playback rate.
lockX / lockY / lockZbooleanfalseAxis lock.

Component

Ped component variation on spawn.

FieldTypeDefaultDescription
componentIdnumber0Component slot.
drawableIdnumber0Drawable index.
textureIdnumber0Texture index.
paletteIdnumber0Palette index.

Ped behaviour

All peds created by this system are:

  • Frozen in place
  • Invincible
  • Unable to ragdoll, flee, or react to events
  • Seeing range set to 0
  • Using default component variation unless component is set

Examples

Basic NPC with one option

lua
exports["prp-bridge"]:AddPedInteraction("my_dealer", {
    model = "s_m_y_dealer_01",
    coords = vector3(100.0, 200.0, 30.0),
    heading = 180.0,
    radius = 50.0,
    scenario = "WORLD_HUMAN_STAND_IMPATIENT",
    options = {
        {
            icon = "fas fa-comments",
            label = "Talk to Dealer",
            distance = 2.0,
            onSelect = function()
                openDealerMenu()
            end
        }
    }
})

NPC with animation and multiple options

lua
exports["prp-bridge"]:AddPedInteraction("workshop_npc", {
    model = "s_m_y_mechanic_01",
    coords = vector3(150.0, -300.0, 40.0),
    heading = 90.0,
    radius = 30.0,
    anim = {
        animDict = "anim@amb@business@bgen@bgen_no_work@",
        anim = "stand_phone_phoneputdown_idle_nowork",
        flag = 49
    },
    options = {
        {
            icon = "fas fa-wrench",
            label = "Repair Vehicle",
            distance = 2.5,
            canInteract = function()
                return IsPedInAnyVehicle(PlayerPedId(), false)
            end,
            onSelect = function()
                repairVehicle()
            end
        },
        {
            icon = "fas fa-cart-shopping",
            label = "Buy Parts",
            distance = 2.5,
            onSelect = function()
                openPartsShop()
            end
        }
    }
})

NPC with weapon

lua
exports["prp-bridge"]:AddPedInteraction("armed_guard", {
    model = "s_m_y_blackops_01",
    coords = vector3(200.0, 100.0, 35.0),
    heading = 270.0,
    radius = 60.0,
    scenario = "WORLD_HUMAN_GUARD_STAND",
    weapon = `weapon_carbinerifle`,
    options = {
        {
            icon = "fas fa-gun",
            label = "Talk",
            distance = 2.0,
            onSelect = function()
                openGuardMenu()
            end
        }
    }
})

Manual cleanup

lua
AddEventHandler("onResourceStop", function(resourceName)
    if resourceName ~= GetCurrentResourceName() then return end
    exports["prp-bridge"]:RemovePedInteraction("my_dealer")
    exports["prp-bridge"]:RemovePedInteraction("workshop_npc")
end)

Auto cleanup

Ped interactions are removed automatically when the resource that created them stops. Use manual cleanup only if you need to remove a ped while the resource is still running.