minipimp Posted September 19, 2014 Author Share Posted September 19, 2014 ```Public Sub FindNearestTarget()Dim i As Long, x As Long, y As Long, x2 As Long, y2 As Long, xDif As Long, yDif As LongDim bestX As Long, bestY As Long, bestIndex As Longx2 = GetPlayerX(MyIndex)y2 = GetPlayerY(MyIndex)bestX = 255bestY = 255For i = 1 To MAX_MAP_NPCSIf MapNpc(i).num > 0 Thenx = MapNpc(i).xy = MapNpc(i).y' find the difference - xIf x < x2 ThenxDif = x2 - xElseIf x > x2 ThenxDif = x - x2ElsexDif = 0End If' find the difference - yIf y < y2 ThenyDif = y2 - yElseIf y > y2 ThenyDif = y - y2ElseyDif = 0End If' best so far?If (xDif + yDif) < (bestX + bestY) ThenbestX = xDifbestY = yDifbestIndex = iEnd IfEnd IfNext' target the bestIf bestIndex > 0 And bestIndex <> myTarget Then playertarget bestIndex, TARGET_TYPE_NPCEnd 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 More sharing options...
lexkymbeth Posted September 19, 2014 Share Posted September 19, 2014 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 :SEnd 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 More sharing options...
abhi2011 Posted September 19, 2014 Share Posted September 19, 2014 Either do what Lex said or do this: ```If bestIndex > 0 And bestIndex <> myTarget Then call playertarget(bestIndex, TARGET_TYPE_NPC)``` Link to comment Share on other sites More sharing options...
minipimp Posted September 19, 2014 Author Share Posted September 19, 2014 There is no playerTarget sub for that to run to though. Link to comment Share on other sites More sharing options...
minipimp Posted September 19, 2014 Author Share Posted September 19, 2014 Okay I got it to work with using that If statement and myTarget = (bestIndex). I took out the targettype npc. how would i add it in ?```' target the bestIf bestIndex > 0 And bestIndex <> myTarget Then myTarget = (bestIndex)End If``` Link to comment Share on other sites More sharing options...
lexkymbeth Posted September 19, 2014 Share Posted September 19, 2014 There is no sub playertarget? If your ripping from another engine you should also get its dependencies the sub you have there just does checks playertarget will do the action Link to comment Share on other sites More sharing options...
minipimp Posted September 19, 2014 Author Share Posted September 19, 2014 I looked this rip up from a while back on another post from a year or 2 ago. I guess I can go find the sub from it ^-^ . Thanks yall Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now