# Examples

## Examples

### Watermark

```lua
-- Capture table insantances
local Render    = fatality.render
local Config    = fatality.config
local Menu      = fatality.menu
local Callbacks = fatality.callbacks

-- Add a config item
local CheckboxConfigItem = Config:add_item( "Example Watermark Item", 0)
-- Add a checkbox
Menu:add_checkbox( "Example Watermark", "Visuals", "Misc", "Various", CheckboxConfigItem )

-- Get the colors of the menu
local BorderColor       = csgo.color(58, 36, 107, 255)
local BackgroundColor   = csgo.color(26, 22, 64, 200)

-- Create a font
local Verdana = Render:create_font( "verdana", 12, 0, 0 )

-- Set how many pixels of spacing we want 
local Spacing = csgo.vector2(10, 10)
local function OnPaint()
    -- Check if our checkbox is on (get_bool() == true) 
    -- If not then do nothing and return
    if not CheckboxConfigItem:get_bool() then
        return
    end
    -- Get our screensize
    local ScreenSize = Render:screen_size()
    -- Calculate the text size of the cheat name
    local TextSize = Render:text_size( Verdana, "Fatality.win" )

    -- Calculate our text size with spacing
    local Size =  csgo.vector2(TextSize.x + (3 * 2), TextSize.y + (3 * 2))
    local Position = csgo.vector2(ScreenSize.x - Size.x - Spacing.x, Spacing.y)

    -- Render background
    Render:rect_filled( Position.x, Position.y, Size.x, Size.y, BackgroundColor)
    Render:rect( Position.x, Position.y, Size.x, Size.y, BorderColor)

    -- Render our text
    Render:text( Verdana, Position.x + 3, Position.y + 3, "Fatality.win", csgo.color(255, 255, 255, 255) )
end

-- Add "paint" to our callback
Callbacks:add( "paint", OnPaint )
```

### Local hurt log

```lua
local Events        = csgo.interface_handler:get_events()
local EntityList    = csgo.interface_handler:get_entity_list()
local Cvar          = csgo.interface_handler:get_cvar()
local Callbacks     = fatality.callbacks

local function OnPlayerHurt(Event)
    -- Get attacker and victim id by calling get_int with aspect name
    local AttackerUserID    = Event:get_int("attacker")
    local VictimUserID      = Event:get_int("userid")

    -- Use id to get csgo.player from user id
    local AttackerPlayer    = EntityList:get_player_from_id(AttackerUserID)
    local VictimPlayer      = EntityList:get_player_from_id(VictimUserID)
    -- Get local player
    local LocalPlayer       = EntityList:get_localplayer()

    -- Check if we arent the attack but we are the victim
    if AttackerPlayer:get_index() ~= LocalPlayer:get_index() and VictimPlayer:get_index() == LocalPlayer:get_index() then
        -- Get the damage done to us 
        local DamageDone = Event:get_int("dmg_health")
        Cvar:print_dev_console(string.format("Hit by %s for %i", AttackerPlayer:get_name(), DamageDone))
    end
end

-- function to be called when a game event is fired
local function OnGameEvent(Event)
    
    local EventName = Event:get_name()
    
    -- Check if we the event that is called is the event we want
    if EventName == "player_hurt" then
        OnPlayerHurt(Event)
    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/getting-started/examples.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.
