GET_ENTITY_COORDS
Gets the current coordinates for a specified entity.
Signature
Vector3 GET_ENTITY_COORDS(Entity entity);Parameters
| Name | Type | Description |
|---|---|---|
entity | Entity | The entity to get the coordinates from. |
Returns Vector3 — The current entity coordinates.
Description
Gets the current coordinates for a specified entity. This native is used server side when using OneSync.
See GET_ENTITY_COORDS for client side.
Usage
local retval = GetEntityCoords(entity)
-- always works, by hash
local retval = Citizen.InvokeNative(0x1647f1cb, entity, Citizen.ResultAsVector())JavaScript and C#
const retval = GetEntityCoords(entity);
// by hash
const retval = Citizen.invokeNative('0x1647f1cb', entity, Citizen.returnResultAnyway(), Citizen.resultAsVector());Vector3 retval = Function.Call<Vector3>((Hash)0x1647f1cb, entity);Examples
local function ShowCoordinates()
local player = source
local ped = GetPlayerPed(player)
local playerCoords = GetEntityCoords(ped)
print(playerCoords) -- vector3(...)
end
RegisterNetEvent("myCoordinates")
AddEventHandler("myCoordinates", ShowCoordinates)onNet('myCoordinates', () => {
const player = global.source; // use (global as any).source for Typescript
const ped = GetPlayerPed(player);
const [playerX, playerY, playerZ] = GetEntityCoords(ped);
console.log(`${playerX}, ${playerY}, ${playerZ}`);
});using static CitizenFX.Core.Native.API;
// ...
// In class constructor
EventHandlers["myCoordinates"] += new Action<Player>(ShowCoordinates);
// Delegate method
private void ShowCoordinates([FromSource]Player player) {
Vector3 playerCoords = GetEntityCoords(player.Character);
// or the preferred use of C# wrapper
Vector3 playerCoords = player.Character.Position;
Debug.WriteLine($"{playerCoords}");
}See also
SET_ENTITY_COORDSSets the coordinates (world position) for a specified entity, offset by the radius of the entity on the Z axis.
Sources
Something wrong or missing? Contribute a verified note — corrections ship through pull requests.