WoW:API GetCompanionInfo: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
m (→‎Example: There's no second argument for GetNumCompanions())
No edit summary
Line 1: Line 1:
{{wowapi}} __NOTOC__
{{wowapi}} __NOTOC__
 
Returns information about the companions you have.
 
<!-- Describe the purpose of the function, exhausting detail can be saved for a later section -->
Returns information about the companions you have. New in [[Patch 3.0]]
 
<!-- List return values and arguments as well as function name, follow Blizzard usage convention for args -->
  creatureID, creatureName, creatureSpellID, icon, issummoned = GetCompanionInfo("type", id)
  creatureID, creatureName, creatureSpellID, icon, issummoned = GetCompanionInfo("type", id)


== Parameters ==
== Arguments ==
=== Arguments ===
;type : String ([[companionType]]) - Companion type to query: "CRITTER" or "MOUNT".
<!-- List each argument, together with its type -->
;id : Integer - The slot id to query (starts at 1).
:("type")


:;type : String - The [[API TYPE TypeId|TypeID]] to query (e.g. "CRITTER", or "MOUNT")
== Returns ==
:;id : Integer - The slot id to query (starts at 1).
;creatureID: Integer - The NPC ID of the companion.
 
;creatureName: String - The name of the companion.
=== Returns ===
;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]].
<!-- List each return value, together with its type -->
;icon: String - The texture of the icon for the companion.
:;creatureID: Integer - The NPC ID of the companion.
;issummoned: Flag - 1 if the companion is summoned, nil if it's not
:;creatureName: String - The name 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]].
:;icon: String - The texture of the icon for the companion.
:;issummoned: integer - 1 if the companion is summoned, nil if it's not
 
== Known Issues ==
 
If called early in the loading process, before [[Events/Companion|COMPANION_UPDATE]] fires, GetCompanionInfo returns companions in the order that they were learned by the current character.  After COMPANION_UPDATE has fired at least once, GetCompanionInfo returns companions in alphabetical order.  This information is accurate as of WoW 3.1.2.


== Example ==
== Example ==
<!-- If it helps, include an example here, though it's not required if the usage is self-explanatory -->
<!-- begin code -->
  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
  end
<!-- end code -->


====Result====
===Result===
<!-- If it helps, include example results here, though they are not required. You're allowed to cheat liberally since WoW isn't a command line language. -->
:Prints all the information regarding your pets to the chat frame.
:Prints all the information regarding your pets to the chat frame.
<!-- begin code -->
  7555 Hawk Owl 10706 Interface\Icons\Ability_EyeOfTheOwl 1  
  7555 Hawk Owl 10706 Interface\Icons\Ability_EyeOfTheOwl 1  
  7553 Great Horned Owl 10707 Interface\Icons\Ability_EyeOfTheOwl nil  
  7553 Great Horned Owl 10707 Interface\Icons\Ability_EyeOfTheOwl nil  
<!-- end code -->
 
[[Category:World of Warcraft API]]
== 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]].
* This function was introduced in [[Patch 3.0]].

Revision as of 23:40, 5 June 2010

WoW API < GetCompanionInfo

Returns information about the companions you have.

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

Arguments

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

Returns

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

Example

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

Result

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 

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.
  • This function was introduced in Patch 3.0.