Page 1 of 1

use nearest waypoint when stuck

Posted: Mon Jan 31, 2011 2:34 am
by Personalausweis
hi there,

is it possible to make my bot run to the nearest waypoint when he is stuck and cant get to his next waypoint?

Re: use nearest waypoint when stuck

Posted: Mon Jan 31, 2011 3:01 am
by rock5
I think it already does that, around the 3rd unstick.

Re: use nearest waypoint when stuck

Posted: Mon Jan 31, 2011 3:07 am
by lisa
It would involve changing the bot.lua but yes it is possible.

As it is it gets to the unstuck count of 11 which is greater then the value set by default as 10 and then logs out.

You could add in at say unstuck count of 5 to then go to nearest WP.

You could add something like this at around line 737, it's untested but should work.

Code: Select all

if player.Unstick_counter == 5 then
__WPL:setWaypointIndex(__WPL:getNearestWaypoint(player.X, player.Z, player.Y));
end
I couldn't find anything in bot.lua about it going nearest wp at 3.

Re: use nearest waypoint when stuck

Posted: Mon Jan 31, 2011 6:11 am
by rock5
When they said they couldn't go to the next waypoint I thought they wanted to go to the previous waypoint. I see the benefit now of going to the 'nearest' waypoint.

Line 737? The unstick function is around line 2000. Shouldn't that go in about line 2011?

Re: use nearest waypoint when stuck

Posted: Mon Jan 31, 2011 6:35 am
by lisa
hmm i show line 738 as being this

Code: Select all

					-- Too many tries, logout
					if( settings.profile.options.MAX_UNSTICK_TRIALS > 0 and
						player.Unstick_counter > settings.profile.options.MAX_UNSTICK_TRIALS ) then
						cprintf(cli.yellow, language[55],
						  player.Unstick_counter,
						  settings.profile.options.MAX_UNSTICK_TRIALS );	-- max unstick reached
My bot.lua doesn't even go up to line 2000, it ends at line 897.

Re: use nearest waypoint when stuck

Posted: Mon Jan 31, 2011 6:56 am
by Personalausweis
yaeh, problem with my bot is that he farms near a cave and sometime he fell down und then tries to go to to his waypoint on the upper level. would be perfect if he goes to the nearest waypoint (on the lower level) when he cant reach his last waypoint three or four times.

i'll give this code a try when i'm back from office. :)

thanks guys

Re: use nearest waypoint when stuck

Posted: Mon Jan 31, 2011 8:00 am
by rock5
lisa wrote:My bot.lua doesn't even go up to line 2000, it ends at line 897.
Ah, I went directly to the unstick function which is part of the player class. I didn't realize you were talking about bot.lua. It would probably work at both locations but I'd probably put it with the other "if( self.Unstick_counter == " conditions.

Re: use nearest waypoint when stuck

Posted: Mon Jan 31, 2011 9:19 am
by lisa
Ahh now I see where you are.

ok so in classes/player.lua line 2002 I added this.

Code: Select all

-- after 1x unsuccesfull unsticks try to reach nearest waypoint
	if( self.Unstick_counter == 2 ) then
	__WPL:setWaypointIndex(__WPL:getNearestWaypoint(player.X, player.Z, player.Y));
	end;
it is directly after

Code: Select all

function CPlayer:unstick()
If you don't see lines you can just do a search.

So if you fall off a cliff it should do one unstick and then go to nearest waypoint, aslong as nearest waypoint is the one at your current height. I like this idea as I do some farming near cliffes aswell.

I'm going to make a waypoint run along the bottom of the cliff edge and then run it back up. Add in a

Code: Select all

__WPL:setDirection(WPT_FORWARD);
At both the first waypoint down bottom and also at the first waypoint I want to actually use. Then at last waypoint add.

Code: Select all

__WPL:setDirection(WPT_BACKWARD);
So it will go back and forth between the waypoints I want and if falls off cliff it will just walk back up and continue.

Hope that helps you Personalausweis.

Re: use nearest waypoint when stuck

Posted: Mon Feb 07, 2011 9:04 pm
by kx9488
lisa wrote: I'm going to make a waypoint run along the bottom of the cliff edge and then run it back up. Add in a

Code: Select all

__WPL:setDirection(WPT_FORWARD);
At both the first waypoint down bottom and also at the first waypoint I want to actually use. Then at last waypoint add.

Code: Select all

__WPL:setDirection(WPT_BACKWARD);
So it will go back and forth between the waypoints I want and if falls off cliff it will just walk back up and continue.
this is going to sound stupid, but how would this look in a waypoint file? i understand you added in the first part to the player.lua file.. i've done that.
but how would this look in the waypoint file, i'm not sure where you're putting these.

this would help me a great deal. often times my farmer goes into unstick player trials for no reason and jumps off of hillsides and cliffs. i have a string of waypoints at the bottom as part of the farming path but my char humps the hillside instead of moving on and skipping the next 5-10 waypoints to the bottom of the hill near where he fell.

ty

Re: use nearest waypoint when stuck

Posted: Mon Feb 07, 2011 9:40 pm
by lisa
Ok I'll use 2 examples

Code: Select all

             7 6 5 4 3 2 1
             8
             9 10 11 12 13
            20           14
            19 18 17 16 15
In this example 9 - 20 are the farm waypoint that the bot will loop and basically ignore 1-8 the majority of the time. If you fall off the cliff at say 12 you will land near 3. So after the unsticks you then start from waypoint 3 and it will walk up to 9 and continue on as normal. This wouldn't require any more coding.
At most you might need a tag at waypoint 9 and have waypoint 20 tell the bot to go to that tag.


Code: Select all

	7 6 5 4 3 2 1
	8
	9 10 11 12 13
		          14
		          15
	  19 18 17 16
This example doesn't have a loop but what you can do is have some code to make it work. Farm area is 9 - 19 & 19 - 9, 1-8 is the walk back up.

Code: Select all

	<!-- #  1 --><waypoint x="XXXX" z="XXXX" y="XXX">	__WPL:setDirection(WPT_FORWARD); </waypoint>

Code: Select all

	<!-- #  9 --><waypoint x="XXXX" z="XXXX" y="XXX">	__WPL:setDirection(WPT_FORWARD); </waypoint>

Code: Select all

	<!-- #  19 --><waypoint x="XXXX" z="XXXX" y="XXX"> __WPL:setDirection(WPT_BACKWARD); </waypoint>
Hope this helps

Re: use nearest waypoint when stuck

Posted: Mon Feb 07, 2011 10:00 pm
by kx9488
lisa wrote: Hope this helps
thank you for explaining that for me. yes it did help.

so basically the additional code only pushes the char up the lower waypoints if it finds itself down there, in my case i actually wouldn't need them in a couple areas, because i farm them.

is rombot sapposed to skip to close waypoints already? before i added the code u made for the player.lua i have fallen close to part of my waypoint farm path like you have illustrated in your scenarios and i just try to climb the wall and unstick reaches 10, and my char never turns around to the waypoint behind him.
other times i have been at the bottom of the path and the mob or unstick made me run too close to the foot of the hillside/cliff and i have gotten stuck trying to run up because forwhatever reason it has skipped the wrong way.
it would be pretty much the same scenario as if i was farming at waypoint 9 in your second diagram, and the waypoint skipped to #20.

this doesn't happen enough to say it wont again with this code, but my hopes are high.

thank you

Re: use nearest waypoint when stuck

Posted: Mon Feb 07, 2011 11:01 pm
by lisa
I would run a set of waypoints along the bottom edge of the cliff, if your walk up coords arn't right where you fall down then it may not tell the bot to use them instead.


example

Code: Select all

<waypoint x="-3758" z="-8499" y="224">
<waypoint x="-3600" z="-8300" y="130">
If you fell off cliff and your current coords were

Code: Select all

x="-3740" z="-8470" y="130"
It might say you were closer to the waypoint up at y="224" and try to move to it.

Re: use nearest waypoint when stuck

Posted: Tue Feb 08, 2011 1:03 am
by rock5
lisa wrote:

Code: Select all

	<!-- #  1 --><waypoint x="XXXX" z="XXXX" y="XXX">	__WPL:setDirection(WPT_FORWARD); </waypoint>

Code: Select all

	<!-- #  9 --><waypoint x="XXXX" z="XXXX" y="XXX">	__WPL:setDirection(WPT_FORWARD); </waypoint>

Code: Select all

	<!-- #  19 --><waypoint x="XXXX" z="XXXX" y="XXX"> __WPL:setDirection(WPT_BACKWARD); </waypoint>
Instead of those __WPL:setDirection(WPT_FORWARD); at the bottom of the cliff you could just use

Code: Select all

   <onUnstickFailure><![CDATA[
      __WPL:setDirection(WPT_FORWARD);
      then whatever the command is to goto nearest waypoint
   ]]></onUnstickFailure>

Re: use nearest waypoint when stuck

Posted: Tue Feb 08, 2011 1:14 am
by lisa
True but the event only occurs when max unsticks is reached. We set up the code earlier for after 3 unsticks to go to nearest waypoint, trouble is that the "nearest" waypoint isn't always the one you want. You want the way point that can be walked to as in not up a cliff face. So even with going to nearest waypoint after 10 unsticks it would still try to walk up the cliff face.

I'm thinking need to put in a calculation for the y value, so it goes to nearest waypoint but only checks waypoints within a range of the current y position of character.
So for y within a range of +- 50 then nearest waypoint within that range.

What you think?

Re: use nearest waypoint when stuck

Posted: Tue Feb 08, 2011 2:18 am
by rock5
getNearestWaypoint does use the 'y' value. That was one of the main reasons I added them. As long as you mark enough points along the bottom of the cliff it should work. Of course if you are using an old waypoint file with only x and z values you would have to redo it.

A height check wouldn't be a bad idea though. evalTargetDefault uses one.

Code: Select all

	-- Check height difference
	if( math.abs(target.Y - player.Y) > 45 ) then
		return false;
	end
It might be an idea to just add it to getNearestWaypoint.

Re: use nearest waypoint when stuck

Posted: Thu Apr 07, 2011 10:31 am
by j19861986
rock5 wrote:getNearestWaypoint does use the 'y' value. That was one of the main reasons I added them. As long as you mark enough points along the bottom of the cliff it should work. Of course if you are using an old waypoint file with only x and z values you would have to redo it.

A height check wouldn't be a bad idea though. evalTargetDefault uses one.

Code: Select all

	-- Check height difference
	if( math.abs(target.Y - player.Y) > 45 ) then
		return false;
	end
It might be an idea to just add it to getNearestWaypoint.
I am really interested in that... but I got an error saying "Wrong value returned in update of item id 520003 and attempt to index global 'target' (a nil value)

look in screenshot

Re: use nearest waypoint when stuck

Posted: Thu Apr 07, 2011 7:12 pm
by rock5
Maybe you didn't do it right. It should look like this, I think.

Code: Select all

-- Returns an index to the waypoint closest to the given point.
function CWaypointList:getNearestWaypoint(_x, _z, _y)
	local closest = 1;

	for i,v in pairs(self.Waypoints) do
		local oldClosestWp = self.Waypoints[closest];

		if( distance(_x, _z, _y, v.X, v.Z, v.Y) < distance(_x, _z, _y, oldClosestWp.X, oldClosestWp.Z, oldClosestWp.Y) ) and
			 ( math.abs(_y - v.Y) < 45 ) then
			closest = i;
		end
	end

	return closest;
end

Re: use nearest waypoint when stuck

Posted: Sat Apr 09, 2011 9:02 pm
by rock5
I been thinking about this and it's not a good solution. For starters, if a waypoint is below you, you should still be able to go to it. And what if you have a waypoint at the top of a ramp? It could be more that 45 above you but it should still be valid. I think what we need is an angle check instead. Something like, if the waypoint is more than about 45 degrees above you skip it. What do you think?