March 24, 20179 yr Hi! Im trying to add a function in the plugin: Basically i want to add a function or replace one so it hops when there isnt a living mob close by, eg. The warbringers in pandaria. If i kill mob, i want to check next realm, if it isnt there i want to jump to next and so on. For now my function looks like this: private List<WoWUnit> GetNPCNearMe() { return ObjectManager.GetObjectWoWUnit() .Where(p => p.GetDistance <= RealmHopSettings.CurrentSetting.DistanceBeforeHopping).ToList(); } However, i think if its there but dead, it still thinks there is a mob. So what can i do? Regards
March 26, 20179 yr Hello, i would replace it by this: public bool NpcExist(string name) { foreach (var unit in ObjectManager.GetObjectWoWUnit()) { if (unit.Name == name && !unit.IsDead && unit.GetDistance <= RealmHopSettings.CurrentSetting.DistanceBeforeHopping) Logging.Write("Unit found."); return true; } return false; } Usage: if (NpcExist("Warbringer")) { //your code } or if you want the ordered npc list by distance: public List<Npc> GetNearestNpcs(string name) { return ObjectManager.GetObjectWoWUnit().Where(i => i != null && !i.IsDead && i.GetDistance <= RealmHopSettings.CurrentSetting.DistanceBeforeHopping ).OrderBy(i => ObjectManager.Me.Position.DistanceTo(i.Position)).ToList(); } Usage to get closest WoWUnit: GetNearestNpcs("Warbringer").FirstOrDefault(); I couldn't test it but it should work :)
April 9, 20179 yr Author Wow! That worked perfectly! Can i do something similarly when it comes to mining/herbs? Thank you!
April 10, 20179 yr Yep. It's almost the same ;) public List<WoWGameObject> WoWGameObjects(string name) { return ObjectManager.GetObjectWoWGameObject().Where(i => i != null && i.Name == name //&& i.GetDistance <= RealmHopSettings.CurrentSetting.DistanceBeforeHopping //or other arguments ).OrderBy(i => ObjectManager.Me.Position.DistanceTo(i.Position)).ToList(); } usage: WoWGameObjects("Kingsblood").FirstOrDefault();
April 11, 20179 yr Author Thanks, however my game plus wrobot crashes with this. I tried using the first method instead (warbringer) then it doesnt crash but its doesnt work either.
April 11, 20179 yr @Pelle now i could test it more, that should work: public List<WoWGameObject> WoWGameObjects(string name) { return ObjectManager.GetObjectWoWGameObject().Where(i => i != null && i.Name == name //&& i.GetDistance <= RealmHopSettings.CurrentSetting.DistanceBeforeHopping ).OrderBy(i => ObjectManager.Me.Position.DistanceTo(i.Position)).ToList(); } public List<WoWUnit> GetNearestUnits(string name) { return ObjectManager.GetObjectWoWUnit().Where(i => i != null && !i.IsDead && i.Name == name && i.GetDistance <= RealmHopSettings.CurrentSetting.DistanceBeforeHopping ).OrderBy(i => ObjectManager.Me.Position.DistanceTo(i.Position)).ToList(); }
April 13, 20179 yr Author 11 hours ago, camelot10 said: its bad practice to search npc by name. use id and entry How would you do it then? :)
April 13, 20179 yr public List<WoWGameObject> WoWGameObjects(int mobID) { return ObjectManager.GetObjectWoWGameObject().Where(i => i != null && i.Entry == mobID //&& i.GetDistance <= RealmHopSettings.CurrentSetting.DistanceBeforeHopping ).OrderBy(i => ObjectManager.Me.Position.DistanceTo(i.Position)).ToList(); } public List<WoWUnit> GetNearestUnits(int mobID) { return ObjectManager.GetObjectWoWUnit().Where(i => i != null && !i.IsDead && i.Entry == mobID && i.GetDistance <= RealmHopSettings.CurrentSetting.DistanceBeforeHopping ).OrderBy(i => ObjectManager.Me.Position.DistanceTo(i.Position)).ToList(); } May for your understanding: .Where({condition for every single object}) In this sample "i" represents a single object from the list, thats why you have access to its properties like Name or the Entry(ID) The result will be a list of all items that are equals your condition.
Create an account or sign in to comment