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());
}