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.
0xE143FA2249364369GetClosestObjectOfType0xE143FA2249364369Signature
Object GET_CLOSEST_OBJECT_OF_TYPE(float x, float y, float z, float radius, Hash modelHash, BOOL missionScriptObject, BOOL scriptHostObject, BOOL networkObject);Parameters
| Name | Type | Description |
|---|---|---|
x | float | — |
y | float | — |
z | float | — |
radius | float | — |
modelHash | Hash | — |
missionScriptObject | BOOL | — |
scriptHostObject | BOOL | — |
networkObject | BOOL | — |
Returns Object
Description
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
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)
endVerified in game on the Borderline RP server, November 2026.
Usage
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#
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());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.InvokeNativeneeds the number — passjoaat("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. Write10.0orvalue + 0.0. The generated JS wrappers add0.0000001to non-zero floats for the same reason.
See also
DOOR_SYSTEM_GET_ACTIVEReturns a list of door system entries: a door system hash (see ADD_DOOR_TO_SYSTEM) and its object handle._ADD_DOOR_TO_SYSTEM_NEWRegisters a door, hashes:FREEZE_ENTITY_POSITIONFreezes or unfreezes an entity preventing its coordinates to change by the player if set to true.GET_GAME_POOLReturns a list of entity handles (script GUID) for all entities in the specified pool - the data returned is an array as Supported pools
Sources
alloc8or RDR3 NativeDB · VORPCORE RDR3natives · RedM Natives (verified notes)
Something wrong or missing? Contribute a verified note — corrections ship through pull requests.