12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 11 ■ Exploring the <strong>World</strong> <strong>of</strong> <strong>Warcraft</strong> API 191<strong>of</strong> the functions are quite simple; they take in one or two unit IDs <strong>and</strong> returnsome in<strong>for</strong>mation to the calling code. Table 11-3 shows a few <strong>of</strong> the differentunit functions.Table 11-3: Example Unit FunctionsUNIT FUNCTIONDESCRIPTIONexists =UnitExists(unit)Returns 1 if the unit exists, nil otherwise. For example,UnitExists(“target“) returns 1 only if you have atarget selected. Many <strong>of</strong> the other unit functions returnnil if UnitExists is nil.name, realm =UnitName(unit)level =UnitLevel(unit)reaction =UnitReaction(unit,otherUnit)health =UnitHealth(unit)mana =UnitPower(unit[,powerType)healthMax =UnitHealthMax(unit)manaMax =UnitManaMax(unit)Returns the name <strong>of</strong> the specified unit. If the unit is aplayer in a cross-realm battleground, the second return isthe server name, otherwise it is nil.Returns the level <strong>of</strong> the unit or –1 if you’re not supposedto know the level (special bosses, enemy players morethan 10 levels above you).Determines the reaction <strong>of</strong> unit to otherUnit. Returnsa number from 1–7, where 1 is extremely hostile, 7 is asfriendly as possible, <strong>and</strong> nil is returned if unknown.Returns the health <strong>of</strong> the unit. For the player, the player’spet, party/raid members, <strong>and</strong> their pets, health is theabsolute number <strong>of</strong> hit points. All other units return apercentage from 0–100.Same as UnitHealth but <strong>for</strong> mana, rage, energy, <strong>and</strong>focus (collectively referred to as mana throughout theAPI). By default this function returns the current powertype that unit is using, but you can specify a secondargument to query another power type (<strong>for</strong> example, themana <strong>of</strong> a druid who is shapeshifted).Returns the maximum health <strong>of</strong> the unit (actual number<strong>of</strong> hit points or 100 depending on the same criteria asUnitHealth).Same as UnitHealthMax but <strong>for</strong> mana.Each <strong>of</strong> these functions takes in unit IDs that follow a very simple pattern.A unit ID can be one <strong>of</strong> the tokens listed in Table 11-4 with either pet addedto the end, or possible target included an arbitrary number <strong>of</strong> times. Forexample, party1target shows the target <strong>of</strong> your first party member, <strong>and</strong>party2pettarget represents the target <strong>of</strong> your second party member’s pet.Additionally, the <strong>WoW</strong> client will accept the name <strong>of</strong> a party or raid memberas a unit ID. These unit ID tokens are not case-sensitive.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!