Created
July 8, 2018 12:43
-
-
Save infowolfe/aae31dce3c62af03c0d3d6d25ce2a3d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Def-- | |
local entity_get_prop = entity.get_prop | |
local entity_set_prop = entity.set_prop | |
local entity_get_all = entity.get_all | |
local entity_get_players = entity.get_players | |
local entity_is_enemy = entity.is_enemy | |
local entity_get_local_player = entity.get_local_player | |
local ui_get = ui.get | |
local ui_new_checkbox = ui.new_checkbox | |
local ui_new_combobox = ui.new_combobox | |
local ui_new_button = ui.new_button | |
local ui_new_slider = ui.new_slider | |
local ui_set_visible = ui.set_visible | |
local ui_new_multiselect = ui.new_multiselect | |
local ui_new_colorpicker = ui.new_color_picker | |
local cl_log = client.log | |
local string_format = string.format | |
local globals_curtime = globals.curtime | |
local globals_realtime = globals.realtime | |
local globals_absoluteframetime = globals.absoluteframetime | |
local globals_tickinterval = globals.tickinterval | |
local get_screen_size = client.screen_size | |
local client_userid_to_entindex = client.userid_to_entindex | |
local client_draw_text = client.draw_text | |
local client_draw_rectangle = client.draw_rectangle | |
local client_draw_gradient = client.draw_gradient | |
local client_get_latency = client.latency | |
local con_cmd = client.exec | |
local table_insert, table_remove = table.insert, table.remove | |
local math_min, math_abs, math_sqrt, math_floor, math_ceil = math.min, math.abs, math.sqrt, math.floor, math.ceil | |
--Ref-- | |
local enabled_ref = ui_new_checkbox("misc", "settings", "Customize HUD") | |
local hudColor = ui_new_combobox("misc", "settings", "HUD Color", "Default", "White", "Aqua", "Blue", "Purple", "Red", "Orange", "Yellow", "Green", "Cyan", "Pink") | |
local hRadar = ui_new_checkbox("misc", "settings", "Hide radar") | |
local Colors = ui_new_checkbox("misc", "settings", "Draw custom HUD") | |
local CPicker = ui_new_colorpicker("misc", "settings", "CP", 159, 202, 43, 25) | |
local DrawRect = ui_new_multiselect("misc", "settings", "Draw rectangles", "Logs", "Weapons", "Indicators") | |
local DrawText = ui_new_multiselect("misc", "settings", "Display", "FPS", "Ping", "Kills", "Deaths", "KDR", "CLIP") | |
--local ResCB = ui_new_checkbox("misc", "settings", "Custom resolution") | |
--local x = ui_new_slider("misc", "settings", "Position X", 1, 1920, 20, true) | |
--local y = ui_new_slider("misc", "settings", "Position Y", 1, 1080, 400, true) | |
--Dec-- | |
local sw, sh = get_screen_size() | |
local frametimes = {} | |
local fps_prev = 0 | |
local last_update_time = 0 | |
local kd = 0 | |
local kdr = 0 | |
local function accumulate_fps() | |
local rt, ft = globals_realtime(), globals_absoluteframetime() | |
if ft > 0 then | |
table_insert(frametimes, 1, ft) | |
end | |
local count = #frametimes | |
if count == 0 then | |
return 0 | |
end | |
local accum = 0 | |
local i = 0 | |
while accum < 0.5 do | |
i = i + 1 | |
accum = accum + frametimes[i] | |
if i >= count then | |
break | |
end | |
end | |
accum = accum / i | |
while i < count do | |
i = i + 1 | |
table_remove(frametimes) | |
end | |
local fps = 1 / accum | |
local time_since_update = rt - last_update_time | |
if math_abs(fps - fps_prev) > 4 or time_since_update > 1 then | |
fps_prev = fps | |
last_update_time = rt | |
else | |
fps = fps_prev | |
end | |
return math_floor(fps + 0.5) | |
end | |
local function round(b,c) | |
local d=10^(c or 0) | |
return math.floor(b*d+0.5)/d | |
end | |
local function HUDcolor() | |
local getcolor = ui_get(hudColor) | |
if getcolor == "Default" then | |
con_cmd("cl_hud_color 0") | |
cl_log("Changed HUD Color to Default") | |
elseif getcolor == "White" then | |
con_cmd("cl_hud_color 1") | |
cl_log("Changed HUD Color to White") | |
elseif getcolor == "Aqua" then | |
con_cmd("cl_hud_color 2") | |
cl_log("Changed HUD Color to Aqua") | |
elseif getcolor == "Blue" then | |
con_cmd("cl_hud_color 3") | |
cl_log("Changed HUD Color to Blue") | |
elseif getcolor == "Purple" then | |
con_cmd("cl_hud_color 4") | |
cl_log("Changed HUD Color to Purple") | |
elseif getcolor == "Red" then | |
con_cmd("cl_hud_color 5") | |
cl_log("Changed HUD Color to Red") | |
elseif getcolor == "Orange" then | |
con_cmd("cl_hud_color 6") | |
cl_log("Changed HUD Color to Orange") | |
elseif getcolor == "Yellow" then | |
con_cmd("cl_hud_color 7") | |
cl_log("Changed HUD Color to Yellow") | |
elseif getcolor == "Green" then | |
con_cmd("cl_hud_color 8") | |
cl_log("Changed HUD Color to Green") | |
elseif getcolor == "Cyan" then | |
con_cmd("cl_hud_color 9") | |
cl_log("Changed HUD Color to Cyan") | |
elseif getcolor == "Pink" then | |
con_cmd("cl_hud_color 10") | |
cl_log("Changed HUD Color to Pink") | |
end | |
end | |
ui.set_callback(hudColor, HUDcolor) | |
local function hideradar() | |
con_cmd("hideradar") | |
end | |
ui.set_callback(hRadar, hideradar) | |
local function scalehud() | |
con_cmd("hud_scaling 0.621500") | |
end | |
ui.set_callback(Colors, scalehud) | |
local function hudalpha() | |
con_cmd("cl_hud_background_alpha 0") | |
end | |
ui.set_callback(enabled_ref, hudalpha) | |
local function UIvisibility(this) | |
local g = ui_get(this) | |
ui_set_visible(hudColor, g) | |
ui_set_visible(hRadar, g) | |
ui_set_visible(Colors, g) | |
end | |
ui.set_callback(enabled_ref, UIvisibility) | |
local function slidersVisibility(this) | |
local g = ui_get(this) | |
ui_set_visible(CPicker, g) | |
ui_set_visible(DrawRect, g) | |
ui_set_visible(DrawText, g) | |
end | |
ui.set_callback(Colors, slidersVisibility) | |
local function handle_paint(ctx) | |
if not ui_get(enabled_ref) then | |
return end | |
if not ui_get(hRadar) then | |
con_cmd("drawradar") | |
end | |
if ui_get(Colors) then | |
getR, getG, getB, getA = ui_get(CPicker) | |
local fps = accumulate_fps() | |
local ping = math_min(999, client_get_latency() * 1000) | |
fps = math_min(999, fps) | |
local fps_text = string_format("%d", fps) | |
local ping_text = string_format("%d ms", ping) | |
local local_player = entity_get_local_player() | |
local hp = entity_get_prop(local_player, "m_iHealth") | |
local armor = entity_get_prop(local_player, "m_ArmorValue") | |
local cashmoney = entity_get_prop(local_player, "m_iAccount") | |
local playerresource = entity_get_all("CCSPlayerResource")[1] | |
local kills = entity_get_prop(playerresource, "m_iKills", local_player) | |
local deaths = entity_get_prop(playerresource, "m_iDeaths", local_player) | |
entity.set_prop(local_player, "m_iHideHud", 8200) -- hides default HUD | |
local r, g, b | |
if fps > 70 then | |
r, g, b = 159, 202, 43 | |
else | |
r, g, b = 255, 0, 0 | |
end | |
local fps_r, fps_g, fps_b = r, g, b | |
if fps < (1 / globals_tickinterval()) then | |
fps_r, fps_g, fps_b = 255, 0, 0 | |
end | |
local ping_r, ping_g, ping_b = r, g, b | |
local max_ping = 200 | |
if ping > max_ping then | |
ping_r, ping_b, ping_b = 255, 0, 0 | |
end | |
if hp == 0 then return end | |
local left = sw - sw | |
local right = sw | |
local top = sh - sh | |
local bot = sh+5 | |
local midw = sw/2 | |
local midh = sh/2 | |
local r2, g2, b2, a2 = 30, 30, 30, 255 | |
--Main drawing-- | |
client_draw_rectangle(ctx, left, bot-50, right, bot-50, getR, getG, getB, getA) -- main rect | |
client_draw_gradient(ctx, left, bot-51, right, 20, r2, g2, b2, a2, getR, getG, getB, getA, false) -- gs grad | |
client_draw_gradient(ctx, left, bot-52, right, 2, 0, 0, 0, 0, 0, 0, 0, 170, false) -- thin line above gs | |
--Texts-- | |
client_draw_text(ctx, midw+15, bot-44, 255, 255, 255, 230, "c+", 0, "game") -- g | |
client_draw_text(ctx, midw+85, bot-44, 149, 184, 6, 230, "c+", 0, "sense") -- s | |
client_draw_text(ctx, midw+50, bot-20, 255, 255, 255, 230, "c+", 0, " | ") -- Line between fps/ping (center of screen) | |
--if hp >= 0 and hp <= 100 then | |
if hp >= 0 then | |
client_draw_text(ctx, left+61, bot-22, 255, 255, 255, 230, nil, 0, "HP") | |
client_draw_text(ctx, left+30, bot-20, 159, 202, 43, 230, "c+", 0, hp) | |
end | |
if armor >= 100 then | |
client_draw_text(ctx, left+130, bot-22, 255, 255, 255, 230, nil, 0, "ARMOR") | |
client_draw_text(ctx, left+105, bot-20, 52, 152, 219, 230, "c+", 0, armor) | |
end | |
local selectedrec = ui_get(DrawRect) | |
for i=1, #selectedrec do | |
if selectedrec[i] == "Logs" then | |
client_draw_rectangle(ctx, left+5, top, 410, 85, getR, getG, getB, getA) | |
client_draw_gradient(ctx, left+5, top+83, 410, 2, 0, 0, 0, 0, 0, 0, 0, 170, false) | |
client_draw_text(ctx, left+180, top+84, 255, 255, 255, 230, nil, 0, "LOGS") | |
elseif selectedrec[i] == "Weapons" then | |
client_draw_text(ctx, right-130, midh+234, 255, 255, 255, 230, nil, 0, "WEAPONS") | |
client_draw_gradient(ctx, right-210, midh+244, 280, 2, 0, 0, 0, 0, 0, 0, 0, 170, false) | |
client_draw_rectangle(ctx, right-210, midh+245, 280, 310, getR, getG, getB, getA) | |
elseif selectedrec[i] == "Indicators" then | |
client_draw_rectangle(ctx, left+8, midh+380, 75, 115, getR, getG, getB, getA) | |
client_draw_gradient(ctx, left+8, midh+379, 75, 2, 0, 0, 0, 0, 0, 0, 0, 170, false) | |
end | |
end | |
local selectedtext = ui_get(DrawText) | |
for i=1, #selectedtext do | |
if selectedtext[i] == "FPS" then | |
client_draw_text(ctx, midw-3, midh+525, fps_r, fps_g, fps_b, 230, "c+", 0, fps_text, " fps") | |
elseif selectedtext[i] == "Ping" then | |
client_draw_text(ctx, midw+102, midh+525, ping_r, ping_g, ping_b, 230, "c+", 0, ping_text) | |
elseif selectedtext[i] == "Kills" then | |
if kills >= 0 then | |
client_draw_text(ctx, midw+342, midh+525, 159, 202, 43, 230, nil, 0, "KILLS") | |
client_draw_text(ctx, midw+290, midh+514, 159, 202, 43, 230, "+", 0, kills) | |
end | |
elseif selectedtext[i] == "Deaths" then | |
if deaths >= 0 then | |
client_draw_text(ctx, midw+432, midh+525, 255, 0, 0, 230, nil, 0, "DEATHS") | |
client_draw_text(ctx, midw+380, midh+514, 255, 0, 0, 230, "+", 0, deaths) | |
end | |
elseif selectedtext[i] == "KDR" then | |
if kills >= 0 and deaths >= 0 then | |
kd = kills / deaths | |
kdr = round(kd, 2) | |
if deaths == 0 then | |
kdr = kills | |
end | |
client_draw_text(ctx, midw+542, midh+525, 52, 152, 219, 230, nil, 0, "KDR") | |
client_draw_text(ctx, midw+480, midh+514, 52, 152, 219, 230, "+", 0, kdr) | |
end | |
elseif selectedtext[i] == "CLIP" then | |
client_draw_text(ctx, right-120, bot-27, 255, 255, 255, 255, "c+", 0, "CLIP: ") | |
end | |
if hp == 0 then return end -- if we dead don't draw anything | |
end | |
end | |
end | |
client.set_event_callback("paint", handle_paint) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment