Some things in EQ2 are targettable but not gatherable, it happens quite often with ? in dungeons.
Code: Select all
'EQ2Harvest Bot. version 1.1
'By WyvernX
' Install Instructions
'1. You MUST install the EQ2Service plugin. Get it from the downloads on the web page.
'2. Configure your data below
'Various Varying Variables
Dim oServiceObject, File, temp, FTarget, TargetID
Dim ResourceIndex, SpawnID, Resources, MobName, ResourceName, NothingClose
Dim ClosestResourceDist, ClosestSpawnID, CurrentResourceDist
Dim HarvestCounter, MaxHarvests, MaxWanderDistance, NumAttempts, MaxAttempts
Dim bQuitOnMaxHarvests, WanderDistance, bIgnoreWanderDistanceIfResourceFound
Dim BadSpawnArray, NumberOfBadSpawns
Dim RX, RY, PX, PY, RH, PH, IX, IY, ClosestSpawnRX, ClosestSpawnRY 'Resource, Player, Initial X and Y values
XUScriptHost.ImportScript "MessageBoxLibrary.vbl"
Dim MessageBoxSample
Set MessageBoxSample = New MessageBoxClass
'Notes: If using patrol route, use a tight/small WanderDistance. If using wander method, use a larger one. Just remember you will wander any where in a square - distance away from the origin!!!
bIgnoreWanderDistanceIfResourceFound = true 'If a resource is outside of our wander area, harvest it anyway. (This could cause to you to move FAR away from home point!)
WanderDistance = 200 'How far the char is allowed to wander around
MaxWanderDistance = 300 'How far to stray away from starting point (if bIgnoreWanderDistanceIfResourceFound is true)
MaxHarvests = 10000 'Will attempt to harvest MaxHarvests times.
bQuitOnMaxHarvets = false 'Log out after MaxHarvests is reached.
MaxAttempts=5 'Max number of tries to gather
'Resources to look for. Syntax: HOTKEY, ResourceName
'Notice, last array has no trailing comma!
Resources = array( _
array("1", "cloven ore"), _
array("1", "wind swept rock"), _
array("2", "armadillo den"), _
array("3", "desert roots"), _
array("4", "wind felled tree") _
)
ClosestResources = array( _
array("0", "NULL") _
)
'////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////
' DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!!!
'////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////
'////////////////////////////////////////////////////////////////////////////
'Set the Log file for our output if necessary
logFilename = GetXUnleashedDirectory() + "\Scripts\EQ2Test.txt" 'debug log file
'Simple Log writing function
function writeLogLine (msg)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim FTarget, File, MyDate, MyTime, temp
MyDate = CStr (FormatDateTime (Date, 1))
MyTime = CStr (FormatDateTime (Time, 3))
Set FTarget = CreateObject("Scripting.FileSystemObject")
Set File = FTarget.OpenTextFile(logFilename, ForAppending, True)
temp = "[" & MyDate & " " & MyTime & "] " & msg & vbCrLf
File.Write temp
File.Close
end function
function WithinRoamArea()
'Check Distance
if (bIgnoreWanderDistanceIfResourceFound = true) then
if (distDiff(IX,RX) < MaxWanderDistance AND distDiff(IY,RY) < MaxWanderDistance) then
WithinRoamArea = true
else
WithinRoamArea = false
end if
else
if (distDiff(IX,RX) < WanderDistance AND distDiff(IY,RY) < WanderDistance) then
WithinRoamArea = true
else
WithinRoamArea = false
end if
end if
end function
sub HandleNoResourcesNearby
writeLogLine("No Resources in this area. Taking a nap!")
for s = 1 to 30
XUScriptPlugin.staStatus.Text = "No Resources nearby. Sleeping " & 30 - s
sleep 100 'Sleep for 30 seconds.
next
XUScriptPlugin.staStatus.Text = "Going to random spot near origin"
for b = LBound(BadSpawnArray) to UBound(BadSpawnArray)
BadSpawnArray(b)=0
next
NavigateXY oServiceObject, IX - WanderDistance + Random(0,WanderDistance * 2), IY - WanderDistance + Random(0,WanderDistance * 2)
end sub
sub HandleBadResource()
'This will take us back to "near" our starting point.
writeLogLine("HandleBadResource Called. Avoid that resource node.")
XUScriptPlugin.staStatus.Text = "Bad Resource/Target! Avoiding it for now. . ."
'NavigateXY oServiceObject, IX - WanderDistance + Random(0,WanderDistance * 2), IY - WanderDistance + Random(0,WanderDistance * 2)
BadSpawnArray(NumberOfBadSpawns) = SpawnID
NumberOfBadSpawns = NumberOfBadSpawns + 1
end sub
'How to find Resources.
'Note, it looks for preference items (lower index in the array) first.
'Might customize this later to look for nearest resources first.
sub FindResource()
NothingClose = "TRUE"
ClosestResourceDist = 9999
writeLogLine("Finding Resource...")
XUScriptPlugin.staStatus.Text = "Looking. . ."
for i = LBound(Resources) to UBound(Resources)
SpawnID = findNearestMob(oServiceObject,Resources(i)(1))
for b = LBound(BadSpawnArray) to UBound(BadSpawnArray)
if (BadSpawnArray(b) = SpawnID) then
writeLogLine("Avoiding this resource, we couldnt get it last time!")
SpawnID = findNextNearestMob(oServiceObject)
if (SpawnID < 0) then 'No more of that type of resource!
exit for
end if
end if
next
if (SpawnID > -1) then '****************************MODIFIED***************************
ResourceIndex = i
writeLogLine("Found Something...")
RX = getMobX(oServiceObject,SpawnID)
RY = getMobY(oServiceObject,SpawnID)
PX = getPlayerX(oServiceObject)
PY = getPlayerY(oServiceObject)
if (WithinRoamArea) then
writeLogLine("Woot! Found a " & Resources(i)(1))
XUScriptPlugin.staStatus.Text = "Found " & Resources(i)(1)
if distDiff(IX,RX) > distDiff(IY,RY) then
CurrentResourceDist = distDiff(IY,RY)
'The goto & harvesting functions will now reference the 'ClosestOLDSTRINGNAME' version of the
'variables as they should always point to the closest resource in the array.
if ClosestResourceDist > CurrentResourceDist then
ClosestResourceDist = CurrentResourceDist
ClosestSpawnRX = RX
ClosestSpawnRY = RY
ClosestResources(0)(0) = Resources(i)(0)
ClosestResources(0)(1) = Resources(i)(1)
ClosestSpawnID = SpawnID
end if
else
CurrentResourceDist = distDiff(IX,RX)
if ClosestResourceDist > CurrentResourceDist then
ClosestResourceDist = CurrentResourceDist
ClosestSpawnRX = RX
ClosestSpawnRY = RY
ClosestResources(0)(0) = Resources(i)(0)
ClosestResources(0)(1) = Resources(i)(1)
ClosestSpawnID = SpawnID
end if
end if
NothingClose = "FALSE"
else
writeLogLine("Nope, too far away!")
SpawnID = -1
end if
end if
next
if NothingClose = "TRUE" then '****************************END MODIFIED***************************
HandleNoResourcesNearby
else
SpawnID = ClosestSpawnID
end if
end sub
sub GotoResource()
writeLogLine("Moving to it...")
If (Index > -1) then
if (ClosestSpawnRX = 0 and ClosestSpawnRY = 0) then '************* MODIFIED
writeLogLine("Bad location?")
XUScriptPlugin.staStatus.Text = "Skipping, bad location?"
Sleep 2000
else
NavigateXY oServiceObject, ClosestSpawnRX, ClosestSpawnRY '************* MODIFIED
end if
end if
end sub
sub HarvestResource()
if (ClosestSpawnID > 0) then 'Make sure we still got a target '************* MODIFIED
writeLogLine("Harvesting...")
XUScriptPlugin.staStatus.Text = "Harvesting. . .Only " & MaxHarvests - HarvestCounter & " more!!!"
SendKeys(ClosestResources(0)(0)) '************* MODIFIED
HarvestCounter = HarvestCounter + 1 'One down!
sleep 5000 + Random(500,1500) 'Wait 5 seconds to harvest + a random delay of .5 to 1.5 seconds
end if
end sub
'Load in the helper functions
writeLogLine("Loading in Library: Navigator")
XUScriptPlugin.staStatus.Text = "Loading libraries... (EQ2Harvest-Navigator)"
XUScriptHost.ImportScript("EQ2Harvest\navigator.vbs")
writeLogLine("Loading in Library: EQ2Service")
XUScriptPlugin.staStatus.Text = "Loading libraries... (EQ2Harvest-EQ2Service)"
XUScriptHost.ImportScript("EQ2Harvest\EQ2Service.vbs")
writeLogLine("Creating EQ2Service Object")
XUScriptPlugin.staStatus.Text = "Loading EQ2Service..."
set oServiceObject = XUScriptPlugin.GetService("EQ2Service.Service")
if Err.Number <> 0 then
XUScriptPlugin.staStatus.Text = "EQ2Service Failed to load!"
Sleep 5000
else
writeLogLine("Doing 1 time init.")
'Any and All initialization
HarvestCounter = 0
IX = getPlayerX(oServiceObject)
IY = getPlayerY(oServiceObject)
NumberOfBadSpawns = 0
redim BadSpawnArray(MaxHarvests)
writeLogLine("Lets do this.")
'Heart of the Script.
Do while HarvestCounter < MaxHarvests
FindResource
if (SpawnID > 0) then
Sleep 2000
GotoResource
writeLogLine("Targeting Resource")
SendKeys("{TAB}") 'To Target the Resource
TargetID = getTargetID(oServiceObject)
if (TargetID > 0) then
MobName = getMobName(oServiceObject, TargetID)
writeLogLine("Targeted Resource: " & MobName)
end if
ResourceName = ClosestResources(0)(1) '************* MODIFIED
if (TargetID <> ClosestSpawnID) then '************* MODIFIED
'Try backing up a little and try again:
writeLogLine("Wrong Target! Trying to back up a little...")
RunBackward
StopRunningBackward
SendKeys("{ESCAPE}")
SendKeys("{TAB}") 'To Target the Resource
TargetID = getTargetId(oServiceObject)
if (TargetID > 0) then
MobName = getMobName(oServiceObject, TargetIndex)
writeLogLine("Targeted Resource: " & MobName)
end if
ResourceName = ClosestResources(0)(1) '************* MODIFIED
if (TargetID <> ClosestSpawnID) then '************* MODIFIED
HandleBadResource
writeLogLine("ARG!!! Could not target the resource!!!")
end if
end if
TargetID = getTargetID(oServiceObject)
NumAttempts=0
Do While NumAttempts < MaxAttempts
if (TargetID = ClosestSpawnID) then HarvestResource '************* MODIFIED
TargetID = getTargetID(oServiceObject)
NumAttempts=NumAttempts+1
loop
if (TargetID = ClosestSpawnID) then HandleBadResource
end if
sleep 200
loop
if (bQuitOnMaxHarvets = true) then
SendKeys("/quit{ENTER}")
end if
set File = Nothing
set FTarget = Nothing
set oServiceObject = Nothing
end if