Pelle 4 Posted March 24, 2017 Share Posted March 24, 2017 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 Link to comment Share on other sites More sharing options...
reapler 154 Posted March 26, 2017 Share Posted March 26, 2017 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 :) Link to comment Share on other sites More sharing options...
Pelle 4 Posted April 9, 2017 Author Share Posted April 9, 2017 Wow! That worked perfectly! Can i do something similarly when it comes to mining/herbs? Thank you! Link to comment Share on other sites More sharing options...
reapler 154 Posted April 10, 2017 Share Posted April 10, 2017 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(); Link to comment Share on other sites More sharing options...
Pelle 4 Posted April 11, 2017 Author Share Posted April 11, 2017 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. Link to comment Share on other sites More sharing options...
reapler 154 Posted April 11, 2017 Share Posted April 11, 2017 @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(); } Link to comment Share on other sites More sharing options...
camelot10 155 Posted April 12, 2017 Share Posted April 12, 2017 its bad practice to search npc by name. use id and entry Link to comment Share on other sites More sharing options...
Pelle 4 Posted April 13, 2017 Author Share Posted April 13, 2017 11 hours ago, camelot10 said: its bad practice to search npc by name. use id and entry How would you do it then? :) Link to comment Share on other sites More sharing options...
iMod 99 Posted April 13, 2017 Share Posted April 13, 2017 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now