Page 1 of 1

Target position

Posted: Mon Jul 05, 2010 4:59 pm
by WhiteTiger
Hi, I got two questions..
First, is there a way to get the location of your target? like a function that returns x,y and z values.. or even better to get the location of the nearest unit of a specific id number.
And 2nd, is there a function that makes your character move to a location without depending of the waypoints? Ty :P

Re: Target position

Posted: Mon Jul 05, 2010 8:15 pm
by Administrator

Code: Select all

local target = player:getTarget();
local x,y,z = target.X, target.Y, target.Z;

Code: Select all

player:moveTo(1000.0, 2000.0);

Re: Target position

Posted: Tue Jul 06, 2010 12:11 pm
by WhiteTiger
[quote="Administrator"]

Code: Select all

local target = player:getTarget();
local x,y,z = target.X, target.Y, target.Z;
tried that with this code:

Code: Select all

<?xml version="1.0" encoding="utf-8"?><waypoints>
	<!-- #  1 --><waypoint x="6773" z="21596">
	local target = player:getTarget();
	local x,y,z = target.X, target.Y, target.Z;
	addMessage(x);
	yrest(1000);
	</waypoint>
</waypoints>
but it only printed 0 :(

Re: Target position

Posted: Tue Jul 06, 2010 1:14 pm
by rock5
WhiteTiger wrote:but it only printed 0 :(
Did you have something targeted?

That code is in between waypoint tags which means it would move to that point first then execute the code. It may not have something targeted when executing that code.

Try putting that code between onLoad tags instead so it gets executed immediately. Then target something first before loading the waypoint file. eg.

Code: Select all

<?xml version="1.0" encoding="utf-8"?><waypoints>
<onLoad>
   local target = player:getTarget();
   local x,y,z = target.X, target.Y, target.Z;
   addMessage(x);
   yrest(1000);
   player:sleep()
</onLoad>
   <!-- #  1 --><waypoint x="6773" z="21596">   </waypoint>
</waypoints>

Re: Target position

Posted: Tue Jul 06, 2010 2:32 pm
by WhiteTiger
it worked when I put it in <OnLoad>. But it still doesnt work when I have it in a waypoint:S. I think I know what the problem is tho: When it got to the waypoint before it executed any code it printed "Clearing target" in the micromacro program. Any idea how I can remove that?

Re: Target position

Posted: Tue Jul 06, 2010 8:13 pm
by WhiteTiger
player:moveTo(1000.0, 2000.0);
I also noticed now when I tried the moveTo that it doesnt work and I get this error:
...rom/classes/player.lua/player.lua:1150: attemp to index local 'waypoint' (a number value)

I tried it with this code:

Code: Select all

<?xml version="1.0" encoding="utf-8"?><waypoints>
<onLoad>
player:moveTo(1000.0, 2000.0);
yrest(5000)
player:sleep()
</onLoad>
   <!-- #  1 --><waypoint x="6773" z="21596">   </waypoint>
</waypoints>
any ideas? :(

Re: Target position

Posted: Tue Jul 06, 2010 11:19 pm
by rock5
WhiteTiger wrote:it worked when I put it in <OnLoad>. But it still doesnt work when I have it in a waypoint:S. I think I know what the problem is tho: When it got to the waypoint before it executed any code it printed "Clearing target" in the micromacro program. Any idea how I can remove that?
At this point I think we need to ask, why do you want to know the coordinates of your target and what do you intend to do with them?

Re: Target position

Posted: Tue Jul 06, 2010 11:36 pm
by rock5
WhiteTiger wrote:
player:moveTo(1000.0, 2000.0);
Looks like this is wrong. moveTo expects a waypoint so you need to create a waypoint object. This seems to work;

Code: Select all

to = CWaypoint(1000.0, 2000.0)
player:moveTo(to);
Edit: Just discovered you can do this too;

Code: Select all

player:moveTo(CWaypoint(1000.0, 2000.0));

Re: Target position

Posted: Wed Jul 07, 2010 1:41 pm
by WhiteTiger
Stuffs work now :) thx for all help!