Ok..most of this is pretty easy stuff for anyone who made it past the 'whoa..what's the objMgr stage' but I don't use LUA at all, only memory_read and mouse/keybd, so..
code to find if there is a mob in a specific range of a specific point
Ie. Are there any mobs within a 25u radius of 123,456,-789.
Code:
Private Function FindClosestMobBase(ByVal centerPos As pathPoint, ByVal maxRange As UInt32) As UInt32
Dim tempObj As New wowBasicObject(FirstObjectAddress)
Dim mobObj As New wowMobObject(FirstObjectAddress)
Dim closestDistance As UInt32 = UInt32.MaxValue
Dim returnMobObjBase As UInt32 = 0
'Dim hasMobAlready As Boolean = False
While tempObj.BaseAddress <> 0
If tempObj.Type = enumBasicObjectType.NPC Then ' ==3
mobObj.BaseAddress = tempObj.BaseAddress
If wowBasicObject.GetDistanceBetweenObjects(centerPos.x, centerPos.y, mobObj.XPos, mobObj.YPos) < maxRange Then 'in-distance
If mobObj.Level > 1 And mobObj.HP > 1 Then
'it's alive and not a lvl 1 'critter' (note: this bugs if you're atctually trying to fight lvl 1 mobs..doesn't work..or, shouldn't.)
If wowBasicObject.GetDistanceBetweenObjects(centerPos.x, centerPos.y, mobObj.XPos, mobObj.YPos) < closestDistance Then
'is closest so far..record it.
If Math.Abs(LocalPlayer.ZPos - mobObj.ZPos) <= 20 Then ' 20??
If theWowWorld.combat.IsBlackListed(mobObj.Guid) = False Then
returnMobObjBase = mobObj.BaseAddress
closestDistance = wowBasicObject.GetDistanceBetweenObjects(centerPos.x, centerPos.y, mobObj.XPos, mobObj.YPos)
'else
'is blacklisted, ignore it --> currently not used
End If
' Else
'probably too far above/below
End If
'else
'not closer than closest object so far
End If
' Else
'is dead or a lvl. 1 critter
End If
'Else
'is really far away
End If
'Else
'curscanobj wasn't an NPC
End If
Try
If memReader.ReadUInt32(New IntPtr(tempObj.BaseAddress + EnumOffsets.wowBasicObjectOffsets.NextObjectPointer)) = FirstObjectAddress Then
'we've reached the end of the loop..exit while
'if we got here..mob.guid not found!
Exit While
ElseIf memReader.ReadUInt32(New IntPtr(tempObj.BaseAddress + EnumOffsets.wowBasicObjectOffsets.NextObjectPointer)) = 0 Then
'NBP is invalid...leave
'Unknown error?
Exit While
Else
'should be a good NBP,keep looping
tempObj.BaseAddress = memReader.ReadUInt32(New IntPtr(tempObj.BaseAddress + EnumOffsets.wowBasicObjectOffsets.NextObjectPointer))
End If
Catch ex As Exception
'DoOutput("FindClosestMobBase::" & ex.Message)
Exit While
End Try
End While
If closestDistance = UInt32.MaxValue Then
'closest_distance hasn't change..no mob found in range
Return 0 ' INDICATES FAIL
Else
'we found one..return it's baseaddress
Return returnMobObjBase ' SUCCESS
End If
End Function
Then here is my code to actually target the mob (run to it, and press tab key) ..I don't have a 'pathing system' yet, as of now it's super reliant on setting up path points w/ attack radiuses(ii?) ..so in this code it just runs a straight line to the target (ie. you set up points that are semi-far away from objects, and set a semi-small atk_radius..it works for now, I think)
Code:
Private Sub TargetClosestMob(ByVal maxDistance As UInt32)
''check if any mobs near lp
Dim xx As UInt32 = FindClosestMobBase(LocalPlayer.PosAsPathPoint, maxDistance)
If xx = 0 Then
'no mobs found that close
Else
'mob(s) found in range!
Dim tempTargMob As New wowMobObject(xx)
'tempTargMob now == closest mob found, as mob object
If tempTargMob.DistanceFromLocalPlayer > 35 Then
theWowWorld.runPath.RunPlayerToPoint(tempTargMob.XPos, tempTargMob.YPos, 35) 'TODO 35 = bow_max_range..should be max_spell_distance or..something non-static.
End If
Dim mPoint As New wowGamePoint
mPoint.x = tempTargMob.XPos
mPoint.y = tempTargMob.YPos
theWowWorld.runPath.RightClickTurn(mPoint, 0.08)
'mob should be in front of us
'press tab key
keybd_event(&H9, 0, &H1, 0)
Threading.Thread.Sleep(300 + Rnd(200))
keybd_event(&H9, 0, &H2, 0)
'should have target now?
Threading.Thread.Sleep(1250)
'sleep to account for lag
'If HasAliveTarget() = True then
'DoOutput("Target Successful")
'Else
'DoOutput("Target Failed??")
'End If
End If
End Sub
Anyway, maybe this should be in vb.net section..but not many ppl in that section to wow stuff: A few of you use vb too..so, any comments?
ps. I left out the code for .RunToPoint and .RightClickTurn() those are semi-private. And the classes themselves..again, private..but my names are semi-obvious..you should get the general idea? Any helpful suggestions?