WildStar:API EVENT UI HealthChanged

Revision as of 15:44, 27 June 2014 by 84.142.99.254 (talk) (Created the page.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The UI_HealthChanged global event triggers whenever the players health bar on the UI changes. It must register to receive events.

Due to it's ability to trigger whenever the players health on the UI bar changes this event can be used for doing something when the player reaches a certain percentage of health or you could use it for determining whether or not your health is full. It's also possible to do react to when the health of the player reaches zero.

Usage

The UI_HealthChanged is registered via RegisterEventHandler in the following manner:

Apollo.RegisterEventHandler("UI_HealthChanged", "<yourFunctionName>", self)

After the event has been registered we create a new function in our Addon.

function <yourAddonName>:<yourFunctionName>(<varCurrHealth>, <varMaxPlayerHealth>)

Parameters: - The amount of health the player has (as number e.g. 26774)

- The amount of maximal health the player has (as number)

Example

Apollo.RegisterEventHandler("UI_HealthChanged", "OnDeath", self)


function MyAddon:OnDeath(current, max)
if current <= 0 then
ChatSystemLib.PostOnChannel(CHANNEL.SYSTEM, "You're dead")
end
end

First we register the event by calling RegisterEventHandler. The first argument is the event "UI_HealthChanged" the second argument is the function we want to call when the event is triggered which is going to be "OnDeath" in this example. As the last argument we give RegisterEventHandler our Addon by using self.

Now since the event is registered, we're going to create a new function in our addon which receives the current health of the player and the max health of the player. By checking whether or not the current health equals zero or lower we can check whether or not the player died. Once we figured out we're going to send a message to the system channel that says "You're dead".