Page 1 of 1

Target NPC

Posted: Fri Nov 22, 2013 4:41 pm
by Danni
Hi Everyone,

I got a little question seems I think I saw it in the game, but could not figure it out how the person does it.

here an script example:

<!-- # 1 --><waypoint x="xxxxx" z="zzzzz" y="yyyyy" tag="Start">
player:target_NPC()
repeat
doing a quest
until condition A is met
switching Channel
if condition B is met than
__WPL:setWaypointIndex(__WPL:findWaypointTag("Go Home"));
else
__WPL:setWaypointIndex(__WPL:findWaypointTag("Start"));
<!-- # 2 --><waypoint x="xxxxx" z="zzzzz" y="yyyyy" tag="Go Home">

In the whole Process the Char should NOT move around, just standing at a specific point starting for example at Ch1. It will target the NPC and after it's done with doing some quest, it will switch to Ch2. When the Char is at Ch2, it start starts targeting the NPC and again does a quest. And the same on Ch3.

I tried that script, BUT the problem is, after the the Channel switching, it seems like the Char is trying again to get to WP 1 and after that it does the part below. It seems like it didn't get the right point, walk back or forward a few steps , and than target the NPC. :?
This really does look like a botter :o

So my Question is, is there a possible way to make sure, the Char will not move around until in example "Condition B is fullfilled"? :?:

Thanks for your help.

Re: Target NPC

Posted: Fri Nov 22, 2013 7:01 pm
by ZZZZZ
I'll give it a shot, you could add it to a function (i have done it to the accept/complete quests in all my daily quest files).

Code: Select all

<onLoad>
function quest()
player:target_NPC()
repeat
doing a quest
until condition A is met
switching Channel
if condition B is met than 
__WPL:setWaypointIndex(__WPL:findWaypointTag("Go Home"));
else
quest()
end
</onLoad>
<!-- # 1 --><waypoint x="xxxxx" z="zzzzz" y="yyyyy" tag="Start">
quest()
<!-- # 2 --><waypoint x="xxxxx" z="zzzzz" y="yyyyy" tag="Go Home">
Should work (idk if its the easiest way, would have to wait for someone that knows more about what they are talking about comments xD

Re: Target NPC

Posted: Fri Nov 22, 2013 7:05 pm
by Bill D Cat
It almost sounds like you are not using a waitForLoadScreen() in between the channel change. That can possibly cause the bot to try and move your character before the game is ready, and those movement commands might get buffered and executed when you finally arrive on the new channel. Whenever I do a channel change or transport to a different location when I know there will be a load screen involved, I always make sure to add a waitForLoadScreen() and sometimes an additional yrest(5000) just to be sure that everything is ready before the bot starts issuing commands to the game again.

Re: Target NPC

Posted: Fri Nov 22, 2013 9:33 pm
by Danni
thx u ZZZZZ and thx u Bill D Cat for your both replys.

@ZZZZZ
you could add it to a function
I did already done that :) I just posted it more simple in my first post so I won't need to post all the functions ;)
but my WP look like that:

Code: Select all


function Zone()
	local zone, channel = getZoneId()
   	if channel == 1 then
		quest()
		channel()
		yrest(5000);
		__WPL:setWaypointIndex(__WPL:findWaypointTag("Start"));
   	elseif channel == 2 then
		quest()
		channel()
		yrest(5000);
		__WPL:setWaypointIndex(__WPL:findWaypointTag("Start"));
   	elseif channel == 3 then
	        quest()
		channel()
		yrest(5000);
		__WPL:setWaypointIndex(__WPL:findWaypointTag("Start"));
   	end
end

function quest()
    	repeat
              	player:target_NPC();
		do the quest
	until Condition A is met
end

function channel()
         sendMacro("ChangeParallelID(".newChannel.");");
         player:rest(33)
         	local id = RoMScript("GetCurrentParallelID()")
         		if id ~= newChannel then
         			RoMScript("ChangeChar(\"current\",nil,".newChannel.")")
         			waitForLoadingScreen()
         			yrest(5000)
         		end
end

<!-- # 1 --><waypoint x="xxxxx" z="zzzzz" y="yyyyy" tag="Start">
          Zone() 
<!-- # 2 --><waypoint x="xxxxx" z="zzzzz" y="yyyyy" tag="Go Home">
@Bill D Cat
I already had waitForLoadScreen() in my WP. But I tried your suggestion above by altering a higher rest. I had put one rest in Zone(), and two more in channel() ....although I change it from previous yrest(3500) to now yrest(5000) & the player:rest(30) to player:rest(33) while a channel switch cost 25 sec. ... the Problem still arise, that the Char is moving. Since I made already a pause from 8 - 10 sec, after the channel switching. :?:

The Char does somehow not realize that the NPC is right next to him. :|

Re: Target NPC

Posted: Fri Nov 22, 2013 9:53 pm
by Bill D Cat
I'm not sure if this will help identify the problem or not, but you could try opening up a second MM window and running rom/getpos in it. Then when you are running the script in the other window, you will be able to see if the channel change is causing the character to move a little.

The other option is to refine the X and Z locations at which your character is standing when trying to target the NPC. Or perhaps a player:clearTarget() before you switch channels and then the player:target_NPC() after might relocate the proper NPC better?

Re: Target NPC

Posted: Fri Nov 22, 2013 10:28 pm
by ZZZZZ
tried

Code: Select all

function Zone()
   local zone, channel = getZoneId()
      if channel == 1 then
      quest()
      channel()
      yrest(5000);
      Zone()
      elseif channel == 2 then
      quest()
      channel()
      yrest(5000);
      Zone()
      elseif channel == 3 then
           quest()
      channel()
      yrest(5000);
      Zone()
      end
end
You're using

Code: Select all

__WPL:setWaypointIndex(__WPL:findWaypointTag("Start"));
at the moment which means it'll try to move to that waypoint each time its called and fro what i have seen, even if you're already standing there it'll still move a short distance. Replace them with Zone() to just load the function strait up rather than moving to the 'same spot' each time. That should fix the player movement issues, wouldn't have a clue about the targeting npc though.

Re: Target NPC

Posted: Fri Nov 22, 2013 11:19 pm
by Danni
Thx Bill D Cat for your reply :) Learned something new :) I will use the rom/getpos for the future :geek:

Thx u ZZZZZ, that solved the problem :mrgreen:

Re: Target NPC

Posted: Sat Nov 23, 2013 9:29 pm
by Danni
Sry guys,

got one more question about the target function

I want to use this code as well:
if player:findNearestNameOrId("NPC-ID") and distance(player, NPC-ID) >= 50 then
do something
else
dosomething
end
The purpose is, that MM should look for a specific NPC and check if its distance to the Char is the same or less than 50.
Depending what MM founds it will do something.

BUT MM give me that message:
10:21am - ...OM/scripts/rom/waypoints/Chrysalia-EoJ_onload - Copy.lua:54: Error: nil value passed to distance()
My guess is that I am using distance() code in a wrong way, so how do I use it? Or what I need to change to make it work? :?:

Thank u for advice. ;)

Re: Target NPC

Posted: Sat Nov 23, 2013 10:11 pm
by ZZZZZ

Code: Select all

local npc1 = player:findNearestNameOrId(NPC-ID)
			
		if npc1 and 50 > distance(npc1.X, npc1.Z, player.X, player.Z) then
player:target(npc1.Address)
---- do something
else
---- do something
end
I think that is what you are after.

Re: Target NPC

Posted: Sat Nov 23, 2013 11:00 pm
by Danni
Yes indeed ZZZZZ

Thank you ;)

Re: Target NPC

Posted: Sat Nov 23, 2013 11:27 pm
by rock5
You can also use the object themselves in the distancefunction instead of the x,z,y values, eg.

Code: Select all

distance(npc1, player)

Re: Target NPC

Posted: Sun Nov 24, 2013 10:18 pm
by Danni
Hey rock5 , thx for reply

I tried yours, looking like this:

Code: Select all

local npc1 = player:findNearestNameOrId(120237)
if npc1 and 50 > distance(120237, player) then
RoMScript("Logout();");
But MM now give me again that message
11:12am - ...macro ROM/scripts/rom/waypoints/myscript_onload.lua:48: Error: nil value passed to distance()
Firstly, :arrow: something seems :?: off

Secondly, :arrow: even with the code from ZZZZZ, my Char does not log off if its distance is over 50. DId I use the code
RoMScript("Logout();");
correctly? :?:

Re: Target NPC

Posted: Sun Nov 24, 2013 10:27 pm
by Bill D Cat
Danni wrote:Hey rock5 , thx for reply

I tried yours, looking like this:

Code: Select all

local npc1 = player:findNearestNameOrId(120237)
if npc1 and 50 > distance(120237, player) then
RoMScript("Logout();");
I think it should be this instead: (use the pawn target rather than the Mob Id)

Code: Select all

local npc1 = player:findNearestNameOrId(120237)
if npc1 and distance(npc1, player) > 50 then
RoMScript("Logout()")
The way you had it, you'd only logout if you were less than 50 (melee) range from the target (Kemo Silvering in this case). This will log out out if you are MORE than 50 from the target.

Re: Target NPC

Posted: Sun Nov 24, 2013 10:41 pm
by Danni
Thx Bill D Cat for the fast answer :)

It is working like a charm now ;)