Check for another player in marker/circle

Hi there everyone,

I need to modify a loop that allows someone standing in a circle to check for another player in the circle before it allows them to interact with something.

AddEventHandler('crate:hasEnteredMarker', function(zone, name)
  if LastZone == 'containerzone' then
    CurrentAction     = 'open_container'
    CurrentActionMsg  = 'Press ~INPUT_CONTEXT~ to open container'
    CurrentActionData = {zone = zone}
    CurrentActionName = name
  end
end)

And I’m not sure how to do that. I looked in the natives for “nearby” but didn’t see anything to catch players The GetClosestPed native states:

This function does not return ped who is:  
1. Standing still  
2. Driving  
3. Fleeing  
4. Attacking  
This function only work if the ped is:  
1. walking normally.  
2. waiting to cross a road. 

Which won’t do at all. The two players will likely be standing still when the check occurs in the marker.

Is there any way for me to determine if there’s another player nearby?

I’m pretty new to FiveM development, but I don’t think GetClosestPed is the function you want. Based on the docs, I think you will want GetClosestPlayer or GetPlayersInArea.

Use Vdist to calculate distance between player and that point, if it’s lower than the circle’s diameter trigger the event.

I’m well past calculating distance to the player, the marker takes care of that. I need to have the client check for other players in the same radius from the item, preferably without the overhead of dealing with it serverside.

I will give them a looksee, thanks!

1 Like