Advertisement
ZernaxLeDozo

Untitled

Nov 11th, 2018
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.91 KB | None | 0 0
  1. local table_insert = table.insert
  2. local table_remove = table.remove
  3. local globals_realtime = globals.realtime
  4. local globals_tickcount = globals.tickcount
  5. local globals_tickinterval = globals.tickinterval
  6. local globals_frametime = globals.frametime
  7. local globals_absoluteframetime = globals.absoluteframetime
  8. local entity_get_all = entity.get_all
  9. local entity_get_prop = entity.get_prop
  10. local entity_get_local_player = entity.get_local_player
  11. local client_draw_rectangle = client.draw_rectangle
  12. local client_draw_text = client.draw_text
  13. local client_screen_size = client.screen_size
  14. local client_latency = client.latency
  15. local ui_get = ui.get
  16. local ui_set_visible = ui.set_visible
  17. local math_floor = math.floor
  18. local math_sqrt = math.sqrt
  19. local math_min = math.min
  20. local math_abs = math.abs
  21. local string_format = string.format
  22. local client_draw_line = client.draw_line
  23.  
  24. --local pingspike_reference = ui.reference("MISC", "Miscellaneous", "Ping spike")
  25. local antiut_reference = ui.reference("MISC", "Settings", "Anti-untrusted")
  26. local enabled_reference = ui.new_combobox("VISUALS", "Effects", "Watermark", "Off", "On", "Rainbow")
  27. local color_reference = ui.new_color_picker("VISUALS", "Effects", "Watermark", 149, 184, 6, 255)
  28. local velocity_reference = ui.new_checkbox("VISUALS", "Effects", "Show velocity")
  29.  
  30. local frametimes = {}
  31. local fps_prev = 0
  32. local last_update_time = 0
  33.  
  34. local offset_x, offset_y = -193, 15
  35. --local offset_x, offset_y = 525, 915 --debug, show above net_graph
  36. local alpha = 230
  37.  
  38. local function draw_container(ctx, x, y, w, h)
  39. local c = {10, 60, 40, 40, 40, 60, 20}
  40. for i = 0,6,1 do
  41. client_draw_rectangle(ctx, x+i, y+i, w-(i*2), h-(i*2), c[i+1], c[i+1], c[i+1], 255)
  42. end
  43. end
  44.  
  45. local function draw_rectangle_outline(ctx, x, y, w, h, thickness, r, g, b, a)
  46. thickness = thickness or 1
  47.  
  48. if thickness == 1 then
  49. client_draw_line(ctx, x, y, x + w, y, r, g, b, a) -- Top | x, y, x + width, y
  50. client_draw_line(ctx, x, y + h, x + w, y + h, r, g, b, a) -- Bottom | x, y + height, x + width, y + height
  51. client_draw_line(ctx, x, y, x, y + h, r, g, b, a) -- Left | x, y, x, y + height
  52. client_draw_line(ctx, x + w, y, x + w, y + h, r, g, b, a) -- Right | x + height, y, x + height, y + height
  53. return
  54. end
  55.  
  56. for i = 0, thickness do
  57. client_draw_line(ctx, x - thickness, y - i, x + w + thickness, y - i, r, g, b, a) -- Top
  58. client_draw_line(ctx, x - thickness, y + h + i, x + w + thickness, y + h + i, r, g, b, a) -- Bottom
  59. client_draw_line(ctx, x - i, y - thickness, x - i, y + h + thickness, r, g, b, a) -- Left
  60. client_draw_line(ctx, x + w + i, y - thickness, x + w + i, y + h + thickness, r, g, b, a) -- Right
  61. end
  62. end
  63.  
  64. local function on_watermark_changed()
  65. local value = ui_get(enabled_reference)
  66. ui_set_visible(velocity_reference, value ~= "Off")
  67. ui_set_visible(color_reference, value ~= "Rainbow")
  68. end
  69.  
  70. local function hsv_to_rgb(h, s, v, a)
  71. local r, g, b
  72.  
  73. local i = math_floor(h * 6);
  74. local f = h * 6 - i;
  75. local p = v * (1 - s);
  76. local q = v * (1 - f * s);
  77. local t = v * (1 - (1 - f) * s);
  78.  
  79. i = i % 6
  80.  
  81. if i == 0 then r, g, b = v, t, p
  82. elseif i == 1 then r, g, b = q, v, p
  83. elseif i == 2 then r, g, b = p, v, t
  84. elseif i == 3 then r, g, b = p, q, v
  85. elseif i == 4 then r, g, b = t, p, v
  86. elseif i == 5 then r, g, b = v, p, q
  87. end
  88.  
  89. return r * 255, g * 255, b * 255, a * 255
  90. end
  91.  
  92. local function accumulate_fps()
  93. local rt, ft = globals_realtime(), globals_absoluteframetime()
  94.  
  95. if ft > 0 then
  96. table_insert(frametimes, 1, ft)
  97. end
  98.  
  99. local count = #frametimes
  100. if count == 0 then
  101. return 0
  102. end
  103.  
  104. local accum = 0
  105. local i = 0
  106. while accum < 0.5 do
  107. i = i + 1
  108. accum = accum + frametimes[i]
  109. if i >= count then
  110. break
  111. end
  112. end
  113.  
  114. accum = accum / i
  115.  
  116. while i < count do
  117. i = i + 1
  118. table_remove(frametimes)
  119. end
  120.  
  121. local fps = 1 / accum
  122. local time_since_update = rt - last_update_time
  123. if math_abs(fps - fps_prev) > 4 or time_since_update > 1 then
  124. fps_prev = fps
  125. last_update_time = rt
  126. else
  127. fps = fps_prev
  128. end
  129.  
  130. return math_floor(fps + 0.5)
  131. end
  132.  
  133. local function on_paint(ctx)
  134. local fps = accumulate_fps()
  135.  
  136. local enabled = ui_get(enabled_reference)
  137. if enabled == "Off" then
  138. return
  139. end
  140.  
  141. local screen_width, screen_height = client_screen_size()
  142. local x = offset_x >= 0 and offset_x or screen_width + offset_x
  143. local y = offset_y >= 0 and offset_y or screen_height + offset_y
  144.  
  145. local velocity_enabled = ui_get(velocity_reference)
  146.  
  147. --watermark
  148. local local_player = entity_get_local_player()
  149. local ping = math_min(999, client_latency() * 1000)
  150.  
  151. fps = math_min(999, fps)
  152.  
  153. local fps_text = string_format("%d", fps)
  154. local ping_text = string_format("%dms", ping)
  155.  
  156. local offset_x_temp = -7
  157. local velocity = 0
  158. local velocity_text
  159.  
  160. if velocity_enabled then
  161. local velocityX, velocityY = entity_get_prop(local_player, "m_vecVelocity")
  162. if velocityX then
  163. velocity = math_sqrt(velocityX*velocityX + velocityY*velocityY)
  164. velocity = math_min(9999, velocity) + 0.2
  165. velocity_text = string_format("%d", velocity)
  166. offset_x_temp = 43
  167. end
  168. end
  169.  
  170. local r, g, b = 255, 255, 255
  171. if enabled == "Rainbow" then
  172. r, g, b = hsv_to_rgb(globals_tickcount() % 350 / 350, 1, 1, 255)
  173. end
  174.  
  175. draw_container(ctx, x-offset_x_temp, y, 182+offset_x_temp, 30)
  176.  
  177. local r_sense, g_sense, b_sense = ui_get(color_reference)
  178.  
  179. client_draw_text(ctx, x+11-offset_x_temp, y+8, 255, 255, 255, alpha, nil, 0, "game")
  180. client_draw_text(ctx, x+38-offset_x_temp, y+8, r_sense, g_sense, b_sense, alpha, nil, 0, "sense")
  181. client_draw_text(ctx, x+68-offset_x_temp, y+8, 255, 255, 255, alpha, nil, 0, " | ")
  182.  
  183. local fps_r, fps_g, fps_b = r, g, b
  184. if fps < (1 / globals_tickinterval()) then
  185. fps_r, fps_g, fps_b = 255, 0, 0
  186. end
  187.  
  188. local fps_x = 81-offset_x_temp
  189. client_draw_text(ctx, x+fps_x+38, y+8, fps_r, fps_g, fps_b, alpha, "r", 0, fps_text, " fps")
  190.  
  191. client_draw_text(ctx, x+fps_x+37, y+8, 255, 255, 255, alpha, nil, 0, " | ")
  192.  
  193. local ping_r, ping_g, ping_b = r, g, b
  194. local max_ping = 200
  195. if not ui_get(antiut_reference) then
  196. max_ping = 100
  197. end
  198.  
  199. if ping > max_ping then
  200. ping_r, ping_g, ping_b = 255, 0, 0
  201. end
  202.  
  203. local ping_x = 126-offset_x_temp
  204. client_draw_text(ctx, x+ping_x+38, y+8, ping_r, ping_g, ping_b, alpha, "r", 0, ping_text)
  205.  
  206. if velocity_enabled then
  207. local velocity_x = 139-offset_x_temp
  208. client_draw_text(ctx, x+ping_x+38, y+8, 255, 255, 255, alpha, nil, 0, " | ")
  209. client_draw_text(ctx, x+velocity_x+38+26, y+8, 255, 255, 255, alpha, "r", 0, velocity_text)
  210. client_draw_text(ctx, x+velocity_x+38+26, y+11, 255, 255, 255, alpha, "-", 0, "u / t")
  211.  
  212. end
  213. end
  214.  
  215. client.set_event_callback("paint", on_paint)
  216. ui.set_callback(enabled_reference, on_watermark_changed)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement