RedM Natives

GET_CLOSEST_OBJECT_OF_TYPE

Returns the closest object of a model near a point, but not the door props placed by a custom map.

Hash0xE143FA2249364369
Runtime nameGetClosestObjectOfType
NamespaceOBJECT
SideClient
NameOfficial
Docs
Since build1207
GTA V hash0xE143FA2249364369

Signature

Object GET_CLOSEST_OBJECT_OF_TYPE(float x, float y, float z, float radius, Hash modelHash, BOOL missionScriptObject, BOOL scriptHostObject, BOOL networkObject);

Parameters

NameTypeDescription
xfloat—
yfloat—
zfloat—
radiusfloat—
modelHashHash—
missionScriptObjectBOOL—
scriptHostObjectBOOL—
networkObjectBOOL—

Returns Object

Description

alloc8or RDR3 NativeDB

missionScriptObject - if true won't return mission script objects
scriptHostObject - if true won't return script host objects
networkObject - if true won't return networked objects

VORPCORE RDR3natives

Returns the closest object of a specified type within a given radius from a specified position

Verified notes

Reviewed in this portal's repository · by borderline-rp

It returns 0 for door props (door archetypes such as p_door_wrh_gate_r / p_door_wrh_gate_l) placed by a custom ymap without a door ID (CExtensionDefScriptEntityId). It does so even with the exact pivot coordinates, the right model and all three filters false. A raycast does hit the same entity, and GetGamePool('CObject') lists it.

Such a door is not in the door system: it has no doorhash, so it is missing from DoorSystemGetActive and _ADD_DOOR_TO_SYSTEM_NEW cannot register it. To lock it, find it in the object pool and freeze it in its closed rotation. A frozen gate stays shut when a player pushes it.

local function findMapProp(model, pivot)
    local e = GetClosestObjectOfType(pivot.x, pivot.y, pivot.z, 1.0, model, false, false, false)
    if e ~= 0 then return e end
    for _, obj in ipairs(GetGamePool('CObject')) do
        if GetEntityModel(obj) == model and #(GetEntityCoords(obj) - pivot) < 1.0 then return obj end
    end
end

local gate = findMapProp(`p_door_wrh_gate_r`, vector3(-5218.84, -2147.25, 10.79))
if gate then
    SetEntityRotation(gate, rx, ry, rz, 2, true)   -- closed rotation, saved when the gate was shut
    FreezeEntityPosition(gate, true)
end

Verified in game on the Borderline RP server, November 2026.

Usage

Lua
local retval = GetClosestObjectOfType(x, y, z, radius, modelHash, missionScriptObject, scriptHostObject, networkObject)

-- always works, by hash
local retval = Citizen.InvokeNative(0xE143FA2249364369, x, y, z, radius, modelHash, missionScriptObject, scriptHostObject, networkObject, Citizen.ResultAsInteger())
JavaScript and C#
JavaScript
const retval = GetClosestObjectOfType(x, y, z, radius, modelHash, missionScriptObject, scriptHostObject, networkObject);

// by hash
const retval = Citizen.invokeNative('0xE143FA2249364369', x + 0.0000001, y + 0.0000001, z + 0.0000001, radius + 0.0000001, modelHash, missionScriptObject, scriptHostObject, networkObject, Citizen.returnResultAnyway(), Citizen.resultAsInteger());
C#
int retval = Function.Call<int>((Hash)0xE143FA2249364369, x, y, z, radius, modelHash, missionScriptObject, scriptHostObject, networkObject);
  • Hash parameters: the named function also accepts a string and hashes it for you; Citizen.InvokeNative needs the number — pass joaat("name") or a backtick literal like `name`.
  • Float parameters: Lua integers (10, or whole numbers decoded from NUI/JSON) are sent as ints and read as garbage. Write 10.0 or value + 0.0. The generated JS wrappers add 0.0000001 to non-zero floats for the same reason.

See also

Sources

alloc8or RDR3 NativeDB · VORPCORE RDR3natives · RedM Natives (verified notes)

Something wrong or missing? Contribute a verified note — corrections ship through pull requests.