Skip to content

Instantly share code, notes, and snippets.

@x4fx77x4f
Last active September 21, 2022 20:46
Show Gist options
  • Save x4fx77x4f/446c4bfae2bddab0b62e110d2830c894 to your computer and use it in GitHub Desktop.
Save x4fx77x4f/446c4bfae2bddab0b62e110d2830c894 to your computer and use it in GitHub Desktop.
ESP chip using StarfallEx
--@name FTQ
local using = {}
if SERVER then
net.receive('usage', function(len, player)
net.start('usage')
net.writeEntity(player)
net.writeBool(net.readBool())
net.send()
end)
return
end
net.receive('usage', function()
using[net.readEntity()] = net.readBool()
end)
hook.add('hudconnected', '', function()
net.start('usage')
net.writeBool(true)
net.send()
end)
hook.add('huddisconnected', '', function()
net.start('usage')
net.writeBool(false)
net.send()
end)
if player() == owner() then
pcall(enableHud, player(), true)
end
if render.isHUDActive() then
net.start('usage')
net.writeBool(true)
net.send()
end
local alpha_dormant = 95
local color_box = Color(0, 0, 0)
local color_box_dormant = Color(color_box[1], color_box[2], color_box[3], alpha_dormant)
local color_box_dead = Color(95, 0, 0)
local color_box_dead_dormant = Color(color_box_dead[1], color_box_dead[2], color_box_dead[3], alpha_dormant)
local color_health = Color(63, 191, 63)
local color_armor = Color(63, 191, 255)
local color_name = Color(255, 255, 255)
local color_name_dormant = Color(color_name[1], color_name[2], color_name[3], alpha_dormant)
local color_name_using = Color(127, 255, 255)
local color_name_using_dormant = Color(color_name_using[1], color_name_using[2], color_name_using[3], alpha_dormant)
local function draw_bar(x, y, w, h, color, value, is_dormant)
if value <= 0 then
return x
end
x = x-w-math.ceil(w*0.5)-2
value = math.min(value, 1)
render.setRGBA(color_box[1], color_box[2], color_box[3], is_dormant and alpha_dormant or 255)
render.drawRectFast(x-2, y-2, w+2, h+4)
render.setRGBA(color[1], color[2], color[3], is_dormant and alpha_dormant or 255)
render.drawRectFast(x-1, y+h+1, w, -(h+2)*value)
return x
end
local eyepos
hook.add('calcview', '', function(pos, ang, fov, near, far)
eyepos = pos
end)
hook.add('drawhud', '', function()
if render.isInRenderView() then
return
end
local me = player()
if eyepos == nil then
eyepos = eyePos()
end
local plys = find.sortByClosest(find.allPlayers(function(ply)
return eyepos:getDistanceSqr(ply:getEyePos()) > 1
end), eyepos, true)
local sw, sh = render.getResolution()
for i=1, #plys do
local ply = plys[i]
-- Get the bounding box of the player in world space
local pos = ply:getPos()
local min, max = ply:obbMins(), ply:obbMaxs()
min:add(pos)
max:add(pos)
-- Draw a line from crosshair to their position
local ply_team = ply:getTeam()
local ply_team_color = team.getColor(ply_team)
local is_dormant = ply.isDormant ~= nil and ply:isDormant()
if is_dormant then
ply_team_color[4] = alpha_dormant
end
local sp = pos:toScreen()
render.setRGBA(ply_team_color[1], ply_team_color[2], ply_team_color[3], 127)
render.drawLine(sw/2, sh/2, sp.x, sp.y)
-- Get the screen position of all 8 corners of the bounding box
local minx, miny, minz = unpack(min)
local maxx, maxy, maxz = unpack(max)
local v1 = Vector(minx, miny, minz):toScreen()
if not v1.visible then
continue
end
local v2 = Vector(maxx, miny, minz):toScreen()
if not v2.visible then
continue
end
local v3 = Vector(minx, miny, maxz):toScreen()
if not v3.visible then
continue
end
local v4 = Vector(maxx, miny, maxz):toScreen()
if not v4.visible then
continue
end
local v5 = Vector(minx, maxy, minz):toScreen()
if not v5.visible then
continue
end
local v6 = Vector(maxx, maxy, minz):toScreen()
if not v6.visible then
continue
end
local v7 = Vector(minx, maxy, maxz):toScreen()
if not v7.visible then
continue
end
local v8 = Vector(maxx, maxy, maxz):toScreen()
if not v8.visible then
continue
end
local v1x, v2x, v3x, v4x, v5x, v6x, v7x, v8x = v1.x, v2.x, v3.x, v4.x, v5.x, v6.x, v7.x, v8.x
local v1y, v2y, v3y, v4y, v5y, v6y, v7y, v8y = v1.y, v2.y, v3.y, v4.y, v5.y, v6.y, v7.y, v8.y
local x = math.floor(math.min(v1x, v2x, v3x, v4x, v5x, v6x, v7x, v8x))
local w = math.ceil(math.max(v1x, v2x, v3x, v4x, v5x, v6x, v7x, v8x))-x
local y = math.floor(math.min(v1y, v2y, v3y, v4y, v5y, v6y, v7y, v8y))
local h = math.ceil(math.max(v1y, v2y, v3y, v4y, v5y, v6y, v7y, v8y))-y
local ply_health = ply:getHealth()
local ply_health_max = ply:getMaxHealth()
local ply_armor = ply:getArmor()
local ply_armor_max = ply:getMaxArmor()
-- Draw black and team-colored 2D box
local color_box = (
ply:isAlive()
and (is_dormant and color_box_dormant or color_box)
or (is_dormant and color_box_dead_dormant or color_box_dead)
)
render.setColor(color_box)
render.drawRectOutline(x-2, y-2, w+4, h+4)
render.drawRectOutline(x, y, w, h)
render.setColor(ply_team_color)
render.drawRectOutline(x-1, y-1, w+2, h+2)
-- Health/armor bars
local bx = x
local bw = math.ceil(math.clamp(32-math.log10(pos:getDistance(eyepos))*10, 1, 4))
bx = draw_bar(bx, y, bw, h, color_health, ply_health/ply_health_max, is_dormant)
bx = draw_bar(bx, y, bw, h, color_armor, ply_armor/ply_armor_max, is_dormant)
-- Text over head
render.setFont('BudgetLabel')
local color_name = (
using[ply]
and (is_dormant and color_name_using_dormant or color_name_using)
or (is_dormant and color_name_dormant or color_name)
)
render.setColor(color_name)
render.drawSimpleText(x+w/2, y-18, ply:getName(), TEXT_ALIGN.CENTER)
-- Text on side
local sw, sh = render.getResolution()
local cx, cy = math.floor(sw/2), math.floor(sh/2)
if
pos:getDistanceSqr(eyepos) < 150^2
or (cx >= x and cy >= y and cx < x+w and cy < y+h)
then
render.setColor(color_name)
render.drawText(x+w+6, y, string.format(
"%3d/%3d\n%3d/%3d\n%d:%q\n%q",
ply_health, ply_health_max,
ply_armor, ply_armor_max,
ply_team, team.getName(ply_team),
ply:getNWVar('UserGroup')
))
end
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment