# 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

Called every frame.&#x20;

Use to draw with the [render ](/documentation/namespaces/render.md)namespace.

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

### on\_paint\_traverse

Called every frame.

Use this to call surface functions with ffi.

```lua
function on_paint_traverse()

end
```

### on\_frame\_stage\_notify

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

| [Parameter](/getting-started/callbacks.md) | [Datatype](/getting-started/callbacks.md) |       [Description](/getting-started/callbacks.md)      |
| :----------------------------------------: | :---------------------------------------: | :-----------------------------------------------------: |
|                    stage                   |     [csgo.frame\_stage](#frame-stages)    |                     stage called on                     |
|                pre\_original               |                  boolean                  | whether or not frame\_stage\_notify has been called yet |

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

<details>

<summary>Stages</summary>

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

</details>

### on\_setup\_move

Called every game tick before the command is used internally.

Use to call movement-related things.

| [Parameter](/getting-started/callbacks.md) |     [Datatype](/getting-started/callbacks.md)     | [Description](/getting-started/callbacks.md) |
| :----------------------------------------: | :-----------------------------------------------: | :------------------------------------------: |
|                     cmd                    | [user\_cmd](/documentation/datatypes/user_cmd.md) |                 user command                 |

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

### on\_run\_command

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.

| [Parameter](/getting-started/callbacks.md) |     [Datatype](/getting-started/callbacks.md)     | [Description](/getting-started/callbacks.md) |
| :----------------------------------------: | :-----------------------------------------------: | :------------------------------------------: |
|                     cmd                    | [user\_cmd](/documentation/datatypes/user_cmd.md) |                 user command                 |

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

### on\_create\_move

Called every game tick after everything internally has finished.

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

| [Parameter](/getting-started/callbacks.md) |     [Datatype](/getting-started/callbacks.md)     | [Description](/getting-started/callbacks.md) |
| :----------------------------------------: | :-----------------------------------------------: | :------------------------------------------: |
|                     cmd                    | [user\_cmd](/documentation/datatypes/user_cmd.md) |                 user command                 |
|                send\_packet                |                      boolean                      |         true if a packet will be sent        |

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

### on\_input

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

| [Parameter](/getting-started/callbacks.md) | [Datatype](/getting-started/callbacks.md) |            [Description](/getting-started/callbacks.md)            |
| :----------------------------------------: | :---------------------------------------: | :----------------------------------------------------------------: |
|                     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             |

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

end
```

### on\_console\_input

| [Parameter](/getting-started/callbacks.md) | [Datatype](/getting-started/callbacks.md) | [Description](/getting-started/callbacks.md) |
| :----------------------------------------: | :---------------------------------------: | :------------------------------------------: |
|                    input                   |                   string                  |                 console input                |

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

### on\_shutdown

Called when the script is unloaded.

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

### on\_shot\_registered

Called after a shot has been fired.

Use to get information about shots.

| [Parameter](/getting-started/callbacks.md) |      [Datatype](/getting-started/callbacks.md)      | [Description](/getting-started/callbacks.md) |
| :----------------------------------------: | :-------------------------------------------------: | :------------------------------------------: |
|                 shot\_info                 | [shot\_info](/documentation/datatypes/shot_info.md) |             the shots information            |

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

### on\_level\_init

Called after the map has loaded.

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

### on\_game\_event

Called on any game event.

| [Parameter](/getting-started/callbacks.md) |       [Datatype](/getting-started/callbacks.md)       | [Description](/getting-started/callbacks.md) |
| :----------------------------------------: | :---------------------------------------------------: | :------------------------------------------: |
|                    event                   | [game\_event](/documentation/datatypes/game_event.md) |                  game event                  |

```lua
function on_game_event(event)

end
```

### on\_xxx

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.

| [Parameter](/getting-started/callbacks.md) |       [Datatype](/getting-started/callbacks.md)       | [Description](/getting-started/callbacks.md) |
| :----------------------------------------: | :---------------------------------------------------: | :------------------------------------------: |
|                    event                   | [game\_event](/documentation/datatypes/game_event.md) |                  game event                  |

```lua
function on_item_pickup(event)

end
```

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

Called after post processing has finished.

```lua
function on_do_post_screen_space_events()

end
```

### on\_config\_load

Called after a config is loaded.

```lua
function on_config_load()

end
```

### on\_config\_save

Called after a config has been saved.

```lua
function on_config_save()

end
```

### on\_esp\_flag

| [Parameter](/getting-started/callbacks.md) | [Datatype](/getting-started/callbacks.md) | [Description](/getting-started/callbacks.md) |
| :----------------------------------------: | :---------------------------------------: | :------------------------------------------: |
|                    index                   |                  integer                  |            index of player drawing           |

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

```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")),
    }
end
```

### on\_draw\_model\_execute

| [Parameter](/getting-started/callbacks.md) | [Datatype](/getting-started/callbacks.md) | [Description](/getting-started/callbacks.md) |
| :----------------------------------------: | :---------------------------------------: | :------------------------------------------: |
|                     dme                    |                  function                 |          calls dme (draws the model)         |
|                 ent\_index                 |                  integer                  |                entity's index                |
|                 model\_name                |                   string                  |                 model's name                 |

```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
```

## Player callbacks

### on\_player\_connect

Called after a player has connected.

| [Parameter](/getting-started/callbacks.md) |       [Datatype](/getting-started/callbacks.md)       | [Description](/getting-started/callbacks.md) |
| :----------------------------------------: | :---------------------------------------------------: | :------------------------------------------: |
|                    event                   | [game\_event](/documentation/datatypes/game_event.md) |                  game event                  |

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

### on\_player\_disconnect

Called after a player has disconnected.

| [Parameter](/getting-started/callbacks.md) |       [Datatype](/getting-started/callbacks.md)       | [Description](/getting-started/callbacks.md) |
| :----------------------------------------: | :---------------------------------------------------: | :------------------------------------------: |
|                    event                   | [game\_event](/documentation/datatypes/game_event.md) |                  game event                  |

```lua
function on_player_disconnect(event)

end
```

### on\_player\_spawn

Called after a player has spawned.

| [Parameter](/getting-started/callbacks.md) |       [Datatype](/getting-started/callbacks.md)       | [Description](/getting-started/callbacks.md) |
| :----------------------------------------: | :---------------------------------------------------: | :------------------------------------------: |
|                    event                   | [game\_event](/documentation/datatypes/game_event.md) |                  game event                  |

```lua
function on_player_spawn(event)

end
```

### on\_player\_hurt

Called after a player has been hurt.

| [Parameter](/getting-started/callbacks.md) |       [Datatype](/getting-started/callbacks.md)       | [Description](/getting-started/callbacks.md) |
| :----------------------------------------: | :---------------------------------------------------: | :------------------------------------------: |
|                    event                   | [game\_event](/documentation/datatypes/game_event.md) |                  game event                  |

```lua
function on_player_hurt(event)

end
```

### on\_player\_death

Called after a player has died.

| [Parameter](/getting-started/callbacks.md) |       [Datatype](/getting-started/callbacks.md)       | [Description](/getting-started/callbacks.md) |
| :----------------------------------------: | :---------------------------------------------------: | :------------------------------------------: |
|                    event                   | [game\_event](/documentation/datatypes/game_event.md) |                  game event                  |

```lua
function on_player_death(event)

end
```


---

# 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://golua.fatality.win/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.
