# Events

## Functions

### add\_event

adds an event to the event manager

`events:add_event( event_name )`

|  Parameter  | Data type |                                         Description                                         |
| :---------: | :-------: | :-----------------------------------------------------------------------------------------: |
| event\_name |   string  | [name of event to add](https://wiki.alliedmods.net/Counter-Strike:_Global_Offensive_Events) |

## Cheat Events

### level\_init

called once the map and all entities have been initialized

## Example

```lua
local Events        = csgo.interface_handler:get_events()
local Callbacks     = fatality.callbacks

-- function to be called when a game event is fired
local function OnGameEvent(Event)
    
    local EventName = Event:get_name()
    
    -- Check if the event that is called is the one we want
    if EventName == "player_hurt" then
        print("A player was hurt")
    end
end

-- Add player_hurt to our event manager
Events:add_event("player_hurt")
-- Add our function to the events callback
Callbacks:add("events", OnGameEvent)
```


---

# 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://lua.legacy.fatality.win/csgo/interfaces/events.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.
