I am making a simple script which is an icon over your head when u speak but i am stuck at the last part

I don’t know how to set a range in which u can see the icon over another players head + want to make it so it won’t appear through walls. Any ideas how to do it?

Here is my code:

Citizen.CreateThread(function()
while true do
Wait( 400 )

	for id = 0, 32 do
		if NetworkIsPlayerActive( id ) then -- and GetPlayerPed( id ) ~= GetPlayerPed( -1 )

			ped = GetPlayerPed( id )

			if GetPlayerPed( id ) ~= GetPlayerPed( -1 ) then
					headDisplayId = N_0xbfefe3321a3f5015(ped, "", false, false, "", false )
			else
				headDisplayId = N_0xbfefe3321a3f5015(ped, "", false, false, "", false )
			end

			if NetworkIsPlayerTalking(id) then
				N_0x63bb75abedc1f6a0(headDisplayId, 9, true)
				N_0xd48fe545cd46f857(headDisplayId, 9, 128) 
			else
				N_0x63bb75abedc1f6a0(headDisplayId, 9, false)
			end
		end
	end
end

end)

hey i see your code are u a Dev for FiveM if u are dm Ovyy #6666 if u can make a fiveM server becuse it looks like u can!

You can find a pretty good example for range and line-of-sight in the default “playernames” resource.

On line 92, of playernames_cl.lua:

if distance < 250 and HasEntityClearLosToEntity(PlayerPedId(), ped, 17) then
                SetMpGamerTagVisibility(tag, gtComponent.GAMER_NAME, true)
                --continue code...
            else
                SetMpGamerTagVisibility(tag, gtComponent.GAMER_NAME, false)
                --other code...
            end

The resource makes use of HasEntityClearLosToEntity native, with entity1 being the client player, and entity2 being the player entity that has the gamertag showing.

Yeah i saw this one but i don’t know how to implement it in my code do you have any ideas on that?

You can try this:

Citizen.CreateThread(function()
  while true do
    Wait( 400 )
    for id = 0, 32 do
      if NetworkIsPlayerActive( id ) then -- and GetPlayerPed( id ) ~= GetPlayerPed( -1 )
        ped = GetPlayerPed( id )

        if GetPlayerPed( id ) ~= GetPlayerPed( -1 ) then
            headDisplayId = N_0xbfefe3321a3f5015(ped, "", false, false, "", false )
        else
          headDisplayId = N_0xbfefe3321a3f5015(ped, "", false, false, "", false )
        end

        if NetworkIsPlayerTalking(id) then
          local distance = #(GetEntityCoords(ped) - GetEntityCoords(PlayerPedId()))
          if distance < 250 and HasEntityClearLosToEntity(PlayerPedId(), ped, 17) then
            N_0x63bb75abedc1f6a0(headDisplayId, 9, true)
            N_0xd48fe545cd46f857(headDisplayId, 9, 128)
          else
            N_0x63bb75abedc1f6a0(headDisplayId, 9, false)
          end
        else
          N_0x63bb75abedc1f6a0(headDisplayId, 9, false)
        end
      end
    end
  end
end)

I basically added the range and LoS check only after NetworkIsPlayerTalking(id) is true.
I don’t know if this is most efficient approach to this, but for 32 players, it should not matter that much.

Ty this one rly helped.