Simply use getPedOccupiedVehicle.
ddEventHandler( "onClientRender",root,
function( )
local px, py, pz, tx, ty, tz, dist
px, py, pz = getCameraMatrix( )
for _, v in ipairs( getElementsByType 'player' ) do
--if(player ~= localPlayer) then
if not getPedOccupiedVehicle(v) then
tx, ty, tz = getElementPosition( v )
dist = math.sqrt( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2 )
if dist < 30.0 then
if isLineOfSightClear( px, py, pz, tx, ty, tz, true, false, false, true, false, false, false,localPlayer ) then
local sx, sy, sz = getPedBonePosition( v, 6 )
local x,y = getScreenFromWorldPosition( sx, sy, sz +1.5 )
if x then -- getScreenFromWorldPosition returns false if the point isn't on screen
dxDrawLine3D ( sx, sy, sz+0.2,sx, sy, sz+1.35, tocolor ( 0, 210,0, 90 ), 1.45,false)
dxDrawText( "Warrior", x-9.5, y, x, y, tocolor(0,210,0,150), 0.85 + ( 15 - dist ) * 0.035, "default-bold" )
end
end
end
end
end
end
)