Problem while harvesting.

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
Rainer12345
Posts: 8
Joined: Wed Jul 07, 2010 1:42 am

Problem while harvesting.

#1 Post by Rainer12345 » Fri Aug 20, 2010 3:52 am

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

User avatar
Administrator
Site Admin
Posts: 5330
Joined: Sat Jan 05, 2008 4:21 pm

Re: Problem while harvesting.

#2 Post by Administrator » Fri Aug 20, 2010 8:29 am

Yeah, this was something I had forgot to do when rewriting the new harvesting system. I'll be fixed.

Rainer12345
Posts: 8
Joined: Wed Jul 07, 2010 1:42 am

Re: Problem while harvesting.

#3 Post by Rainer12345 » Fri Aug 20, 2010 9:26 am

Thank you.

I really love this new harvesting system.

User avatar
Administrator
Site Admin
Posts: 5330
Joined: Sat Jan 05, 2008 4:21 pm

Re: Problem while harvesting.

#4 Post by Administrator » Fri Aug 20, 2010 9:34 am

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.

Rainer12345
Posts: 8
Joined: Wed Jul 07, 2010 1:42 am

Re: Problem while harvesting.

#5 Post by Rainer12345 » Fri Aug 20, 2010 10:21 am

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.

User avatar
Administrator
Site Admin
Posts: 5330
Joined: Sat Jan 05, 2008 4:21 pm

Re: Problem while harvesting.

#6 Post by Administrator » Fri Aug 20, 2010 10:33 am

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?

Rainer12345
Posts: 8
Joined: Wed Jul 07, 2010 1:42 am

Re: Problem while harvesting.

#7 Post by Rainer12345 » Fri Aug 20, 2010 11:18 am

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

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Problem while harvesting.

#8 Post by rock5 » Sat Aug 21, 2010 2:34 am

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()?
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
Administrator
Site Admin
Posts: 5330
Joined: Sat Jan 05, 2008 4:21 pm

Re: Problem while harvesting.

#9 Post by Administrator » Sat Aug 21, 2010 6:24 am

rock5 wrote: Will something like this work with player:target_Object()?
I'm not sure what you're asking.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Problem while harvesting.

#10 Post by rock5 » Sat Aug 21, 2010 6:59 am

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
MiesterMan
Posts: 543
Joined: Tue Jul 06, 2010 9:15 pm
Location: Between the Second and Third Circles of Hell

Re: Problem while harvesting.

#11 Post by MiesterMan » Sun Aug 22, 2010 2:45 am

Too many posts, please delete this one.
Last edited by MiesterMan on Sun Aug 22, 2010 12:24 pm, edited 2 times in total.

User avatar
MiesterMan
Posts: 543
Joined: Tue Jul 06, 2010 9:15 pm
Location: Between the Second and Third Circles of Hell

Re: Problem while harvesting.

#12 Post by MiesterMan » Sun Aug 22, 2010 5:55 am

Too many posts, please delete this one.
Last edited by MiesterMan on Sun Aug 22, 2010 1:12 pm, edited 4 times in total.

User avatar
MiesterMan
Posts: 543
Joined: Tue Jul 06, 2010 9:15 pm
Location: Between the Second and Third Circles of Hell

Re: Problem while harvesting.

#13 Post by MiesterMan » Sun Aug 22, 2010 6:58 am

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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 0 guests