> For the complete documentation index, see [llms.txt](https://valex.gitbook.io/valex/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://valex.gitbook.io/valex/external-lua-environment/aimbot-library-lua-environment.md).

# Aimbot Library Lua Environment

## Aim Library Documentation

The `aim` library provides functions for targeting players, camera locking, and input detection for aimbot functionality.

***

### Input

#### `aim.is_key_held(key)`

Checks if a key or mouse button is currently held down.

* **Parameters:** `key` \[int] - Use `aim.keys` constants or virtual key codes
* **Returns:** `bool`

```lua
if aim.is_key_held(aim.keys.RIGHT_MOUSE) then
    print("Right mouse held")
end
```

***

### Player Discovery

#### `aim.get_players(exclude_local, exclude_team)`

Gets a list of all player addresses.

* **Parameters:**
  * `exclude_local` \[optional bool] - Skip local player (default: true)
  * `exclude_team` \[optional bool] - Skip teammates (default: false)
* **Returns:** `table` (array of uint64 addresses)

```lua
local players = aim.get_players(true, false)
for i, addr in ipairs(players) do
    local info = aim.get_player_info(addr)
    print(info.name)
end
```

#### `aim.get_player_info(player_addr)`

Gets detailed information about a player.

* **Parameters:** `player_addr` \[uint64]
* **Returns:** `table` with fields:
  * `exists` \[bool] - Player exists
  * `is_local` \[bool] - Is local player
  * `is_team` \[bool] - Is on same team
  * `name` \[string] - Player name
  * `health` \[float] - Current health
  * `max_health` \[float] - Maximum health
  * `has_character` \[bool] - Has spawned character

```lua
local info = aim.get_player_info(player_addr)
if info.exists and info.health > 0 then
    print(info.name .. " has " .. info.health .. " HP")
end
```

***

### Target Acquisition

#### `aim.get_closest_target(fov_radius, team_check, health_check)`

Finds the closest valid target to screen center.

* **Parameters:**
  * `fov_radius` \[optional float] - Maximum pixel distance from center (default: 9999)
  * `team_check` \[optional bool] - Skip teammates (default: false)
  * `health_check` \[optional bool] - Skip dead players (default: true)
* **Returns:** `table` with fields:
  * `address` \[uint64] - Player address (0 if none found)
  * `distance` \[float] - Pixel distance from screen center
  * `screen_x` \[float] - Screen X position
  * `screen_y` \[float] - Screen Y position
  * `name` \[string] - Player name
  * `health` \[float] - Current health
  * `max_health` \[float] - Maximum health

```lua
local target = aim.get_closest_target(200, false, true)
if target.address ~= 0 then
    print("Target: " .. target.name .. " at distance " .. target.distance)
end
```

#### `aim.get_screen_position(player_addr, body_part)`

Gets the screen position of a player's body part.

* **Parameters:**
  * `player_addr` \[uint64]
  * `body_part` \[optional string] - "head" or "torso" (default: "head")
* **Returns:** `table` with fields:
  * `visible` \[bool] - On screen
  * `x` \[float] - Screen X
  * `y` \[float] - Screen Y
  * `z` \[float] - Depth

```lua
local pos = aim.get_screen_position(target.address, "head")
if pos.visible then
    valex.draw_circle(pos.x, pos.y, 5, color3.red())
end
```

***

### Aiming Methods

#### `aim.aim_at_player(player_addr, smoothing, body_part)`

Moves the mouse towards a player using mouse input (for games with mouse-based aiming).

* **Parameters:**
  * `player_addr` \[uint64]
  * `smoothing` \[optional float] - Higher = slower/smoother (default: 1.0, min: 1.0)
  * `body_part` \[optional string] - "head" or "torso" (default: "head")
* **Returns:** `void`

```lua
valex.register("update", function()
    if aim.is_key_held(aim.keys.RIGHT_MOUSE) then
        local target = aim.get_closest_target(150)
        if target.address ~= 0 then
            aim.aim_at_player(target.address, 3.0, "head")
        end
    end
end)
```

#### `aim.lock_camera(player_addr, body_part)`

Directly locks the camera to look at a player (for games with camera-based aiming like Roblox shooters).

* **Parameters:**
  * `player_addr` \[uint64]
  * `body_part` \[optional string] - "head" or "torso" (default: "head")
* **Returns:** `void`

```lua
valex.register("update", function()
    if aim.is_key_held(aim.keys.X) then
        local target = aim.get_closest_target()
        if target.address ~= 0 then
            aim.lock_camera(target.address, "head")
        end
    end
end)
```

***

### Key Constants

Access via `aim.keys`:

#### Mouse Buttons

| Constant       | Description           |
| -------------- | --------------------- |
| `LEFT_MOUSE`   | Left mouse button     |
| `RIGHT_MOUSE`  | Right mouse button    |
| `MIDDLE_MOUSE` | Middle mouse button   |
| `MOUSE4`       | Mouse button 4 (side) |
| `MOUSE5`       | Mouse button 5 (side) |

#### Modifier Keys

| Constant    | Description   |
| ----------- | ------------- |
| `SHIFT`     | Shift key     |
| `CTRL`      | Control key   |
| `ALT`       | Alt key       |
| `SPACE`     | Spacebar      |
| `TAB`       | Tab key       |
| `CAPS`      | Caps Lock     |
| `ENTER`     | Enter key     |
| `ESCAPE`    | Escape key    |
| `BACKSPACE` | Backspace key |

#### Navigation Keys

| Constant   | Description |
| ---------- | ----------- |
| `INSERT`   | Insert      |
| `DELETE`   | Delete      |
| `HOME`     | Home        |
| `END`      | End         |
| `PAGEUP`   | Page Up     |
| `PAGEDOWN` | Page Down   |
| `UP`       | Arrow Up    |
| `DOWN`     | Arrow Down  |
| `LEFT`     | Arrow Left  |
| `RIGHT`    | Arrow Right |

#### Function Keys

| Constant     | Description        |
| ------------ | ------------------ |
| `F1` - `F12` | Function keys 1-12 |

#### Letter Keys

| Constant  | Description     |
| --------- | --------------- |
| `A` - `Z` | Letter keys A-Z |

#### Number Keys

| Constant              | Description     |
| --------------------- | --------------- |
| `0` - `9`             | Number keys 0-9 |
| `NUMPAD0` - `NUMPAD9` | Numpad 0-9      |

#### Numpad Operators

| Constant   | Description |
| ---------- | ----------- |
| `MULTIPLY` | Numpad \*   |
| `ADD`      | Numpad +    |
| `SUBTRACT` | Numpad -    |
| `DECIMAL`  | Numpad .    |
| `DIVIDE`   | Numpad /    |

#### Special Keys

| Constant    | Description |
| ----------- | ----------- |
| `TILDE`     | \~ key      |
| `MINUS`     | - key       |
| `EQUALS`    | = key       |
| `LBRACKET`  | \[ key      |
| `RBRACKET`  | ] key       |
| `BACKSLASH` | \ key       |
| `SEMICOLON` | ; key       |
| `QUOTE`     | ' key       |
| `COMMA`     | , key       |
| `PERIOD`    | . key       |
| `SLASH`     | / key       |

***

### Complete Examples

#### Basic Camera Lock Aimbot

```lua
-- Simple camera lock on X key
valex.register("update", function()
    if aim.is_key_held(aim.keys.X) then
        local target = aim.get_closest_target()
        if target.address ~= 0 then
            aim.lock_camera(target.address, "head")
        end
    end
end)

print("Camera Lock loaded! Hold X to lock onto closest target")
```

#### FOV-Limited Mouse Aimbot with Smoothing

```lua
local FOV_SIZE = 150
local SMOOTHING = 5.0

valex.register("update", function()
    if aim.is_key_held(aim.keys.RIGHT_MOUSE) then
        local target = aim.get_closest_target(FOV_SIZE, false, true)
        if target.address ~= 0 then
            aim.aim_at_player(target.address, SMOOTHING, "head")
        end
    end
end)

-- Draw FOV circle
valex.register("render", function()
    local screen = valex.get_screen_size()
    valex.draw_circle(screen.center_x, screen.center_y, FOV_SIZE, color3.white(), 0.5)
end)

print("Mouse Aimbot loaded! Hold Right Click to aim")
```

#### Target Info Display

```lua
valex.register("render", function()
    local target = aim.get_closest_target(300)
    
    if target.address ~= 0 then
        -- Draw line to target
        local screen = valex.get_screen_size()
        valex.draw_line(
            screen.center_x, screen.center_y,
            target.screen_x, target.screen_y,
            color3.red(), 1.0
        )
        
        -- Draw target info
        local info_text = target.name .. " | " .. math.floor(target.health) .. " HP"
        valex.draw_text(info_text, target.screen_x, target.screen_y - 20, color3.white())
    end
end)
```

#### Toggle Aimbot with Visual Feedback

```lua
local aimbot_enabled = false
local target_lock = nil

-- Toggle on F key press
valex.register("update", function()
    -- Simple toggle (you may want to add debounce)
    if aim.is_key_held(aim.keys.F) then
        if aim.is_key_held(aim.keys.RIGHT_MOUSE) then
            local target = aim.get_closest_target(200)
            if target.address ~= 0 then
                aim.lock_camera(target.address, "head")
                target_lock = target
            end
        else
            target_lock = nil
        end
    end
end)

valex.register("render", function()
    local screen = valex.get_screen_size()
    
    -- Draw FOV
    valex.draw_circle(screen.center_x, screen.center_y, 200, color3.green(), 0.3)
    
    -- Draw lock indicator
    if target_lock and target_lock.address ~= 0 then
        valex.draw_text("LOCKED: " .. target_lock.name, 10, 10, color3.red())
    end
end)

print("Toggle Aimbot - Hold F + Right Click to lock")
```
