openmohaa/docs/script/events.md

94 lines
2.4 KiB
Markdown
Raw Normal View History

2025-02-03 20:24:35 +01:00
# Events
2025-02-03 20:57:07 +01:00
OpenMoHAA introduces a new way for scripts to monitor for specific events, like players spawning or getting killed. Multiple scripts can subscribe to the same events.
2025-02-03 20:24:35 +01:00
## Subscribing
2025-02-03 20:57:07 +01:00
Commands related to events:
2025-02-03 20:24:35 +01:00
```cpp
event_subscribe event_name script_label
Subscribes to an event, script_label will be called when the event is triggered
event_unsubscribe event_name script_label
Unsubscribe from an event, script_label will not be called anymore
```
2025-02-03 20:57:07 +01:00
When an event is not needed anymore, make sure to call `event_unsubscribe` with the same parameters used when subscribing to the event.
### Example
2025-02-03 20:24:35 +01:00
```cpp
main:
event_subscribe "player_spawned" event_player_spawned
2025-02-03 20:57:07 +01:00
// Can specify another script:
//event_subscribe "player_spawned" global/test_script::event_player_spawned
2025-02-03 20:24:35 +01:00
end
event_player_spawned:
iprintlnbold("player entity number " + self.entnum + " just spawned!")
end
```
## List of events
### Player events
2025-02-03 20:57:07 +01:00
The `self` object is the player object for all triggered player events.
2025-02-03 20:24:35 +01:00
#### player_connected
2025-02-03 20:57:07 +01:00
The player entered the game.
2025-02-03 20:24:35 +01:00
2025-02-03 20:57:07 +01:00
Called when:
- On the next round (for all players)
2025-02-03 20:24:35 +01:00
- When a client spawns for the first time
2025-02-03 20:57:07 +01:00
- When the map restarts, or when the map changes (for all players)
2025-02-03 20:24:35 +01:00
2025-02-03 20:57:07 +01:00
This is called after the player finished spawning, and before `player_spawned` event.
2025-02-03 20:24:35 +01:00
#### player_damaged
The player just got hit.
The parameters are the same as the `damage` command:
```
player_damaged local.attacker local.damage local.inflictor local.position local.direction local.normal local.knockback local.damageflags local.meansofdeath local.location
```
#### player_disconnecting
The player is disconnecting.
#### player_killed
The player got killed.
The parameters are the same as the `killed` command:
```
player_killed local.attacker local.damage local.inflictor local.position local.direction local.normal local.knockback local.damageflags local.meansofdeath local.location
```
#### player_spawned
2025-02-03 20:57:07 +01:00
The player just spawned.
Called when:
2025-02-03 20:24:35 +01:00
- The player has entered the battle
- The player respawned or spawned with weapons
2025-02-03 20:57:07 +01:00
This is called after the player finished spawning.
2025-02-03 20:24:35 +01:00
2025-02-03 20:57:07 +01:00
The event can be called even for spectators (when the spectator gets respawned).
2025-02-03 20:24:35 +01:00
#### player_textMessage
The player sent a text message.
```
player_textMessage local.text local.is_team
```
Parameters:
- local.text: The full text message with battle language tokens applied
- local.is_team: `1` if it's a team message. `0` otherwise.