```
Public Sub FindNearestTarget()
Dim i As Long, x As Long, y As Long, x2 As Long, y2 As Long, xDif As Long, yDif As Long
Dim bestX As Long, bestY As Long, bestIndex As Long
x2 = GetPlayerX(MyIndex)
y2 = GetPlayerY(MyIndex)
bestX = 255
bestY = 255
For i = 1 To MAX_MAP_NPCS
If MapNpc(i).num > 0 Then
x = MapNpc(i).x
y = MapNpc(i).y
' find the difference - x
If x < x2 Then
xDif = x2 - x
ElseIf x > x2 Then
xDif = x - x2
Else
xDif = 0
End If
' find the difference - y
If y < y2 Then
yDif = y2 - y
ElseIf y > y2 Then
yDif = y - y2
Else
yDif = 0
End If
' best so far?
If (xDif + yDif) < (bestX + bestY) Then
bestX = xDif
bestY = yDif
bestIndex = i
End If
End If
Next
' target the best
If bestIndex > 0 And bestIndex <> myTarget Then playertarget bestIndex, TARGET_TYPE_NPC
End Sub
```

It says the sub or function of PLAYERTARGET BESTINDEX is undefined. im trying to place this in my engine that is based off of Prospects engine. ( dont hate for using this engine ) How could I convert it to work? Im placing this so when I push the tab button i can cycle through all the nearest npcs around my character instead of using the point to click method.