🚀 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:
entity.GetPlayers()
: To get a list of all players.entity.IsEnemy()
andentity.BoundingBox()
: To check if a player is an enemy and get their screen position.draw.rectOutline()
: 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.rectOutline(bbox.x, bbox.y, bbox.w, bbox.h, 255, 0, 0, 255)
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.measureText(1, name)
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(text_x, text_y, teamColor.R, teamColor.G, teamColor.B, 255, 1, name)
-- Draw a health bar
local health_percent = player.Health / player.MaxHealth
local bar_width = 5
local bar_height = bbox.h * health_percent ealth
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, 50, 0, 0, 200)
draw.rect(bar_x, bar_y, bar_width, bar_height, 0, 255, 0, 255)
end
end
end
-- Register our function to the onPaint event
cheat.register("onPaint", draw_esp)
Last updated