Get informations about the entity target

I’m currently searching a function or method to get informations on the player who I’m targeting.
I found a native “GET_ENTITY_PLAYER_IS_FREE_AIMING_AT” which returns the entityID but a same player has different entityID for each other players.
I would like to get the name of the player for example.

If someone has an idea, I’m waiting to read you.

The entity returned should be a ped. You can test this with IsEntityAPed()

Yes, i know the entity should be a ped and i tried IsEntityAPed() and i have 1 in return.
Can we retrieve information to differentiate a ped from another ?

IsPedAPlayer(Ped ped)

Yes we can use this native for make difference between players and PNJ but we can’t make difference between 2 players.

Try GetNearestPlayerToEntity() - I don’t know if this will ignore the entity if it is a player

I have successfully done this by looping through each player in the server and then comparing their Ped to my earlier result (Ped entity).

Thanks, I’ll try this and give you feedback.

@Povers Hi Povers, did you tried and can you give feedback ?
Thanks in advance

Hey i find that :

-- Get entity in front of player
function GetEntInFrontOfPlayer(Distance, Ped)
  local Ent = nil
  local CoA = GetEntityCoords(Ped, 1)
  local CoB = GetOffsetFromEntityInWorldCoords(Ped, 0.0, Distance, 0.0)
  local RayHandle = StartShapeTestRay(CoA.x, CoA.y, CoA.z, CoB.x, CoB.y, CoB.z, -1, Ped, 0)
  local A,B,C,D,Ent = GetRaycastResult(RayHandle)
  return Ent

-- Camera's coords
function GetCoordsFromCam(distance)
  local rot = GetGameplayCamRot(2)
  local coord = GetGameplayCamCoord()

  local tZ = rot.z * 0.0174532924
  local tX = rot.x * 0.0174532924
  local num = math.abs(math.cos(tX))

  newCoordX = coord.x + (-math.sin(tZ)) * (num + distance)
  newCoordY = coord.y + (math.cos(tZ)) * (num + distance)
  newCoordZ = coord.z + (math.sin(tX) * 8.0)
  return newCoordX, newCoordY, newCoordZ

-- Get entity's ID and coords from where player sis targeting
function Target(Distance, Ped)
  local Entity = nil
  local camCoords = GetGameplayCamCoord()
  local farCoordsX, farCoordsY, farCoordsZ = GetCoordsFromCam(Distance)
  local RayHandle = StartShapeTestRay(camCoords.x, camCoords.y, camCoords.z, farCoordsX, farCoordsY, farCoordsZ, -1, Ped, 0)
  local A,B,C,D,Entity = GetRaycastResult(RayHandle)
  return Entity, farCoordsX, farCoordsY, farCoordsZ

In JS :

function GetEntInFrontOfPlayer(Distance, Ped) {
  let CoA = GetEntityCoords(Ped, true);
  let CoB = GetOffsetFromEntityInWorldCoords(Ped, 0.0, Distance, 0.0)
  let RayHandle = StartShapeTestRay(CoA[0], CoA[1], CoA[2], CoB[0], CoB[1], CoB[2], -1, Ped, 0);
  let A, B, C, D, Ent = GetRaycastResult(RayHandle)
  return Ent;

//Camera's coords
function GetCoordsFromCam(distance) {

  let rot = GetGameplayCamRot(2);
  let coord = GetGameplayCamCoord();

  let tZ = rot[2] * 0.0174532924;
  let tX = rot[0] * 0.0174532924;
  let num = Math.abs(Math.cos(tX));

  let newCoordX = coord[0] + (-Math.sin(tZ)) * (num + distance);
  let newCoordY = coord[1] + (Math.cos(tZ)) * (num + distance);
  let newCoordZ = coord[2] + (Math.sin(tX) * 8.0);
  return [newCoordX, newCoordY, newCoordZ];

// Get entity's ID and coords from where player sis targeting
function Target(Distance, Ped) {
  let camCoords = GetGameplayCamCoord();
  let [farCoordsX, farCoordsY, farCoordsZ] = GetCoordsFromCam(Distance);
  let RayHandle = StartShapeTestRay(camCoords[0], camCoords[1], camCoords[2], farCoordsX, farCoordsY, farCoordsZ, -1, Ped, 0);
  let A, B, C, D, Entity = GetRaycastResult(RayHandle);
  return [Entity, farCoordsX, farCoordsY, farCoordsZ];

setTick(() => {
  var target = Target(2, PlayerPedId());