11-21-13, 03:56 AM | #1 | |
Explaining UnitPower
I thought it might by helpful to bring some light into UnitPower.
The unit power function calls are: Code:
local p = UnitPower(unit[, POWER_TYPE_INDEX][, FULL_POWER]) local pm = UnitPowerMax(unit[, POWER_TYPE_INDEX][, FULL_POWER]) Code:
local p = UnitPower("player") At its current state WoW knows a ton of other power types. Instead of getting the default power it is possible to access any other unit power by adding a second argument, the POWER_TYPE_INDEX. Full unit power list as of state WoW patch 5.4.1 Code:
POWER_INDEX_VARIABLE POWER_INDEX Type ================================================================================================= SPELL_POWER_MANA 0 Mana SPELL_POWER_RAGE 1 Rage SPELL_POWER_FOCUS 2 Focus SPELL_POWER_ENERGY 3 Energy ??? 4 Combo Points SPELL_POWER_RUNES 5 Deathknight Runes SPELL_POWER_RUNIC_POWER 6 Deathknight Runic Power SPELL_POWER_SOUL_SHARDS 7 Warlock Affliction Soul Shards SPELL_POWER_ECLIPSE 8 Druid Balance Eclipse SPELL_POWER_HOLY_POWER 9 Paladin Holy Power SPELL_POWER_ALTERNATE_POWER 10 Alternate Power used in certain boss encounters or in mini-games SPELL_POWER_DARK_FORCE 11 -- SPELL_POWER_CHI 12 Monk Chi SPELL_POWER_SHADOW_ORBS 13 Priest Shadow Orbs SPELL_POWER_BURNING_EMBERS 14 Warlock Destruction Burning Embers SPELL_POWER_DEMONIC_FURY 15 Warlock Demonology Demonic Fury So if you are a druid and you are currently in cat form by using Code:
local SPELL_POWER_MANA = SPELL_POWER_MANA local p = UnitPower("player", SPELL_POWER_MANA) Before we get to a full example a quick note. The above is a list of global variables that will deliver the corresponding power type index. The index is needed to access the correct power value. When working with powers you will register events to your frame. At the current state of the game that will probably be "UNIT_POWER" or "UNIT_POWER_FREQUENT". When those events fire they will deliver 4 arguments: SELF, EVENT, UNIT, POWER_TYPE_TOKEN. The token itself does nothing, it is just a string. But you can use that string to access the corresponding power type index from the global scope by doing: _G["SPELL_POWER_"..POWER_TYPE_TOKEN] lua Code:
When using the above example it will print you all unit power values from the WoW API that triggered an event for the "player" and the "vehicle" unit. When you play a class that runs multiple power types you will recognize that multiple power types fire constantly. So using one bar to display all the powers is impossible. One has to create multiple bars for multiple powers and register specific power types per bar. To check which is the default unit power one can use UnitPowerType(UnitId). To prevent event spam the powerTypeToken of the event should be checked against a list of active power types available for that bar. (Example: https://github.com/haste/oUF/blob/ma...icons.lua#L164) The last point I want to talk about is the difference between Code:
local up = UnitPower(unit, powerTypeIndex) Code:
local upf = UnitPower(unit, powerTypeIndex, true) Example. lua Code:
Sources: http://wowprogramming.com/docs/api/UnitPower http://www.wowwiki.com/API_UnitPower http://wowpedia.org/API_UnitPower http://wowprogramming.com/docs/api/UnitPowerMax http://www.wowwiki.com/API_UnitPowerMax http://wowpedia.org/API_UnitPowerMax
__________________
| Simple is beautiful. | WoWI AddOns | GitHub | Zork (WoW)
Last edited by zork : 11-05-14 at 03:52 PM. |
||
WoWInterface » Developer Discussions » Tutorials & Other Helpful Info. » Explaining UnitPower |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Switch to Hybrid Mode |
Threaded Mode |
|
|