Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How can I fix this little piece of code?


minipimp
 Share

Recommended Posts

```
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.
Link to comment
Share on other sites

Try

```
If bestIndex > 0 And bestIndex <> myTarget Then
call playertarget(bestIndex, TARGET_TYPE_NPC) // I always found it odd how some subs (not all) need to be called :S
End If
```
Looks like playertarget (the sub or function) is missing did you type it exact?if you named the sub, playerTarget then it needs to be playerTarget (case matters)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...