add entity events to docs

This commit is contained in:
MihailRis 2024-07-16 14:29:56 +03:00
parent 50050dbe40
commit ef22b2d7e0
2 changed files with 127 additions and 0 deletions

View File

@ -136,3 +136,66 @@ rig:set_texture(key: str, value: str)
-- Returns the bone index by name or nil
rig:index(name: str) -> int
```
## Component events
```lua
function on_despawn()
```
Called when the entity is despawned.
```lua
function on_grounded(force: number)
```
Called on landing. The first argument is the impact force (Speed module).
```lua
function on_fall()
```
Called when the entity starts to fall.
```lua
function on_save()
```
Called before component data is saved. Here you can write the data you want to save into the *SAVED_DATA* table, which is available for the entire life of the component.
```lua
function on_sensor_enter(index: int, entity: int)
```
Called when another entity hits the sensor with the index passed as the first argument. The UID of the entity that entered the sensor is passed as the second argument.
```lua
function on_sensor_exit(index: int, entity: int)
```
Called when another entity exits the sensor with the index passed as the first argument. The UID of the entity that left the sensor is passed as the second argument.
```lua
function on_aim_on(playerid: int)
```
Called when the player aims at the entity. The player ID is passed as an argument.
```lua
function on_aim_off(playerid: int)
```
Called when the player takes aim away from the entity. The player ID is passed as an argument.
```lua
function on_attacked(attackerid: int, playerid: int)
```
Called when an entity is attacked (LMB on the entity). The first argument is the UID of the attacking entity. The attacking player ID is passed as the second argument. If the entity was not attacked by a player, the value of the second argument will be -1.
```lua
function on_used(playerid: int)
```
Called when an entity is used (RMB by entity). The player ID is passed as an argument.

View File

@ -145,3 +145,67 @@ rig:is_visible([optional] index: int) -> bool
-- или всего скелета, если индекс не указан
rig:set_visible([optional] index: int, status: bool)
```
## События компонента
```lua
function on_despawn()
```
Вызывается при удалении сущности.
```lua
function on_grounded(force: number)
```
Вызывается при приземлении. В качестве первого аргумента передается сила удара. (На данный момент - модуль скорости).
```lua
function on_fall()
```
Вызывается при начале падения.
```lua
function on_save()
```
Вызывается перед сохранением данных компонентов. Здесь можно записать данные, которые нужно сохранить, в таблицу *SAVED_DATA*, которая доступна весь срок жизни компонента.
```lua
function on_sensor_enter(index: int, entity: int)
```
Вызывается при попадании другой сущности в сенсор с индексом, передаваемым первым аргументом. UID сущности, попавшей в сенсор, передается вторым аргументом.
```lua
function on_sensor_exit(index: int, entity: int)
```
Вызывается при выходе другой сущности из сенсора с индексом, передаваемым первым аргументом. UID сущности, покинувшей сенсор, передается вторым аргументом.
```lua
function on_aim_on(playerid: int)
```
Вызывается при наведении прицела игрока на сущность. ID игрока передается в качестве аргумента.
```lua
function on_aim_off(playerid: int)
```
Вызывается когда игрок уводит прицел с сущности. ID игрока передается в качестве аргумента.
```lua
function on_attacked(attackerid: int, playerid: int)
```
Вызывается при атаке на сущность (ЛКМ по сущности). Первым аргументом передается UID атакующей сущности. ID атакующего игрока передается вторым аргументом. Если сущность была атакована не игроком, значение второго аргумента будет равно -1.
```lua
function on_used(playerid: int)
```
Вызывается при использовании сущности (ПКМ по сущности). ID игрока передается в качестве аргумента.