Jump to content

Help with continuation of plugin


Pelle

Recommended Posts

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

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

  • 2 weeks later...

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

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

@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

        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

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...