๐Ÿ“Pos Helper

What it does

Creates a static interaction point at world coordinates without spawning a ped. Wraps a lib.points proximity node, auto-displays the hold UI when players enter range, throttles repeated triggers, and recalculates offsets. The UI is re-armed after each use and automatically cleaned up on resource stop.

Register :

  • Signature : positionRegister(pos, name?, interact?) -> index Pos : vector3 (vec3) world coordinates. A duplicate call with the same XYZ reuses the existing handler.

  • Name : optional string shortcut; when provided without an interact table it becomes the default message. Interact : { message, icon?, intent?, holdKey?, holdTime?, interactRange?, holdDistance?, heightOffset?, canInteract?, onInteract? }

Example :

local STORAGE_POINT = {
    coords = vec3(-40.0, -1095.0, 25.0),
    message = "Open the locker",
    icon = "Box",
    intent = "inform",
    holdKey = 38, -- E
    holdTime = 0.5,
    interactRange = 4.0,
    holdDistance = 2.0,
    heightOffset = 1.2
}

exports["Var-Interact"]:positionRegister(
    STORAGE_POINT.coords,
    nil,
    {
        message = STORAGE_POINT.message,
        icon = STORAGE_POINT.icon,
        intent = STORAGE_POINT.intent,
        holdKey = STORAGE_POINT.holdKey,
        holdTime = STORAGE_POINT.holdTime,
        interactRange = STORAGE_POINT.interactRange,
        holdDistance = STORAGE_POINT.holdDistance,
        heightOffset = STORAGE_POINT.heightOffset,
        canInteract = function(_, dist, spec)
            if dist > 1.5 then
                return false -- Too far to interact
            end
        end,
        onInteract = function(i, _, spec)
            print("Static point triggered", i, spec.pos)
            TriggerEvent("mylife:lockers:open", spec.pos)
        end
    }
)

Notes

  • Interaction stays armed even if the player keeps the key pressed; an internal 200 ms throttle prevents back-to-back callbacks.

  • The hold UI is closed when leaving the area or on resource stop, so there is no manual cleanup required.

Last updated