WildStar:API EVENT UI HealthChanged

From AddOn Studio
Jump to navigation Jump to search

API events < UI.HealthChanged

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

Apollo.RegisterEventHandler("UI_HealthChanged", "OnHealthChanged", self)
function MyAddOn:OnHealthChnaged(newValue, maxCharacterHealth)


newValue [number] - current health. amount of health the player has, like 26774
maxPlayerHealth [number] - current maximum amount of maximal health the player can have


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.


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

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

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".