Jump to content

[WOTLK] How to get the tank


iMod
 Share

Recommended Posts

 protected WoWPlayer GetPartyTank()
        {
            WoWPlayer tank;

            var lua = new[]
                          {
                            "partyTank = \"\";",
                            "for groupindex = 1,MAX_PARTY_MEMBERS do",
                            "	if (UnitInParty(\"party\" .. groupindex)) then",
                            "		local role = UnitGroupRolesAssigned(\"party\" .. groupindex);",
                            "		if role == \"TANK\" then",
                            "			local name, realm = UnitName(\"party\" .. groupindex);",
                            "			partyTank = name;",
                            "			return;",
                            "		end",
                            "	end",
                            "end",
                        };

            // Get tank name
            string tankName = Lua.LuaDoString(lua, "partyTank");

            if (string.IsNullOrEmpty(tankName))
            {
                // Set us as tank
                tank = this.Me;
            }
            else
            {
                // Set tank
                tank = this.GetPartyMember().Single(p => p.Name == tankName);
            }

            return tank;
        }

i'm looking for a way to get the tank object of a party or raid. it seems i'm something missing couz i get an empty string back.

Link to comment
Share on other sites

On WOTLK "UnitGroupRolesAssigned" change, try this (not tested):

    public WoWPlayer GetPartyTank()
    {
        WoWPlayer tank = new WoWPlayer(0);

        var lua = @"
                    for groupindex = 1,MAX_PARTY_MEMBERS do
	                    if (UnitInParty('party' .. groupindex)) then
		                    local isTank, isHealer, isDamage = UnitGroupRolesAssigned('party' .. groupindex);
		                    if isTank then
			                    local name = UnitName('party' .. groupindex);
			                    return name;
		                    end
	                    end
                    end
                    return '';
                    ";

        // Get tank name
        string tankName = Lua.LuaDoString<string>(lua);

        if (!string.IsNullOrEmpty(tankName))
        {
            tankName = tankName.Trim().ToLower();

            //foreach (var p in Party.GetPartyHomeAndInstance())
            foreach (var p in ObjectManager.GetObjectWoWPlayer())
            {
                if (p != null && p.IsValid && p.Name.Trim().ToLower() == tankName)
                {
                    tank = new WoWPlayer(p.GetBaseAddress);
                    break;
                }
            }
        }

        return tank;
    }

 

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
 Share

×
×
  • Create New...