# Health Node

The node enables the addition of health capabilities, which can be adjusted by invoking the health `update_amount` function. It can automatically send signals based on changes in the health amount and set properties.

## Features

* Customizable health and maximum health values.
* Simplified connection to a `TextureProgressBar` and `ProgressBar` node as a health bar.
* Configurable auto-hide feature for the health bar.
* Option to switch from manual to automatic health update behavior.
* Ability to pause the automatic health update for a specified number of seconds.
* Ability to enable or disable damageable, healable, and revivable behaviors.
* Signals are emitted based on behavior, set properties, and updates to health amounts.

## How the idea started

*"I searched the Asset Library for a health component but found only limited options. Since health is a crucial component in almost every game, as most games utilize some form of health mechanism for their characters, I decided to create my own. I didn't expect it to become this versatile."*

## Video Demo/Tutorial

{% embed url="<https://www.youtube.com/watch?v=CS524A5O90s>" %}
Health Node plugin in Godot!
{% endembed %}

## How to use

#### Adding the node

After enabling this plugin, you can add the `Health` node as a child of another node, usually a `CharacterBody` or `StaticBody`, to use its capabilities.

1. Right-click on a node or press Ctrl+A.

<div align="left"><figure><img src="/files/jLdepCsmIBFYKeVYOxxK" alt=""><figcaption><p>Adding a new node</p></figcaption></figure></div>

2. Type "health" on the Search textbox of the Create New Node form to filter the node list and easily find the `Health` node.

<div align="left"><figure><img src="/files/DlYwHsyuVlE5T4wNGy43" alt=""><figcaption><p>Searching the health node</p></figcaption></figure></div>

3. Double-click the `Health` node to add as a child of the node.

<div align="left"><figure><img src="/files/yqdIfyUQoo6kzxNPepqn" alt=""><figcaption><p>Health node as a child node</p></figcaption></figure></div>

## Properties

#### Health

* **Amount:** The current amount of health.
* **Max Amount**: The maximum amount of health.

#### Interface

* **Texture Progress**: The visual representation of the health status using `TextureProgressBar` node.
* **Progress**: The visual representation of the health status using `ProgressBar` node.
* **Hide in Seconds**: The number of seconds until the health bar is hidden from view.  If the value is set to 0, the health bar will remain visible at all times.

#### Behavior

* **Behavior**: The behavior of the health node
  * ***Default***: Manual control.
  * ***Auto Increase***: Automatically increase health by **Change Percent**.
  * ***Auto Decrease***: Automatically decrease health by **Change Percent**.
* **Change Percent**: The percentage of automatic change, calculated based on the **Max Amount**. If **Behavior** is set to `Default`, no changes will occur, even if the percentage is greater than 0.
* **Change in Seconds**: The number of seconds until an automatic health change occurs. The automatic health change is controlled by a change timer in the health node.
* **Pause in Seconds**: The number of seconds to pause the automatic health change. The pause in automatic health change is controlled by a pause timer in the health node.

#### Switches

* **Damageable**: Enable this if health can be decreased.
* **Healable**: Enable this if health can be increased.
* **Revivable**: Enable this if health can be increased when the amount is already at or below 0.

#### Emitters

* **Emit Damage**: Enable this to emit the `damage` signal.
* **Emit Death**: Enable this to emit the `death` signal.
* **Emit Heal**: Enable this to emit the `heal` signal.
* **Emit Revive**: Enable this to emit the `revive` signal.

## Functions

* ***get\_class()** -> <mark style="color:green;">String</mark>*

Returns the object's class name, as a String. This function overrides the base Object's built-in function Object.get\_class.

* ***is\_behavior\_paused()** -> <mark style="color:green;">bool</mark>*

A function to check if the automatic health change is paused.

* ***pause\_behavior()***

A function to pause the automatic health change for a specified number of seconds using the **Pause in seconds** value.&#x20;

Changing the behavior to default will not stop the pause timer. However, if the behavior is restarted while the pause timer is active, it will likely delay the start of the change timer until the pause timer expires.

* ***sync\_healthbar()***

A function to synchronize the health bar with the current health values.

* ***update\_amount(**\_amount: <mark style="color:green;">float</mark>**)***

A function that updates the health amount and emits signals based on the amount. The *`_amount`* parameter is the value added to the current health **Amount**.

## Signals

* ***update(**&#x62;ody: <mark style="color:green;">Node</mark>, amount: <mark style="color:green;">float</mark>, health: <mark style="color:green;">float</mark>**)***

This signal is emitted when the health is updated. The parameter *body* refers to the parent of this node, the parameter *amount* is the value added to the health, and the parameter *health* is the new health value after adding *amount*.

{% hint style="info" %}
If parameter *amount* is negative, the **damage** signal will be emitted if **Damageable** and **Emit Damage** is enabled; if it is positive, the **heal** signal will be emitted if **Healable** and **Emit Heal** is enabled.
{% endhint %}

{% hint style="info" %}
If the **GlobalHealth** singleton is enabled, this signal is emitted on a global scale.
{% endhint %}

* ***damage(**&#x64;amage: <mark style="color:green;">float</mark>, health: <mark style="color:green;">float</mark>**)***

This signal is emitted when the health is updated with a negative amount.

{% hint style="info" %}
This is emitted only if **Damageable** and **Emit Damage** are enabled.
{% endhint %}

* ***heal(**&#x72;ecovery: <mark style="color:green;">float</mark>, health: <mark style="color:green;">float</mark>**)***

This signal is emitted when the health is updated with a positive amount.

{% hint style="info" %}
This is emitted only if **Healable** and **Emit Heal** are enabled.
{% endhint %}

* ***death()***

This signal is emitted when the health reaches or falls below 0.

{% hint style="info" %}
This is emitted only if **Damageable** and **Emit Death** are enabled.
{% endhint %}

* ***revive(**&#x61;mount: <mark style="color:green;">float</mark>, health: <mark style="color:green;">float</mark>**)***

This signal is emitted when the health is updated with a positive parameter *amount* while the current health value is 0 or negative.

{% hint style="info" %}
This is emitted only if **Revivable** and **Emit Revive** are enabled.
{% endhint %}

## Global Health (auto load)

The `GlobalHealth` singleton facilitates global relay of the **update** signal.

## Screenshots

<figure><img src="/files/1byojUuun5iD6f5rYfVT" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/8nvMedlU8CiQesRqIPZE" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://plugins.jbsnippets.com/my-plugins/health-node.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
