events
Balamod provides a set of events that you can hook into to modify the game’s behavior. Below is a list of events that you can hook into.
| name | args | return | description |
|---|---|---|---|
| on_enable | None | nil | Called when the mod is enabled and also AFTER game initialization if mod was not disabled |
| on_disable | None | nil | Called when the mod is disabled, it’s a good place to clean up changes |
| menu | None | nil | Called when the mod menu is opened, it will add a “menu” button if you returned it in the table near the “enable/disable” button that calls the function. |
| on_game_load | args:array: The program arguments | nil | Called before the game is loaded, you can modify the game’s behavior here. It’s recommended tu use injection here. |
| on_game_quit | None | nil | Called when the game is quit, you can clean up changes here. |
| on_key_pressed | key:string: The key pressed, see KeyConstant | nil|boolean | Called when a key is pressed. Setting the return value to true will prevent the key from being processed by the game. |
| on_key_released | key:string: The key released, see KeyConstant | nil|boolean | Called when a key is released. Setting the return value to true will prevent the key from being processed by the game. |
| on_mouse_pressed | button:number: The mouse button pressed (1: left, 2: right, 3: middle), x:number: The x position, y:number: The y position, touch:boolean: If it’s a touchscreen touch-press. | nil|boolean | Called when a mouse button is pressed. Setting the return value to true will prevent the mouse event from being processed by the game. |
| on_mouse_released | button:number: The mouse button released (1: left, 2: right, 3: middle), x:number: The x position, y:number: The y position. | nil|boolean | Called when a mouse button is released. Setting the return value to true will prevent the mouse event from being processed by the game. |
| on_mousewheel | x:number: The x scroll amount, y:number: The y scroll amount | nil|boolean | Called when the mouse wheel is scrolled. Setting the return value to true will prevent the mouse event from being processed by the game. |
| on_pre_render | None | nil | Called before the game starts rendering a frame. |
| on_post_render | None | nil | Called after the game finishes rendering a frame. |
| on_error | message:string: The error message | nil | Called when an error occurs. |
| on_pre_update | dt:number: The time since the last update in seconds | nil|boolean | Called before the game updates. Setting the return value to true will prevent the update from being processed by the game. |
| on_post_update | dt:number: The time since the last update in seconds | nil | Called after the game updates. |