Jump to content

Error while trying to get distance from Object (Ship)


ScripterQQ

Recommended Posts

Hello, I used the following code to make the player use the tram on my profile: (thanks to Stauffenberg)

if (ObjectManager.GetWoWGameObjectByyId(176082).FirstOrDefault().GetDistance <= 25) {
  Logging.Write("[Quester] Tram already here - waiting for the next one to make sure boarding will not fail");
}
while (ObjectManager.GetWoWGameObjectByyId(176082).FirstOrDefault().GetDistance <= 25) {Thread.Sleep(500);};

Logging.Write("[Quester] Waiting for the Tram");
while (ObjectManager.GetWoWGameObjectByyId(176082).FirstOrDefault().GetDistance > 25) {Thread.Sleep(500);};

I tried to replace the ID of the tram with the ID of the ship on Booty Bay (tried both ships, Maiden and Bravery)  and I can't get it work. I tested randomly this code by swapping the ID and putting the ID of a mailbox and the code was working, obviously (I put a debug print like "im near the mailbox", "im far away from the mailbox").

This is basically the error I get when I try to put the ID of the Ship

[E] 18:54:56 - QuesterState > TestCondition(string csharpCode): System.NullReferenceException: A reference to an object not set on an object instance.
   in Main.Pulse2()
   in Quester.Bot.OjuwidaiVejuowe.EriaqeivalJaubalaw(String akainuf, Boolean ekeqeureiNiatiok)

I thought about the ship entering/exiting from the zone, so basically when checking range conditions the bot doesn't find the object and crashes somehow, but applied to Darnassus Ships it works so I have no idea honestly (also I don't understand the error..is it francais?). I tried even in a custom server where there are custom npcs and objects, and with development tools I took the ID of a custom object and still the same issue, it was not recognizing it. Any idea how to fix this? I would like to add this feature on my quester profile to move from Booty Bay to Ratchet.

Link to comment
Share on other sites

Sorry I just noticed I've posted into Official Forums, I'm testing this on private servers, so idk if this should be moved or what, maybe the problem it's indeed the private server object ID recognition.. Thanks.

Link to comment
Share on other sites

10 minutes ago, ScripterQQ said:

Sorry I just noticed I've posted into Official Forums, I'm testing this on private servers, so idk if this should be moved or what, maybe the problem it's indeed the private server object ID recognition.. Thanks.

I think it might be crashing  because FirstOrDefault is not returning an instance of an object. So, you'll need to check if the object returned is null or not before checking its distance property.

For example:

var tram = ObjectManager.GetWoWGameObjectByyId(176082).FirstOrDefault();

if(tram!=null){
 var distance = tram.GetDistance();
	if(distance<=25){
		 Logging.Write("Tram is within 25 units");
	}
	else{
		 Logging.Write("Tram is farther than 25 units");
	}
}
else{
	 Logging.Write("Tram is null");
}

 

Also, to be safe, you can wrap the entire thing in a try catch block. This will prevent WRobot from crashing.

try{
  var tram = ObjectManager.GetWoWGameObjectByyId(176082).FirstOrDefault();

  if(tram!=null){
   var distance = tram.GetDistance();
      if(distance<=25){
           Logging.Write("Tram is within 25 units");
      }
      else{
           Logging.Write("Tram is farther than 25 units");
      }
  }
  else{
       Logging.Write("Tram is null");
  }
}
catch(Exception e){
	Logging.Write("Uh oh... something happened:"+ e.ToString());
}

 

 

 

Edited by Avvi
Link to comment
Share on other sites

I just had to change (after the tram != null check)

var distance = tram.GetDistance();

to

var distance = ObjectManager.GetWoWGameObjectByyId(20808).FirstOrDefault().GetDistance;

because it was giving me error (basically not running at all). Now it reads the ship position correctly, I just need to adjust the range and other settings and it should be good =)

Link to comment
Share on other sites

1 hour ago, ScripterQQ said:

I just had to change (after the tram != null check)


var distance = tram.GetDistance();

to


var distance = ObjectManager.GetWoWGameObjectByyId(20808).FirstOrDefault().GetDistance;

because it was giving me error (basically not running at all). Now it reads the ship position correctly, I just need to adjust the range and other settings and it should be good =)

Great, cool to see the null check worked!

Link to comment
Share on other sites

I took another peak at his code, in fact on the first ship he didn't add a control basically because the ship is always in the zone, but the second ship actually appears/disappears from the zone and goes through "portals", so yea he added a check

ObjectManager.GetWoWGameObjectByyId(ID).Count == 0

I guess both options are valid, I just didn't think about the item ID going out of the zone. Now I stick with the null check and I'm fine, the result is the same :)
Still I prefer his code rather than the classic "Catch Zeppelin/Ship", but that's a matter of preferences

Link to comment
Share on other sites

Small update: I got the same error while using Stauffenberg 's profile "darnassus to northshire", on a private server (not w.rmane). I was waiting at Teldrassil for the Ship to Auberdine, and exactly like my profile, I got the same error and behaviour (after the error the char was jumping into the water thinking the ship was there). I tested his profile on w.rmane and it was perfect, so I guess it's something wrong on the server rather than on the code, I don't know. I even tried to make a separate Quester profile with just a RunCode with

while (ObjectManager.GetWoWGameObjectByyId(ID).Count == 0)
{Thread.Sleep(1000);}

and the step after, a debug print on the screen, which never triggered, meaning it was still on the while loop because the ID was not found, but the Ship appeared on the game so the while statement should have stopped.

My guess is the robot on some servers can't recognize ships IDs when they appear/disappear... or it bugs somehow.

I will make further tests and try to localize the problem..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...