Thread Tools Display Modes
03-23-12, 11:35 AM   #1
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
Pet's owner

does anyone know a way to get the pet's owner/summoner without doing a for loop through the entire raid (or party) running UnitIsUnit(PetName, ("raidpet%i"):format(x)) I looked around and found nothing...
  Reply With Quote
03-23-12, 12:23 PM   #2
Waky
A Cobalt Mageweaver
 
Waky's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 200
I don't know of any functions listed in the WoW API that tell you who is the owner of a pet, but I do know a way that could work.

You'd need to create an extra tooltip just for scanning the text:

Code:
local scanTool = CreateFrame( "GameTooltip", "ScanTooltip", nil, "GameTooltipTemplate" )
scanTool:SetOwner( WorldFrame, "ANCHOR_NONE" )
local scanText = _G["ScanTooltipTextLeft2"] -- This is the line with <[Player]'s Pet>
Then whenever you find a pet you want to find the owner of you could run this function:

Code:
function getPetOwner(petName)
   scanTool:ClearLines()
   scanTool:SetUnit(petName)
   local ownerText = scanText:GetText()
   if not ownerText then return nil end
   local owner, _ = string.split("'",ownerText)
   
   return owner -- This is the pet's owner
end
As long as the pet is in range, or a member in your party/raid the SetUnit() function should work and you should be able to retrieve it's owner's name via the tooltip.

This is how my addon, DispelWatch, works to retrieve buff types on your target!

Hope this helps!

Last edited by Waky : 03-23-12 at 01:45 PM.
  Reply With Quote
03-23-12, 12:39 PM   #3
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
Thanks... it sure beats what I was doing and should be faster too lol

lua Code:
  1. if Pet then
  2.         local p = GetNumPartyMembers()
  3.         local r = GetNumRaidMembers()
  4.         local PetOwner = ""
  5.         if r > 0 then
  6.             for x = 1, r do
  7.                 if UnitIsUnit(("raidpet%i"):format(x), sourceName ) then
  8.                     PetOwner = ("raidpet%i"):format(x)
  9.                     break
  10.                 end
  11.             end
  12.         elseif p > 0 then
  13.             for x = 1, p do
  14.                 if UnitIsUnit(("partypet%i"):format(x), sourceName ) then
  15.                     PetOwner = ("partypet%i"):format(x)
  16.                     break
  17.                 end
  18.             end
  19.         elseif UnitIsUnit("pet", sourceName) then
  20.             PetOwner = "player"
  21.         end
  22.         local _, PetOwnerClass = UnitClass( PetOwner )
  23.         name = ("%s%s "):format( CCC(PetOwnerClass), UnitName(PetOwner) ) .. name
  24.     end
  Reply With Quote
03-23-12, 01:47 PM   #4
Waky
A Cobalt Mageweaver
 
Waky's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 200
Glad I could help, plus a slight change in the getPetOwner() function to make it more stable and accurate:

Code:
function getPetOwner(petName)
   scanTool:ClearLines()
   scanTool:SetUnit(petName)
   local ownerText = scanText:GetText()
   if not ownerText then return nil end
   local owner, _ = string.split("'",ownerText)
   
   return owner -- This is the pet's owner
end
If you don't have the "ClearLines()" then if when you call "SetUnit([name])" and there is no Unit with that name it would reference the old unit called. The second change just makes it so it returns nil if there is no unit with that arg name passed.

Edit: I think I broke it, I've no idea what's wrong. Working on it...

Edit2: Not broken, actually just remembered this will only work for pets in your party/raid. (Which was your original intention, right?)

The way the getPetOwner() function is set up now, it will either return the pet's owner if they're in your party/raid or if it is your pet, otherwise it will return nil

Last edited by Waky : 03-23-12 at 02:01 PM.
  Reply With Quote
03-23-12, 02:18 PM   #5
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
Yes, that was my intention... I am in the process of writing an addon that will combine the abilities of several addons like Alice's taunt watch and the taunt watch pets version and make it change how it alerts you depending on your party role and other settings( like yelling at the hunter with the taunting pet )
  Reply With Quote
03-24-12, 06:22 AM   #6
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
so that works sweet, Thank you... The basic addon is now written, alerting the user of all taunts... now for all the bells and whistles... but they may have to wait as I have to move... I HATE moving... put everything in boxes, drive them a few miles, take out of boxes, repeat... it sucks

I also thought of something... that function will work for non party/ raid pets as long as you pass it as a valid unit like target / focus... and originally I was doing a check with
(UnitPlayerOrPetInParty(sourceName) or UnitPlayerOrPetInRaid(sourceName) or UnitIsUnit(sourceName, "player") or UnitIsUnit(sourceName, "pet") )

I then realized when looking for a valid unit to reference the pets owner that all that could be replaced with a simple:
UnitExists(sourceName) as a name is only valid as a unit if it is you, your pet, or in your party, or raid lol

Last edited by Billtopia : 03-24-12 at 06:40 AM. Reason: added some thoughts...
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Pet's owner


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off