Jump to content
This site uses cookies! Learn More

This site uses cookies!

By continuing to use this site, you agree to allow us to store cookies on your computer. :)

KateLibby

[Solved]Issues with list of WoWObjectType.Player but WoWObjectType.Unit works fine

Recommended Posts

Hello,

I have been struggling to create a list of all nearby players for the last few days and figured its time to ask for some help.

I just don't see what I am doing wrong, it works other type "unit", the debug tools outputs all players of type "Player" but I am trying to make a plugin and my list is always just completely null/empty no matter what I try for "Player", however I am having no problems with other types like "Unit".

I wrote a sample plugin to demonstrate the issue (Attached to post) here is the parts that matter.

// Broken
var playersList = new List<WoWUnit>();	// Init list type
var ptemp = ObjectManager.GetObjectWoWUnit().Where(u => u.Type == WoWObjectType.Player).ToList();	// Get all nearby players
playersList.AddRange(ptemp);	// Add all players to the list
string pstr = "PlayerList: " + playersList;	// Get object type
string pcount = "PlayerList-Count: " + playersList.Count;	// Get number of entries in list 
Logging.Write(pstr);	// Print object type
Logging.Write(pcount);	// Print number of entries in list 
foreach (var i in playersList)	// For each entry in the list
{
	string str = " plist output: " + i.Name;	// Create string
	Logging.Write("[PlayerDetector]" + str);	// Print the name of the unit
}

// Working
var unitsList = new List<WoWUnit>();
var utemp = ObjectManager.GetObjectWoWUnit().Where(u => u.Type == WoWObjectType.Unit && u.PlayerControlled).ToList();
unitsList.AddRange(utemp);
string ustr = "UnitsList: " + unitsList;
string ucount = "UnitsList-Count: " + unitsList.Count;
Logging.Write(ustr);
Logging.Write(ucount);
foreach (var i in unitsList)
{
	string str = " ulist output: " + i.Name;
	Logging.Write("[PlayerDetector]" + str);
}

As you can see in the output, its finding player pets just fine but for some reason the same thing for players just does not work at all.

image.png.37eb5d923622556435da69581d29b17f.png

(I am running this in ORG with players right in front of me)

 

My WRobot debug tools get all objects:

image.png.f923f5bfa70a163b4c99a1df0f102aed.png

 

 

TestDetection1.cs

Edit: Fixed

Well I knew it had to be something simple I was overlooking. Apparently the code I found "GetObjectWoWUnit Where WoWObjectType.Player" was supposed to actually be "GetObjectWoWPlayer Where WoWObjectType.Player", glad I decided to randomly try that. Feel free to consider this a free sample plugin.

Happy Me ♥

WorkingSample.cs

Share this post


Link to post
Share on other sites

Try using this, from @Droidz

public static List<WoWPlayer> GetFriendlyPlayersAndMe()
    {
        List<WoWPlayer> listPlayersResult = new List<WoWPlayer>();

        List<WoWPlayer> allPlayers = ObjectManager.GetObjectWoWPlayer();
        foreach (var player in allPlayers)
        {
            if (player.IsValid && player.IsAlive && player.PlayerFaction == ObjectManager.Me.PlayerFaction && player.Position.DistanceTo(ObjectManager.Me.Position) < 100)
                listPlayersResult.Add(player);
        }

        listPlayersResult.Add(ObjectManager.Me);

        return listPlayersResult;
    }

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...