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]) 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 So if you are a druid and you are currently in cat form by using Code:
local SPELL_POWER_MANA = 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 |
Illuminating for people who aren't sure how to handle the UnitPower* APIs and related events, but, and don't take this as anything other than curiosity on my behalf, why post this here? Unless someone asked, and using the WowI forums is a means to an end?
|
I think it's a good submission to the "Tutorials & Other Helpful Info" category! :)
|
Quote:
|
WoD updated the powertype index 4 for WoD. That index now reflects player combo points.
http://wowpedia.org/PowerType |
All times are GMT -6. The time now is 01:00 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI