# Callbacks

{% hint style="info" %}
Although this api does not use true callbacks, they will be referred to as such.
{% endhint %}

## How to use

To create a callback you need to use one of the many names listed below to access them.

```lua
-- Callbacks CANNOT be local
-- "local function on_shot_fired" will not work

function on_shot_fired(shot_info)
    print(string.format("Expected damage: %i", shot_info.client_damage)
end

function on_paint()
    render.rect_filled(10, 10, 110, 110, render.color("#FFFFFF"))
end
```

## Callbacks

### on\_paint

```lua
function on_paint()
    render.rect_filled(10, 10, 110, 110, render.color("#FFFFFF"))
end
```

#### Usage:

Called every frame.&#x20;

Use to draw with the [render ](https://fecality-api.gitbook.io/docs/getting-started/broken-reference)namespace.

### on\_paint\_traverse

```lua
function on_paint_traverse()

end
```

#### Usage:

Called every frame.

Use this to call surface functions with ffi.

### on\_frame\_stage\_notify

```lua
function on_frame_stage_notify(stage, pre_original)
    if stage == csgo.frame_render_start then
        print("Rendering has started!")
    end
end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) | [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                        stage                                       |                         [csgo.frame\_stage](#frame-stages)                        |                                    stage called on                                   |
|                                    pre\_original                                   |                                      boolean                                      |                whether or not frame\_stage\_notify has been called yet               |

<details>

<summary>Frame stages</summary>

* frame\_undefined
* frame\_start
* frame\_render\_start
* frame\_net\_update\_start
* frame\_net\_update\_postdataupdate\_start
* frame\_net\_update\_postdataupdate\_end
* frame\_net\_update\_end
* frame\_render\_end

</details>

#### Usage:

Called when on a specific [frame](https://developer.valvesoftware.com/wiki/Frame_Order).

### on\_setup\_move

```lua
function on_setup_move(cmd)
    cmd:set_move(xxx)
end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |  [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                         cmd                                        | [user\_cmd](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |                                     user command                                     |

#### Usage:

Called every game tick before the command is used internally.

Use to call movement related things.

### on\_run\_command

```lua
function on_run_command(cmd)
    cmd:set_view_angles(xxx)
end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |  [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                         cmd                                        | [user\_cmd](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |                                     user command                                     |

#### Usage:

Called for every tick in a choked cycle the moment it is going to be sent to the server, after the cheat's anti-aim has run.

Use to change angles without cheat interference. All angle changes will be movement corrected.

### on\_create\_move

```lua
function on_create_move(cmd)
    do_anti_aim()
end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |  [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                         cmd                                        | [user\_cmd](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |                                     user command                                     |

#### Usage:

Called every game tick after everything internally has finished.

Use to run something on a per-tick basis that does not modfy commands.

### on\_input

```lua
function on_input(msg, wParam, lParam)

end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) | [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                         msg                                        |                                       number                                      |          [window message](https://wiki.winehq.org/List_Of_Windows_Messages)          |
|                                       wParam                                       |                                       number                                      |                      used to pass values with specific messages                      |
|                                       lParam                                       |                                       number                                      |                      used to pass values with specific messages                      |

#### Usage:

Called on [wndproc](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nc-winuser-wndproc).

### on\_console\_input

```lua
function on_console_input(input)
    
end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) | [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                        input                                       |                                       string                                      |                                     console input                                    |

### on\_shutdown

```lua
function on_shutdown()
    
end
```

#### Usage:

Called when the script is unloaded.

### on\_shot\_registered

```lua
function on_shot_registered(shot_info)
    print(string.format("Expected damage: %i", shot_info.client_damage))
end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |  [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference)  | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                     shot\_info                                     | [shot\_info](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |                                 the shots information                                |

#### Usage:

Called after a shot has been fired.

Use to get information about shots.

### on\_level\_init

```lua
function on_level_init()
    
end
```

#### Usage:

Called after the map has loaded.

### on\_game\_event

```lua
function on_game_event(event)

end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |   [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference)  | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                        event                                       | [game\_event](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |                                      game event                                      |

#### Usage:

Called on any game event.

### on\_xxx

```lua
function on_item_pickup(event)

end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |   [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference)  | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                        event                                       | [game\_event](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |                                      game event                                      |

#### Usage:

Called on a specific game event.&#x20;

Read the [list of events](https://wiki.alliedmods.net/Counter-Strike:_Global_Offensive_Events) and prefix one with "on\_" to set a callback to it.

### on\_do\_post\_screen\_space\_events

```lua
function on_do_post_screen_space_events()

end
```

#### Usage:

Called after post processing has finished.

### on\_config\_load

```lua
function on_config_load()

end
```

#### Usage:

Called after a config is loaded.

### on\_config\_save

```lua
function on_config_save()

end
```

#### Usage:

Called after a config has been saved.

### on\_esp\_flag

<pre class="language-lua"><code class="lang-lua">function on_esp_flag(index)
    return
    {
        render.esp_flag("first extra flag", render.color("#FFFFFF")),
        render.esp_flag("second extra flag", render.color("#FFFFFF")),
<strong>    }
</strong>end
</code></pre>

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) | [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                        index                                       |                                      integer                                      |                                index of player drawing                               |

{% hint style="info" %}
Return a table of flags that you want to add
{% endhint %}

### on\_draw\_model\_execute

```lua
function on_draw_model_execute(dme, ent_index, model_name)
   
   -- How to do overlay cham
   dme() -- call dme to draw the model with the normal material
   mat.override_material(overlay_mat) -- set the overlay material
   -- you do not need to call dme again. it is called after the callback
end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) | [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                         dme                                        |                                      function                                     |                              calls dme (draws the model)                             |
|                                     ent\_index                                     |                                      integer                                      |                                    entity's index                                    |
|                                     model\_name                                    |                                       string                                      |                                     model's name                                     |

## Player callbacks

### on\_player\_connect

```lua
function on_player_connect(event)
    print("player connected")
end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |   [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference)  | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                        event                                       | [game\_event](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |                                      game event                                      |

#### Usage:

Called after a player has connected.

### on\_player\_disconnect

```lua
function on_player_disconnect(event)

end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |   [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference)  | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                        event                                       | [game\_event](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |                                      game event                                      |

#### Usage:

Called after a player has disconnected.

### on\_player\_spawn

```lua
function on_player_spawn(event)

end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |   [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference)  | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                        event                                       | [game\_event](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |                                      game event                                      |

#### Usage:

Called after a player has spawned.

### on\_player\_hurt

```lua
function on_player_hurt(event)

end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |   [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference)  | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                        event                                       | [game\_event](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |                                      game event                                      |

#### Usage:

Called after a player has been hurt.

### on\_player\_death

```lua
function on_player_death(event)

end
```

| [Parameter](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |   [Datatype](https://fecality-api.gitbook.io/docs/getting-started/broken-reference)  | [Description](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |
| :--------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------: |
|                                        event                                       | [game\_event](https://fecality-api.gitbook.io/docs/getting-started/broken-reference) |                                      game event                                      |

#### Usage:

Called after a player has died.


---

# 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://fecality-api.gitbook.io/docs/getting-started/callbacks.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.
