Thread Tools Display Modes
03-09-13, 02:13 PM   #1
jlrm365
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 113
Question Summon: 1 particular companion

There are many addons to summon random pets (companions, if you prefer, known as pets in this post / thread).

NugMiniPet seemed to be working until recently but, for some reason, has just started to cause me interface issues.

I've yet to find a currently working addon that can summon just one chosen pet.

What I imagine is opening the lua and typing in a pet's name.
I then imagine a set of commands, using logic something like this:

- If player has a pet summoned, do not summon.
- If player does not have a pet summoned, then:
-- If player is not moving, don't summon.
-- If player is moving, summon [NAME]

I can see it being less than half a dozen lines, with no GUI. It only summons one pet and opening the LUA is the only way to change which pet is summoned.

I'm sure any solution would be more elegant than my logic, but that was just to illustrate my thinking.
Is such a thing, as an addon with the above logic steps, possible?

Thanks!

  Reply With Quote
03-09-13, 05:33 PM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
You only want it to summon a pet if the player is moving?
  Reply With Quote
03-09-13, 06:53 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
1. The default UI already has a "/summonpet White Kitten" command to summon a specific companion pet.

2. However, if you really want to use an addon that prevents you from summoning the pet if you already have another one summoned or if you're not moving (why???) here you go. Use the "/favpet" command to summon the pet. You can optionally specify a different pet name, eg. "/favpet Leaping Hatchling".

Code:
-- Change this to the exact name of the pet you want to summon:
local DEFAULT_PET = "White Kitten"

-- Nothing below here needs to be changed.
SLASH_CALLFAVORITEPET1 = "/favpet"
SlashCmdList.CALLFAVORITEPET = function(petName)
	if InCombatLockdown() then
		-- You can't summon a pet in combat from insecure code.
		return
	end

	if GetUnitSpeed("player") == 0 then
		-- You aren't moving.
		return
	end

	if C_PetJournal.GetSummonedPetGUID() then
		-- You already have a summoned pet.
		return
	end

	if petName and strlen(petName) == 0 then
		-- Summon the default pet specified above if no other pet name
		-- was provided with the command:
		petName = DEFAULT_PET
	end

	local _, petGUID = C_PetJournal.FindPetIDByName(petName)
	if petGUID then
		-- Summon the desired pet:
		C_PetJournal.SummonPetByGUID(petGUID)
	else
		-- Pet not found. Alert the user so they can fix it:
		print(format("Pet %q not found!", petName))
	end
end
If you need help turning the above code into an addon, copy and paste it into this page:
http://addon.ziuo.net/

If that's not what you want, please describe what you want more clearly. If it doesn't work correctly, please describe what doesn't work and provide any error messages captured by BugSack.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 03-09-13 at 06:57 PM.
  Reply With Quote
03-10-13, 10:29 AM   #4
jlrm365
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 113
Originally Posted by semlar View Post
You only want it to summon a pet if the player is moving?
No. I just wanted movement to be the trigger - as with NugMiniPet.
Often, standing still, I don't want a companion pet to be out.
Essentially what I wanted was the operation of NugMiniPet, but stripped down and to work with just a single companion.


Originally Posted by Phanx View Post
1. The default UI already has a "/summonpet White Kitten" command to summon a specific companion pet.
Thanks for your code, as ever.
I shall study it and then form it into an addon.
  Reply With Quote
03-10-13, 06:08 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you want it to happen automatically you probably want something like this:

Code:
local petName = "White Kitten"

local function CheckAndSummonPet()
	if InCombatLockdown() then
		-- You can't summon a pet in combat from insecure code.
		return
	end

	if C_PetJournal.GetSummonedPetGUID() then
		-- You already have a summoned pet.
		return
	end

	local _, petGUID = C_PetJournal.FindPetIDByName(petName)
	if petGUID then
		-- Summon the desired pet:
		C_PetJournal.SummonPetByGUID(petGUID)
	end
end

hooksecurefunc("MoveBackwardStart", CheckAndSummonPet)
hooksecurefunc("MoveForwardStart", CheckAndSummonPet)
hooksecurefunc("StrafeLeftStart", CheckAndSummonPet)
hooksecurefunc("StrafeRightStart", CheckAndSummonPet)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
03-10-13, 08:17 PM   #6
jlrm365
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 113
Originally Posted by Phanx View Post
If you want it to happen automatically you probably want something like this:

Code:
local petName = "White Kitten"

local function CheckAndSummonPet()
	if InCombatLockdown() then
		-- You can't summon a pet in combat from insecure code.
		return
	end

	if C_PetJournal.GetSummonedPetGUID() then
		-- You already have a summoned pet.
		return
	end

	local _, petGUID = C_PetJournal.FindPetIDByName(petName)
	if petGUID then
		-- Summon the desired pet:
		C_PetJournal.SummonPetByGUID(petGUID)
	end
end

hooksecurefunc("MoveBackwardStart", CheckAndSummonPet)
hooksecurefunc("MoveForwardStart", CheckAndSummonPet)
hooksecurefunc("StrafeLeftStart", CheckAndSummonPet)
hooksecurefunc("StrafeRightStart", CheckAndSummonPet)
That's even better. I'll test it out now.

Really appreciate the time.

I realise you may not look at PMs, but never be in doubt that your help is appreciated.

It is.
  Reply With Quote
03-10-13, 10:35 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by jlrm365 View Post
I realise you may not look at PMs, ...
I do, in general, but any PMs asking for help with addons or coding are either ignored or replied with a form letter, so if your PM started with a request for help of some kind, I probably did not read the rest of it before deleting it.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
03-11-13, 02:28 PM   #8
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
In case you want to unsummon your pet when entering stealth/prowl/camouflage:

lua Code:
  1. local petName = "White Kitten"
  2.  
  3. local _, class = UnitClass("player")
  4. local stealthBuff = class == "ROGUE" and GetSpellInfo(1784) -- Stealth
  5.     or class == "DRUID" and GetSpellInfo(5215) -- Prowl
  6.     or class == "HUNTER" and GetSpellInfo(51753) -- Camouflage
  7. --  or class == "MAGE" and GetSpellInfo(66) -- Invisibility (not sure if minipet also turns invisible??)
  8.  
  9. local function CheckAndSummonPet()
  10.     if stealthBuff and UnitBuff("player", stealthBuff) and C_PetJournal.GetSummonedPetGUID() then
  11.         -- You have a stealth buff and you have a companion out.
  12.         DismissCompanion("CRITTER") -- I'm assuming this function still works and is available in combat??
  13.         return
  14.     end
  15.    
  16.     if InCombatLockdown() then
  17.         -- You can't summon a pet in combat from insecure code.
  18.         return
  19.     end
  20.  
  21.     if C_PetJournal.GetSummonedPetGUID() then
  22.         -- You already have a summoned pet.
  23.         return
  24.     end
  25.  
  26.     local _, petGUID = C_PetJournal.FindPetIDByName(petName)
  27.     if petGUID then
  28.         -- Summon the desired pet:
  29.         C_PetJournal.SummonPetByGUID(petGUID)
  30.     end
  31. end
  32.  
  33. hooksecurefunc("MoveBackwardStart", CheckAndSummonPet)
  34. hooksecurefunc("MoveForwardStart", CheckAndSummonPet)
  35. hooksecurefunc("StrafeLeftStart", CheckAndSummonPet)
  36. hooksecurefunc("StrafeRightStart", CheckAndSummonPet)
Note: this is untested

Last edited by ravagernl : 03-11-13 at 02:39 PM. Reason: Fail!
  Reply With Quote
03-11-13, 02:42 PM   #9
jlrm365
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2007
Posts: 113
Originally Posted by ravagernl View Post
In case you want to unsummon your pet when entering stealth/prowl/camouflage:

lua Code:
  1. local petName = "White Kitten"
  2.  
  3. local _, class = UnitClass("player")
  4. local stealthBuff = class == "ROGUE" and GetSpellInfo(1784) -- Stealth
  5.     or class == "DRUID" and GetSpellInfo(5215) -- Prowl
  6.     or class == "HUNTER" and GetSpellInfo(51753) -- Camouflage
  7. --  or class == "MAGE" and GetSpellInfo(66) -- Invisibility (not sure if minipet also turns invisible??)
  8.  
  9. local function CheckAndSummonPet()
  10.     if stealthBuff and UnitBuff("player", stealthBuff) and C_PetJournal.GetSummonedPetGUID() then
  11.         -- You have a stealth buff and you have a companion out.
  12.         DismissCompanion("CRITTER") -- I'm assuming this function still works and is available in combat??
  13.         return
  14.     end
  15.    
  16.     if InCombatLockdown() then
  17.         -- You can't summon a pet in combat from insecure code.
  18.         return
  19.     end
  20.  
  21.     if C_PetJournal.GetSummonedPetGUID() then
  22.         -- You already have a summoned pet.
  23.         return
  24.     end
  25.  
  26.     local _, petGUID = C_PetJournal.FindPetIDByName(petName)
  27.     if petGUID then
  28.         -- Summon the desired pet:
  29.         C_PetJournal.SummonPetByGUID(petGUID)
  30.     end
  31. end
  32.  
  33. hooksecurefunc("MoveBackwardStart", CheckAndSummonPet)
  34. hooksecurefunc("MoveForwardStart", CheckAndSummonPet)
  35. hooksecurefunc("StrafeLeftStart", CheckAndSummonPet)
  36. hooksecurefunc("StrafeRightStart", CheckAndSummonPet)
Note: this is untested
Cool.
I've got the latest from Phanx in my folder.
I'll see how that goes and then try yours out another time.
If you happen to test it yourself, in the meantime, please do let us know how it went.

Thanks for the contribution, as that appears to be a nice tweak.
  Reply With Quote
03-11-13, 02:57 PM   #10
endx7
An Aku'mai Servant
 
endx7's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 38
Originally Posted by ravagernl View Post
lua Code:
  1. -- You have a stealth buff and you have a companion out.
  2.         DismissCompanion("CRITTER") -- I'm assuming this function still works and is available in combat??
Not sure if DismissCompanion still works in combat from insecure code, but when I last tested it, it only worked with pets you originally owned on that character before patch 5.0
  Reply With Quote
03-11-13, 03:49 PM   #11
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by endx7 View Post
Not sure if DismissCompanion still works in combat from insecure code, but when I last tested it, it only worked with pets you originally owned on that character before patch 5.0
Thanks, confirmed. It doesn't work. There doesn't seem to be any way to dismiss an account wide minipet in combat

Updated/changed slightly, I included a way to trigger random pets (either from your favorites or from all your pets)
Code:
local petName = "Egbert"
local random = 1 -- 1 for favorite random, 0 for a random pet from all pets, false to disable a random pet

local _, class = UnitClass("player")
local stealthBuff = class == "ROGUE" and GetSpellInfo(1784) -- Stealth
    or class == "DRUID" and GetSpellInfo(5215) -- Prowl
    or class == "HUNTER" and GetSpellInfo(51753) -- Camouflage
--  or class == "MAGE" and GetSpellInfo(66) -- Invisibility (not sure if minipet also turns invisible??)

local function CheckAndSummonPet()
    local activePet = C_PetJournal.GetSummonedPetGUID()

    if stealthBuff and UnitBuff("player", stealthBuff) then
        if activePet then
            -- You have a stealth buff and you have a minipet out.
            -- Can we use the journal functions?
            if not InCombatLockdown() then
                -- if the active pet is summoned again, it is dismissed using the journal function
                C_PetJournal.SummonPetByGUID(activePet)
            else
                -- Try the old function, this one works in combat for pets you actually own on your character.
                -- There is no way to unsummon account wide minipets in combat :(
                DismissCompanion("CRITTER")
            end
        end
        return
    end

    if InCombatLockdown() then
        -- You can't summon a pet in combat from insecure code.
        return
    end

    if activePet then
        -- You already have a summoned pet.
        return
    end

    if random == 1 or random == 0 then
        -- Summon a random pet (either a favorite(1) or from all pets(0) )
        C_PetJournal.SummonRandomPet(random == 1)
        return
    end

    local _, petGUID = C_PetJournal.FindPetIDByName(petName)
    if petGUID then
        -- Summon the desired pet:
        C_PetJournal.SummonPetByGUID(petGUID)
    end
end

hooksecurefunc("MoveBackwardStart", CheckAndSummonPet)
hooksecurefunc("MoveForwardStart", CheckAndSummonPet)
hooksecurefunc("StrafeLeftStart", CheckAndSummonPet)
hooksecurefunc("StrafeRightStart", CheckAndSummonPet)
This was tested
  Reply With Quote
03-11-13, 03:57 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You can detect stealth more efficiently by using macro conditionals:

Code:
if SecureCmdOptionParse("[stealth]") then
     print("You are stealthed.")
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
03-11-13, 04:25 PM   #13
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
There's no point in dismissing your pet while stealthed, nobody else will be able to see it.
  Reply With Quote
03-11-13, 05:12 PM   #14
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Originally Posted by semlar View Post
There's no point in dismissing your pet while stealthed, nobody else will be able to see it.


I didn't know that, since which patch?

EDIT: since 4.2 /facepalm
  Reply With Quote
03-11-13, 05:13 PM   #15
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Pets have stealthed with the player since 4.1, which was 2 years ago.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » Summon: 1 particular companion

Thread Tools
Display Modes

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