Page 1 of 1

Questions about harvesting

Posted: Mon Dec 23, 2013 12:47 pm
by Bill D Cat
I'm building my waypoint files for Sascilia Steppes and am attempting to gather Ash wood in order to ensure that my gathering skill level for wood is at least level 8 so that I can harvest Willow for a quest. I'm using a function in my onload section to locate and harvest the Ash only until I get the gathering skill to level 8, then it switches to gathering the Willow. My problem is, occasionally the bot will decide that there is no nearby Ash to gather when the node is exhausted and try to attack it!?! This usually ends up resulting in the bot becoming totally locked up and unresponsive. Any ideas why it tries to use combat skills on gathering nodes?

Code: Select all

			function getWood()
				local _isMounted = player.Mounted
				woodSkill = player:getCraftLevel(CRAFT_WOODCUTTING)
				if 8 > woodSkill then
					repeat
						ash = player:findNearestNameOrId(560018) -- Ash Wood
						if ash and 250 > distance(ash, player) then
							player:moveTo(CWaypoint(ash.X, ash.Z), true)
							player:harvest(560018)
						end
					until ash == nil
				else
					repeat
						willow = player:findNearestNameOrId(560019) -- Willow Wood
						if willow and 250 > distance(willow, player) then
							player:moveTo(CWaypoint(willow.X, willow.Z), true)
							player:harvest(560019)
						end
					until willow == nil
				end
				if _isMounted then player:mount() end
			end

Re: Attacking harvestable nodes?

Posted: Mon Dec 23, 2013 1:55 pm
by rock5
It looks like it is trying to caste Forge between harvests.

I don't understand the problem. Instead of saying what the bot "decides" try describing exactly what happens. Is it failing to cast forge? Is casting Forge interrupting the harvest? Is forge a self cast or friendly cast skill?

Re: Attacking harvestable nodes?

Posted: Mon Dec 23, 2013 6:32 pm
by Bill D Cat
Forge is a Champion's self buff. I was harvesting a node, collected two pieces of wood from it and it started fading. At that point the bot started to cast Forge while the node was still targeted. Then for some reason it just locked up and stopped responding. Pressing END would not pause the bot, though I could abort the script with CTRL-L or kill MM completely with CTRL-C still. No matter what I tried, the script would not resume execution, so I ended up aborting it and manually restarting it at the current waypoint.

I was just confused because of the way the log shows that the bot has found Ash Wood on one line, and on the next there is no harvestables found. Then it tries to cast Forge while targeting the Ash. Then the cycle repeats until the bot locks up.

Re: Attacking harvestable nodes?

Posted: Mon Dec 23, 2013 9:26 pm
by rock5
I'm assuming it's getting stuck in a loop somewhere but I'm having trouble figuring out where. It looks like it exits the harvest function so i don't think that is it. I've looked at your function carefully and I can't see how it could get stuck in that. You could double check that it's not your function by putting a print message in each repeat loop. If when it gets stuck it prints the message again and again then you know it's stuck there.

Is it possible it's getting stuck in some other part of the code?

Re: Attacking harvestable nodes?

Posted: Mon Dec 23, 2013 11:23 pm
by lisa
I dunno I think it is kind of obvious.

Code: Select all

               repeat
                  ash = player:findNearestNameOrId(560018) -- Ash Wood
                  if ash and 250 > distance(ash, player) then
                     player:moveTo(CWaypoint(ash.X, ash.Z), true)
                     player:harvest(560018)
                  end
               until ash == nil
if it finds ash and it is within 250 to the ash then it will move to it and harvest it, what if it finds ash but ash is more than 250 away? it will just keep repeating the loop for ever and ever and ever. From memory the distance to objects in memory is 450, so a node 251-450 distance that is the closest to you of that type will infact put u in a never ending loop.

Re: Attacking harvestable nodes?

Posted: Mon Dec 23, 2013 11:34 pm
by rock5
Or it could be something really obvious. :oops:

I must be half asleep.

Re: Attacking harvestable nodes?

Posted: Tue Dec 24, 2013 1:56 am
by Bill D Cat
Thanks, I didn't realize the distance was quite that large. I've refined my function and it seems to be working fine now.

Code: Select all

			function getWood()
				player:update()
				local _isMounted = player.Mounted
				local woodSkill = player:getCraftLevel(CRAFT_WOODCUTTING)
				local woodType = 560018 -- Ash Wood
				if woodSkill > 8 then
					woodType = 560019 -- Willow Wood
				end
				local wood = player:findNearestNameOrId(woodType)
				if wood and 250 > distance(wood, player) then
					player:moveTo(CWaypoint(wood.X, wood.Z), true)
					player:harvest(woodType)
				end
				if _isMounted then player:mount() end
			end

Re: Attacking harvestable nodes?

Posted: Tue Dec 24, 2013 3:32 am
by lisa
yeah I did some testing on it a long time ago (when I first started on GM detect), the memory distance for objects is roughly 450, Could write up a quite function to work it out easy enough. Just do through all objects and distance to object and "save" the largest distance and then print it. Run that a few times as you move around and you will get a good idea of memory max distance.

Code: Select all

function getmaxdistance(ID)
	local biggestdist = 0
	local biggestname = "NFI"
	local objectList = CObjectList();
	objectList:update();
	local objSize = objectList:size()
	for i = 0,objSize do
		local obj = objectList:getObject(i);
		if obj then
			player:update()
			local distt = distance(player.X,player.Z,obj.X,obj.Z)
			if ID then 
				if obj.Id == ID and obj.X ~= 0 and distt > biggestdist then
					biggestdist = distt
					biggestname = obj.Name
				end
			else
				if obj.X ~= 0 and distt > biggestdist then
					biggestdist = distt
					biggestname = obj.Name
				end
			end
		end
	end
	print(biggestname.." : "..biggestdist)
end
very crude.

Code: Select all

Command> for i = 1,20 do getmaxdistance(560036) yrest(2000) end
Beetroot : 126.74964950122
Beetroot : 126.74964950122
Beetroot : 140.39763726016
Beetroot : 150.77740117873
Beetroot : 536.30074154124
Beetroot : 523.25221161962
Beetroot : 539.25868311131
Beetroot : 574.18289609459
Beetroot : 160.87849571858
Beetroot : 161.48928071738
Beetroot : 165.42705646769
Beetroot : 155.30046021061
Beetroot : 561.8466712678
Beetroot : 559.55259717484
Beetroot : 564.04493358956
Beetroot : 572.09828077326
Beetroot : 165.89135288464
Beetroot : 162.32728266977
Beetroot : 568.60617156103
Beetroot : 576.88728617999
so can get close to 600 distance for nodes, other objects were weird though.

Code: Select all

Flying Ship : 3874.2133801221
Tador's Stone Tablet : 12441.011306651

Re: Attacking harvestable nodes?

Posted: Tue Dec 24, 2013 4:23 am
by rock5
You know you could abbreviate this

Code: Select all

            local wood = player:findNearestNameOrId(woodType)
            if wood and 250 > distance(wood, player) then
               player:moveTo(CWaypoint(wood.X, wood.Z), true)
               player:harvest(woodType)
            end
to

Code: Select all

settings.profile.options.HARVEST_DISTANCE=250
player:harvest(woodType)
Or you could put HARVEST_DISTANCE in your profile.

Re: Attacking harvestable nodes?

Posted: Tue Dec 24, 2013 1:21 pm
by Bill D Cat
What does the _second_try option do? It's referenced only in the function arguments, but nowhere else in the function itself. I was hoping it would be a true/false type argument to retry the harvest if it fails. Typically this happens when you reach a new gathering plateau and begin harvesting the next level of materials.

/classes/player.lua line 380:

Code: Select all

function CPlayer:harvest(_id, _second_try)

Re: Questions about harvesting

Posted: Tue Dec 24, 2013 7:53 pm
by rock5
Um... I think it does nothing. The variable isn't used anywhere. It probably did at some stage.

But I believe the harvest function is set up to recover from interruptions such as being attacked. I'm not sure it's set to recover when it just fails with no interruption. I guess that's why you had the repeat loop earlier. I thought that was a really rare occurrence in later leveling. I guess it would be an issue if you are botting new character harvest skills.

If you try adding the repeat loop again maybe this time add a pause to give the node time to fade so it doesn't try to harvest a fading node. I could probably add a 'fading' check.

Re: Questions about harvesting

Posted: Wed Dec 25, 2013 12:07 pm
by Bill D Cat
I was using the repeat loop in case the gathering failed on its own, and to automatically harvest other nearby nodes without needing to call the function again for each node. I've put the repeat loop back, and have other sanity checks now to exit the loop properly when all nearby nodes have been gathered.

Re: Questions about harvesting

Posted: Fri Dec 27, 2013 1:49 pm
by Marlb0ro
Harvesting something on a steep slope may cause your character to slide down a cm. or two when it reached the node, causing the first harvest to fail cause of movement. It always tries a second time before giving up and moving on with the waypoint. That's my thoughts about second_try anyway.

Re: Questions about harvesting

Posted: Fri Dec 27, 2013 8:34 pm
by Bill D Cat
I've noticed that as well. I try to put a yrest() between the movement and the gather command. Most of the time it fails for me is when I have reached a level where I can gather a new material. The failure rate isn't too bad but it does happen enough that I have to add extra code to catch it when it happens.

Re: Questions about harvesting

Posted: Fri Dec 27, 2013 10:46 pm
by rock5
You could also use the wall hack to reduce sliding.