WoW:API GetCompanionInfo: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
m (Move page script moved page API GetCompanionInfo to API GetCompanionInfo without leaving a redirect)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{wowapi}} __NOTOC__
{{wowapi}} __NOTOC__
Returns information about the companions you have.
Returns information about the companions you have.
  creatureID, creatureName, creatureSpellID, icon, issummoned = GetCompanionInfo("type", id)
  creatureID, creatureName, creatureSpellID, icon, issummoned, mountTypeID = GetCompanionInfo("type", id)


== Arguments ==
== Arguments ==
;type : String ([[companionType]]) - Companion type to query: "CRITTER" or "MOUNT".
;type
;id : Integer - The slot id to query (starts at 1).
: String ([[companionType]]) - Companion type to query: "CRITTER" or "MOUNT".
;id
: Integer - The slot id to query (starts at 1).


== Returns ==
== Returns ==
;creatureID: Integer - The NPC ID of the companion.
;creatureID
;creatureName: String - The name of the companion.
: Integer - The NPC ID of the companion.
;creatureSpellID: Integer - The spell ID to cast the companion. This is not passed to [[API CallCompanion|CallCompanion]], but can be used with, e.g., [[API GetSpellInfo|GetSpellInfo]].
;creatureName
;icon: String - The texture of the icon for the companion.
: String - The name of the companion.
;issummoned: Flag - 1 if the companion is summoned, nil if it's not
;creatureSpellID
: Integer - The spell ID to cast the companion. This is not passed to [[API CallCompanion|CallCompanion]], but can be used with, e.g., [[API GetSpellInfo|GetSpellInfo]].
;icon
: String - The texture of the icon for the companion.
;issummoned
: Flag - 1 if the companion is summoned, nil if it's not
;mountTypeID
: Integer - 15 and 31 (0x0f and 0x1f) for flying mounts, 29 (0x1d) for ground mounts, 12 (0x0c) for water mounts and nil for companions. Difference between flying mount values unknown.


== Example ==
== Examples ==
;Example 1
  for i=1,GetNumCompanions("CRITTER") do
  for i=1,GetNumCompanions("CRITTER") do
     local creatureID, creatureName, creatureSpellID, icon, issummoned = GetCompanionInfo("CRITTER", i);
     local creatureID, creatureName, creatureSpellID, icon, issummoned = GetCompanionInfo("CRITTER", i);
     print(creatureID, creatureSpellID, creatureName, icon, issummoned)
     print(creatureID, creatureSpellID, creatureName, icon, issummoned)
end
Prints all the information regarding your pets to the chat frame:
7555 Hawk Owl 10706 Interface\Icons\Ability_EyeOfTheOwl 1
7553 Great Horned Owl 10707 Interface\Icons\Ability_EyeOfTheOwl nil
;Example 2
for i = 1, GetNumCompanions("MOUNT") do
    local _,name,_,_,_,typeID,typeString = GetCompanionInfo("mount", i)
    -- Assign local vars name and typeID from GetCompanionInfo(). Create unnasigned local var typeString.
    typeID = bit.band(3, typeID)
    -- Bitwise AND operator sets typeID to 0 for water, 1 for ground and 3 for flying mounts.
    typeString = typeID == 0 and "Water" or typeID == 1 and "Ground" or "Flying"
    -- Nested and..or operator to set typeString according to typeID.
    print(name, typeString)
  end
  end


===Result===
Prints the name of all of your mounts, followed by their mount type:
:Prints all the information regarding your pets to the chat frame.
Abyssal Seahorse Water
  7555 Hawk Owl 10706 Interface\Icons\Ability_EyeOfTheOwl 1
  Black Drake Mount Flying
  7553 Great Horned Owl 10707 Interface\Icons\Ability_EyeOfTheOwl nil
  Ochre Skeletal Warhorse Ground


== Notes ==
== Notes ==
* If called before the client updates the creature cache, GetCompanionInfo returns companions in the order in which they were learned by the current character (this can be observed during the first log-on after a patch or by removing the client's cache files). Once the cache is updated, however, it returns companions in alphabetical order; a COMPANION_UPDATE event is fired to notify of this update (however, multiple COMPANION_UPDATE events may be fired prior to the update as well). This was last verified in [[Patch 3.3.0a]].
* If called before the client updates the creature cache, GetCompanionInfo returns companions in the order in which they were learned by the current character (this can be observed during the first log-on after a patch or by removing the client's cache files). Once the cache is updated, however, it returns companions in alphabetical order; a COMPANION_UPDATE event is fired to notify of this update (however, multiple COMPANION_UPDATE events may be fired prior to the update as well). This was last verified in [[Patch 3.3.0a]].
* This function was introduced in [[Patch 3.0]].
* This function was introduced in [[Patch 3.0]].
;This command will be removed in the WoD 6.0 API and replaced with:
:mountName, spellID, icon, active, mountFlags = '''C_MountJournal.GetMountInfo'''(index)
:creatureID no longer is given at the beginning of the return list.
:There are many new '''C_PetJournal''' functions and I am unable to document them at this time.

Latest revision as of 04:45, 15 August 2023

WoW API < GetCompanionInfo

Returns information about the companions you have.

creatureID, creatureName, creatureSpellID, icon, issummoned, mountTypeID = GetCompanionInfo("type", id)

Arguments[edit]

type
String (companionType) - Companion type to query: "CRITTER" or "MOUNT".
id
Integer - The slot id to query (starts at 1).

Returns[edit]

creatureID
Integer - The NPC ID of the companion.
creatureName
String - The name of the companion.
creatureSpellID
Integer - The spell ID to cast the companion. This is not passed to CallCompanion, but can be used with, e.g., GetSpellInfo.
icon
String - The texture of the icon for the companion.
issummoned
Flag - 1 if the companion is summoned, nil if it's not
mountTypeID
Integer - 15 and 31 (0x0f and 0x1f) for flying mounts, 29 (0x1d) for ground mounts, 12 (0x0c) for water mounts and nil for companions. Difference between flying mount values unknown.

Examples[edit]

Example 1
for i=1,GetNumCompanions("CRITTER") do
    local creatureID, creatureName, creatureSpellID, icon, issummoned = GetCompanionInfo("CRITTER", i);
    print(creatureID, creatureSpellID, creatureName, icon, issummoned)
end

Prints all the information regarding your pets to the chat frame:

7555 Hawk Owl 10706 Interface\Icons\Ability_EyeOfTheOwl 1 
7553 Great Horned Owl 10707 Interface\Icons\Ability_EyeOfTheOwl nil
Example 2
for i = 1, GetNumCompanions("MOUNT") do
    local _,name,_,_,_,typeID,typeString = GetCompanionInfo("mount", i)
    -- Assign local vars name and typeID from GetCompanionInfo(). Create unnasigned local var typeString.
    typeID = bit.band(3, typeID)
    -- Bitwise AND operator sets typeID to 0 for water, 1 for ground and 3 for flying mounts.
    typeString = typeID == 0 and "Water" or typeID == 1 and "Ground" or "Flying"
    -- Nested and..or operator to set typeString according to typeID.
    print(name, typeString)
end

Prints the name of all of your mounts, followed by their mount type:

Abyssal Seahorse Water
Black Drake Mount Flying
Ochre Skeletal Warhorse Ground

Notes[edit]

  • If called before the client updates the creature cache, GetCompanionInfo returns companions in the order in which they were learned by the current character (this can be observed during the first log-on after a patch or by removing the client's cache files). Once the cache is updated, however, it returns companions in alphabetical order; a COMPANION_UPDATE event is fired to notify of this update (however, multiple COMPANION_UPDATE events may be fired prior to the update as well). This was last verified in Patch 3.3.0a.
  • This function was introduced in Patch 3.0.
This command will be removed in the WoD 6.0 API and replaced with
mountName, spellID, icon, active, mountFlags = C_MountJournal.GetMountInfo(index)
creatureID no longer is given at the beginning of the return list.
There are many new C_PetJournal functions and I am unable to document them at this time.