๐Ÿš€ Creating a Simple ESP

An ESP script is a great way to learn the fundamentals of the API. This guide will show you how to draw a box around every enemy player.


This script uses three key components:

  1. entity.GetPlayers(): To get a list of all players.

  2. entity.IsEnemy() and entity.BoundingBox(): To check if a player is an enemy and get their screen position.

  3. draw.Rect(): To draw the box.


local function draw_esp()
    -- Get a list of all enemy player objects
    local enemy_players = entity.GetPlayers(true)

    for _, player in ipairs(enemy_players) do
        if player.IsAlive then
            -- Get the 2D bounding box from the player object's property
            local bbox = player.BoundingBox

            draw.Rect(bbox.x, bbox.y, bbox.w, bbox.h, Color3.fromRGB(255, 0, 0))


            local name = player.Name
            local teamColor = player.TeamColor -- This is a Color3 object
            
            -- Calculate text size to center it
            local text_width, text_height = draw.GetTextSize(name, "Tahoma")
            local text_x = bbox.x + (bbox.w / 2) - (text_width / 2)
            local text_y = bbox.y - text_height - 2 -- Position text above the box


            draw.text(name, text_x, text_y, Color3.fromRGB(teamColor.R, teamColor.G, teamColor.B), "Tahoma", 255)

            -- Draw a health bar
            local health_percent = player.Health / player.MaxHealth
            local bar_width = 5
            local bar_height = bbox.h * health_percent
            local bar_x = bbox.x - bar_width - 2
            local bar_y = bbox.y + (bbox.h - bar_height)
            

            draw.Rect(bar_x, bbox.y, bar_width, bbox.h, Color3.fromRGB(50, 0, 0))
            draw.RectFilled(bar_x, bar_y, bar_width, bar_height, Color3.fromRGB(0, 255, 0))
        end
    end
end

-- Register our function to the onPaint event
cheat.register("onPaint", draw_esp)

Last updated