Hi guys,
I found a script online for a bot I'm using which works great to gather peacebloom and silverleaf, unfortunately it's not scripted to gathering anything other than those two.
Could someone here kindly explain how I can edit it/what I need to add to the script in order to make it gather other herbs or nodes?
Be gentle, I'm really noob with scripting/botting
script_gather = {
isSetup = false,
useVendor = false,
useMount = true,
nodeObj = nil,
timer = 0,
tickRate = 100,
nextNodeDistance = 5,
gatherDistance = 100,
lootDistance = 3,
lastPathIndex = -1,
message = 'Gather...',
collectMinerals = true,
collectHerbs = true,
herbs = {},
numHerbs = 0,
minerals = {},
numMinerals = 0
}
function script_gather:addHerb(name, id, use)
self.herbs[self.numHerbs] = {}
self.herbs[self.numHerbs][0] = name;
self.herbs[self.numHerbs][1] = id;
self.herbs[self.numHerbs][2] = use;
self.numHerbs = self.numHerbs + 1;
end
function script_gather:addMineral(name, id, use)
self.minerals[self.numMinerals] = {}
self.minerals[self.numMinerals][0] = name;
self.minerals[self.numMinerals][1] = id;
self.minerals[self.numMinerals][2] = use;
self.numMinerals = self.numMinerals + 1;
end
function script_gather:setup()
script_gather:addHerb('Peacebloom', 269, true);
script_gather:addHerb('Silverleaf', 270, false);
script_gather:addMineral('Copper Vein', 310, true);
script_gather:addMineral('Tin Vein', 315, false);
self.isSetup = true;
end
function script_gather:ShouldGather(id)
if(self.collectMinerals) then
for i=0,self.numMinerals - 1 do
if(self.minerals[i][1] == id and self.minerals[i][2]) then
return true;
end
end
end
if(self.collectHerbs) then
for i=0,self.numHerbs - 1 do
if(self.herbs[i][1] == id and self.herbs[i][2]) then
return true;
end
end
end
end
function script_gather:GetNode()
local targetObj, targetType = GetFirstObject();
local bestDist = 9999;
local bestTarget = nil;
while targetObj ~= 0 do
if (targetType == 5) then --GameObject
if(script_gather:ShouldGather(targetObj:GetObjectDisplayID())) then
if(targetObj:IsInLineOfSight() or IsUsingNavmesh()) then
local dist = targetObj:GetDistance();
if(dist < self.gatherDistance and bestDist > dist) then
local _x, _y, _z = targetObj:GetPosition();
if(not IsNodeBlacklisted(_x, _y, _z, 5)) then
bestDist = dist;
bestTarget = targetObj;
end
end
end
end
end
targetObj, targetType = GetNextObject(targetObj);
end
return bestTarget;
end
function script_gathereBugInfo()
-- color
local r = 255;
local g = 2;
local b = 233;
-- position
local y = 152;
local x = 25;
-- info
DrawRectFilled(x - 10, y - 2, x + 230, y + 16, 0, 0, 0, 160, 0, 0);
DrawLine(x - 10, y - 2, x - 10, y + 16, r, g, b, 2);
DrawText(self.message .. " " .. self.lastPathIndex, x, y, r, g, b); y = y + 15;
if(self.nodeObj ~= nil) then
local _x, _y, _z = self.nodeObj:GetPosition();
local _tX, _tY, onScreen = WorldToScreen(_x, _y, _z);
if(onScreen) then
DrawText('^', _tX, _tY, r, g, b);
end
end
end
function script_gather:draw()
script_gathereBugInfo();
end
function script_gather:run()
if(not self.isSetup) then
script_gather:setup();
end
if(GetTimeEX() > self.timer) then
self.timer = GetTimeEX() + self.tickRate;
local localObj = GetLocalPlayer();
local isInCombat = IsInCombat();
self.nodeObj = script_gather:GetNode();
if(isInCombat) then
self.message = "Combat!";
if(GetTarget() ~= 0) then
RunCombatScript(GetTarget():GetGUID());
end
self.lastPathIndex = -1;
return;
else
if (RunRestScript()) then
self.message = "Resting!";
return;
end
end
if (AreBagsFull()) then
if(self.useVendor) then
--NOT DONE
StopBot();
return;
else
SetSatusText("Gather", "Bot Stopped, Bags are Full!");
StopBot();
return;
end
end
if(self.nodeObj ~= nil) then
local _x, _y, _z = self.nodeObj:GetPosition();
local dist = self.nodeObj:GetDistance();
if(dist < self.lootDistance) then
if(IsMoving()) then
StopMoving();
end
if(IsMounted()) then
DisMount();
else
if(not IsLooting() and not IsChanneling()) then
self.nodeObj:GameObjectInteract();
else
LootTarget();
end
end
else
Move(_x, _y, _z);
end
self.lastPathIndex = -1;
return
end
if(IsLooting() or IsCasting() or IsChanneling()
or IsDrinking() or IsEating()) then
return;
end
if(self.useMount and not IsMounted()) then
if(RunMountScript()) then
return;
end
return --FIX, return not working (Could be in water, need to move)
end
if(IsPathLoaded(0)) then
local pathSize = GetPathSize(0); -- walkPath = 0
local _lx, _ly, _lz = localObj:GetPosition();
if(self.lastPathIndex == -1) then
local _bestDist = 1000;
for index = 0, pathSize do
local _x, _y, _z = GetPathPositionAtIndex(0, index);
if(GetDistance3D(_x, _y, _z, _lx, _ly, _lz) < _bestDist) then
_bestDist = GetDistance3D(_x, _y, _z, _lx, _ly, _lz);
self.lastPathIndex = index;
end
end
else
local _x, _y, _z = GetPathPositionAtIndex(0, self.lastPathIndex);
Move(_x, _y, _z);
if(GetDistance3D(_x, _y, _z, _lx, _ly, _lz) < self.nextNodeDistance) then
self.lastPathIndex = self.lastPathIndex + 1;
if(self.lastPathIndex >= pathSize) then
self.lastPathIndex = 0;
end
end
end
end
end
end
function script_gather:menu()
if(not self.isSetup) then
script_gather:setup();
end
if (CollapsingHeader("[Gather")) then
wasClicked, self.useMount = Checkbox("Use Mount", self.useMount);
self.gatherDistance = SliderFloat("Gather Distance", 1, 100, self.gatherDistance);
self.lootDistance = SliderFloat("Loot Distance", 1, 6, self.lootDistance);
self.nextNodeDistance = SliderFloat("Next Node Distance", 1, 10, self.nextNodeDistance);
self.tickRate = SliderFloat("Tick Rate", 1, 1000, self.tickRate);
wasClicked, self.collectMinerals = Checkbox("Mining", self.collectMinerals);
wasClicked, self.collectHerbs = Checkbox("Herbalism", self.collectHerbs);
if(self.collectMinerals) then
Separator();
Text('Minerals');
for i=0,self.numMinerals - 1 do
wasClicked, self.minerals[i][2] = Checkbox(self.minerals[i][0], self.minerals[i][2]);
end
end
if(self.collectHerbs) then
Separator();
Text('Herbs');
for i=0,self.numHerbs - 1 do
wasClicked, self.herbs[i][2] = Checkbox(self.herbs[i][0], self.herbs[i][2]);
end
end
end
end