Page 1 of 1
Problem while harvesting.
Posted: Fri Aug 20, 2010 3:52 am
by Rainer12345
Hallo
I use this bot now for something about 1 year. At the beginning for harvesting ... later only for collecting daily-stuff.
Now after the new patch I want to harvest again and noticed a problem. In the profile I set my "level above" and "level below" to -1. So the bot will only attack aggressive mobs. Works fine. The problem is the moment the bot collect the herbs und a mob becomes aggressive. The bot stops harvesting and kills the mob. After killing he goes to the NEXT waypoint instead of start again harvesting. That way I miss nearly 1/3 of the stuff.
First I thought ... no problem ... I take it next round. But if the round is long enough, the mob respawns and ... hm ... you can imagine...
Is there any way to restart collecting after killing the mob?
Thx
Re: Problem while harvesting.
Posted: Fri Aug 20, 2010 8:29 am
by Administrator
Yeah, this was something I had forgot to do when rewriting the new harvesting system. I'll be fixed.
Re: Problem while harvesting.
Posted: Fri Aug 20, 2010 9:26 am
by Rainer12345
Thank you.
I really love this new harvesting system.
Re: Problem while harvesting.
Posted: Fri Aug 20, 2010 9:34 am
by Administrator
Can you test the change for me? Open classes/player.lua in notepad, and find this line:
Code: Select all
lastHarvestedNodeAddr = closestHarvestable.Address;
Should be around line 137 (CTRL+G).
Change it to this:
Code: Select all
self:update();
if( not self.Battling ) then
lastHarvestedNodeAddr = closestHarvestable.Address;
else
while( self.Battling ) do
self:target(self:findEnemy(true, nil, evalTargetDefault, self.IgnoreTarget));
self:update();
if( self:haveTarget() ) then
self:fight();
end
end
end
Save it. It *should* now fight all aggressive enemies then return to harvesting.
Re: Problem while harvesting.
Posted: Fri Aug 20, 2010 10:21 am
by Rainer12345
dont seems to work. I tried 5 times.
on 2 of them the mob attacked .. the bot shortly started harvesting ... got interrupted ... killed the mob ... and went on to the next waypoint.
the other 3 tries ... the bot started harvesting ... mob got closer and attacked ... the bot killed the mob ... and went on to the next waypoint.
maybe Im to stupid to copy-paste

... here is the part in my player.lua I changed...
Code: Select all
function CPlayer:harvest(_id, _second_try)
local function findNearestHarvestable(_id, ignore)
ignore = ignore or 0;
local closestHarvestable = nil;
local obj = nil;
local objectList = CObjectList();
objectList:update();
for i = 0,objectList:size() do
obj = objectList:getObject(i);
if( obj ~= nil ) then
if( obj.Type == PT_NODE and obj.Address ~= ignore and (_id == obj.Id or (not _id and database.nodes[obj.Id])) ) then
local dist = distance(self.X, self.Z, obj.X, obj.Z);
if( closestHarvestable == nil ) then
if( distance(self.X, self.Z, obj.X, obj.Z ) < settings.profile.options.HARVEST_DISTANCE ) then
closestHarvestable = obj;
end
else
if( distance(self.X, self.Z, obj.X, obj.Z) <
distance(self.X, self.Z, closestHarvestable.X, closestHarvestable.Z) ) then
-- this node is closer
closestHarvestable = obj;
end
end
end
end
end
return closestHarvestable;
end
local function nodeStillFound(node)
local closestHarvestable = nil;
local obj = nil;
local objectList = CObjectList();
objectList:update();
for i = 0,objectList:size() do
obj = objectList:getObject(i);
if( obj.Address == node.Address ) then
return true;
end
end
return false;
end
yrest(200); -- Make sure we come to a stop before attempting to harvest.
local lastHarvestedNodeAddr = nil;
while(true) do
self:update();
closestHarvestable = findNearestHarvestable(_id, lastHarvestedNodeAddr);
if( closestHarvestable == nil ) then
printf(language[79]);
return;
end
cprintf(cli.yellow, language[95], closestHarvestable.Name);
if( distance(self.X, self.Z, closestHarvestable.X, closestHarvestable.Z) > 80 ) then
self:moveTo(CWaypoint(closestHarvestable.X, closestHarvestable.Z), true);
end
memoryWriteInt(getProc(), self.Address + addresses.pawnTargetPtr_offset, closestHarvestable.Address);
RoMScript("UseSkill(1,1)");
if _id and not database.nodes[closestHarvestable.Id] then -- The rest is not needed if not resource node
return true
end
self:update();
local timeStart = getTime();
while( not self.Harvesting ) do
-- Wait to start harvesting
yrest(100);
self:update();
if( self.Battling ) then
printf(language[78]);
return;
end
if( deltaTime(getTime(), timeStart) > 3000 ) then
-- Maybe the command didn't go through. Try once more.
RoMScript("UseSkill(1,1)");
yrest(500);
break;
end
end
self:update();
timeStart = getTime();
while( self.Harvesting ) do
yrest(100);
self:update();
if( self.Battling ) then
printf(language[78]);
return;
end
if( not nodeStillFound(closestHarvestable) or self.TargetPtr ~= closestHarvestable.Address ) then
break;
end
if( deltaTime(getTime(), timeStart) > 45000 ) then
-- Taking too long. Drop out.
printf("Stop harvesting. Taking too long.\n");
break;
end
end
self:update();
if( not self.Battling ) then
lastHarvestedNodeAddr = closestHarvestable.Address;
else
while( self.Battling ) do
self:target(self:findEnemy(true, nil, evalTargetDefault, self.IgnoreTarget));
self:update();
if( self:haveTarget() ) then
self:fight();
end
end
end
end
end
Anyway ... thanks for your fast response.
Re: Problem while harvesting.
Posted: Fri Aug 20, 2010 10:33 am
by Administrator
Ok, at around line 122, you'll see this:
Code: Select all
if( self.Battling ) then
printf(language[78]);
return;
end
Change the return line like so:
Code: Select all
if( self.Battling ) then
printf(language[78]);
--return;
end
Now does it work?
Re: Problem while harvesting.
Posted: Fri Aug 20, 2010 11:18 am
by Rainer12345
didnt work.
this part you can find twice in player.lua
Code: Select all
if( self.Battling ) then
printf(language[78]);
--return;
I tried 3 times ... changed first part ... changed second part ... changed both parts ... each change with one test ... all with the same result:
... the bot started harvesting ... mob came closer and attacked ... the bot got interrupted ... and didnt react...
the bot not targeted the mob ... the bot not attacked the mob ... the bot not started harvesting again ... just stand at the waypoint and took damage ... I waited for one minute ... thats it ...
here again the part of the player.lua I changed:
Code: Select all
while( not self.Harvesting ) do
-- Wait to start harvesting
yrest(100);
self:update();
if( self.Battling ) then
printf(language[78]);
--return;
end
if( deltaTime(getTime(), timeStart) > 3000 ) then
-- Maybe the command didn't go through. Try once more.
RoMScript("UseSkill(1,1)");
yrest(500);
break;
end
end
self:update();
timeStart = getTime();
while( self.Harvesting ) do
yrest(100);
self:update();
if( self.Battling ) then
printf(language[78]);
--return;
end
if( not nodeStillFound(closestHarvestable) or self.TargetPtr ~= closestHarvestable.Address ) then
break;
end
if( deltaTime(getTime(), timeStart) > 45000 ) then
-- Taking too long. Drop out.
printf("Stop harvesting. Taking too long.\n");
break;
end
end
Re: Problem while harvesting.
Posted: Sat Aug 21, 2010 2:34 am
by rock5
Administrator wrote:Can you test the change for me? Open classes/player.lua in notepad, and find this line:
Code: Select all
lastHarvestedNodeAddr = closestHarvestable.Address;
Should be around line 137 (CTRL+G).
Change it to this:
Code: Select all
self:update();
if( not self.Battling ) then
lastHarvestedNodeAddr = closestHarvestable.Address;
else
while( self.Battling ) do
self:target(self:findEnemy(true, nil, evalTargetDefault, self.IgnoreTarget));
self:update();
if( self:haveTarget() ) then
self:fight();
end
end
end
Save it. It *should* now fight all aggressive enemies then return to harvesting.
Will something like this work with player:target_Object()?
Re: Problem while harvesting.
Posted: Sat Aug 21, 2010 6:24 am
by Administrator
rock5 wrote:
Will something like this work with player:target_Object()?
I'm not sure what you're asking.
Re: Problem while harvesting.
Posted: Sat Aug 21, 2010 6:59 am
by rock5
Administrator wrote:rock5 wrote:
Will something like this work with player:target_Object()?
I'm not sure what you're asking.
player:target_Object() needs to check for aggro too while collecting or it can get stuck trying to collect something but always getting interrupted by an aggressive mob. Don't worry I'm looking into it. I'm trying to design it so it will still harvest the item after it's killed the mob.
Re: Problem while harvesting.
Posted: Sun Aug 22, 2010 2:45 am
by MiesterMan
Too many posts, please delete this one.
Re: Problem while harvesting.
Posted: Sun Aug 22, 2010 5:55 am
by MiesterMan
Too many posts, please delete this one.
Re: Problem while harvesting.
Posted: Sun Aug 22, 2010 6:58 am
by MiesterMan
The edited code below includes:
- Fix for canceling harvesting from battle thus skipping node
- Fix for failing to harvest because character is still moving thus skipping node
- Fix for canceling harvesting from buffing while harvesting thus skipping node
CPlayer:cast(skill) before "-- Wait for casting to start (if it has a decent cast time)"
Code: Select all
-- Check if harvesting and correct waypoint
if self.Harvesting then
if __WPL.Direction == 1 then __WPL:setWaypointIndex(__WPL.CurrentWaypoint - 1) end;
if __WPL.Direction == 2 then __WPL:setWaypointIndex(__WPL.CurrentWaypoint + 1) end;
end
CPlayer:harvest from line 74 to the end of the function.
Code: Select all
-- Make sure we come to a stop before attempting to harvest.
repeat
self:update();
local curX = self.X;
local curY = self.Y;
local curZ = self.Z;
yrest(200);
until curX == self.X and curY == self.Y and curZ == self.Z
local lastHarvestedNodeAddr = nil;
while(true) do
self:update();
closestHarvestable = findNearestHarvestable(_id, lastHarvestedNodeAddr);
if( closestHarvestable == nil ) then
printf(language[79]);
return;
end
cprintf(cli.yellow, language[95], closestHarvestable.Name);
if( distance(self.X, self.Z, closestHarvestable.X, closestHarvestable.Z) > 80 ) then
self:moveTo(CWaypoint(closestHarvestable.X, closestHarvestable.Z), true);
end
memoryWriteInt(getProc(), self.Address + addresses.pawnTargetPtr_offset, closestHarvestable.Address);
RoMScript("UseSkill(1,1)");
if _id and not database.nodes[closestHarvestable.Id] then -- The rest is not needed if not resource node
return true
end
self:update();
local timeStart = getTime();
-- Set repeat waypoint waypoint
local reWapt = 1;
if __WPL.Direction == 1 then reWapt = __WPL.CurrentWaypoint - 1 end;
if __WPL.Direction == 2 then reWapt = __WPL.CurrentWaypoint + 1 end;
while( not self.Harvesting ) do
-- Wait to start harvesting
yrest(100);
self:update();
if( self.Battling ) then
printf(language[78]);
__WPL:setWaypointIndex(reWapt);
return;
end
if( deltaTime(getTime(), timeStart) > 3000 ) then
-- Maybe the command didn't go through. Try once more.
RoMScript("UseSkill(1,1)");
yrest(500);
break;
end
end
self:update();
timeStart = getTime();
while( self.Harvesting ) do
yrest(100);
self:update();
if( self.Battling ) then
printf(language[78]);
__WPL:setWaypointIndex(reWapt);
return;
end
if( not nodeStillFound(closestHarvestable) or self.TargetPtr ~= closestHarvestable.Address ) then
break;
end
if( deltaTime(getTime(), timeStart) > 45000 ) then
-- Taking too long. Drop out.
printf("Stop harvesting. Taking too long.\n");
break;
end
end
lastHarvestedNodeAddr = closestHarvestable.Address;
end
Edit: Tested final cut, working as intended.
New problem found. The harvest function will actually attempt to harvest all nearby harvestables but once the first node is down and it goes to the next it seems to have the same issue about character moving after harvesting starts. I will look into it.
More edited: After some thought using waypoints isn't the best option, saving a pointer and adding an additional condition to revisit the node after combat would be better. This way "hunting" nodes might be viable later on.