# Plugin Support

This script supports user-made plugins.

## How to create a custom plugin

### Basic Preparation

1. Open the root folder of <mark style="color:yellow;">`visn_are`</mark>, there should be a <mark style="color:yellow;">`plugins`</mark> folder, open it.
2. Download the [sample plugin](https://github.com/veryinsanee/visn_are_sample_plugin) from our github page.
3. Drag and drop the folder inside the plugins folder.
4. Now rename the folder to your custom name.
5. Open the <mark style="color:yellow;">`plugin_test_client.lua`</mark> and edit the <mark style="color:yellow;">`pluginData`</mark>.
6. Do the same for <mark style="color:yellow;">`plugin_test_server.lua`</mark>.
7. Now rename the two files to your custom name, but this format is important:
   1. <mark style="color:yellow;">`plugin_NAME_TYPE.lua`</mark>
   2. Type can be: 'server' or 'client' -> It will decide if it will execute on client or server.

### Let's create our own content!

Let's create a plugin that prints a message when our heart rate is below 80.

Since this will be a client-side-plugin, we will open our client-side plugin file. (In this case <mark style="color:yellow;">`plugin_test_client.lua`</mark>)

Inside of the <mark style="color:yellow;">`RegisterClientPlugin`</mark> function we will put our logic.

To permanently print a message when our heart rate is below 80, we need a <mark style="color:yellow;">`thread`</mark> and a <mark style="color:yellow;">`while-loop`</mark>.

![](https://3719360761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fck7Fdkl3tw9GlGnkwHuu%2Fuploads%2Fdh6W0D4Qz3od1hrh0At9%2Fdddb3339b6d25d962236e3da344315e9.png?alt=media\&token=064d71eb-d4ac-468d-af3c-77aee5c922a0)

After we implemented it, we will access the [client health buffer](https://docs.veryinsanee.space/api-reference#client) and do a check if the heart rate is below 80.

![](https://3719360761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fck7Fdkl3tw9GlGnkwHuu%2Fuploads%2FOYYp8y1IdDjhlqZmdcbt%2F6dce65845a3f1d1e5729ae40c5ea7068.png?alt=media\&token=0c681219-48d8-4c9a-b37a-971ac88b3423)

Since everything in the if-statement will only trigger when the heart rate is below 80 we will just print <mark style="color:yellow;">`"Low on health!"`</mark> inside the statement.

The basic logic is done, but we need to prevent a client-crash so let's implement a <mark style="color:yellow;">`Citizen.Wait`</mark>-call inside the <mark style="color:yellow;">`while-loop`</mark>.

![](https://3719360761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fck7Fdkl3tw9GlGnkwHuu%2Fuploads%2FNHEkhUzMxBhdp63ImIiT%2F7f26696d0edd3068ca9babcf92bffeba.png?alt=media\&token=5ed53e0f-e5c1-4bb3-87cb-35378bad337c)

### **We are done!**&#x20;

After the resource has been started (or restarted) the plugin will load.

Now when are ingame and the heart rate is below 80, the console is getting spammed with <mark style="color:yellow;">`"Low on health!"`</mark>.

![](https://3719360761-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fck7Fdkl3tw9GlGnkwHuu%2Fuploads%2FUi24f7rWC4AxRDZwyBpx%2F4e6a417f0aea925a25947db456f659de.png?alt=media\&token=fac9f4e3-7880-46eb-bb0f-8f7f902a230d)

## Questions

<details>

<summary>Which functions can I use?</summary>

Take a look at the [API Reference](https://docs.veryinsanee.space/advanced-roleplay-environment/api-reference).

</details>
