WildStar:API EVENT UI HealthChanged: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
(Created the page.)
 
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{\|uiapievent|name=UI_HealthChanged}}
The '''UI_HealthChanged''' global event triggers whenever the players health bar on the UI changes. It must register to receive events.
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.
{{\|api||Apollo|RegisterEventHandler}}("UI_HealthChanged", "OnHealthChanged", self)
function MyAddOn:OnHealthChnaged(newValue, maxCharacterHealth)


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


The UI_HealthChanged is registered via ''RegisterEventHandler ''in the following manner:
;Returns
Apollo.RegisterEventHandler("UI_HealthChanged", "''<yourFunctionName>''", self)
: none
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)
== Summary ==
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.


== Example ==
== Example ==
  Apollo.RegisterEventHandler("UI_HealthChanged", "OnDeath", self)
  Apollo.RegisterEventHandler("UI_HealthChanged", "OnDeath", self)
   
   
  function MyAddon:OnDeath(current, max)<br>
  function MyAddon:OnDeath(current, max)<br>
Line 22: Line 24:
       end<br>
       end<br>
  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.
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".
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".

Latest revision as of 07:41, 9 August 2023

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)

Usage[edit]

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

Summary[edit]

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.

Example[edit]

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