This repository has been archived by the owner on Jul 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
pingspike_warning.lua
260 lines (210 loc) · 11.9 KB
/
pingspike_warning.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
--local variables for API. Automatically generated by https://github.com/simpleavaster/gslua/blob/master/authors/sapphyrus/generate_api.lua
local client_latency, client_log, client_draw_rectangle, client_draw_circle_outline, client_userid_to_entindex, client_draw_indicator, client_draw_gradient, client_set_event_callback, client_screen_size, client_eye_position = client.latency, client.log, client.draw_rectangle, client.draw_circle_outline, client.userid_to_entindex, client.draw_indicator, client.draw_gradient, client.set_event_callback, client.screen_size, client.eye_position
local client_draw_circle, client_color_log, client_delay_call, client_draw_text, client_visible, client_exec, client_trace_line, client_set_cvar = client.draw_circle, client.color_log, client.delay_call, client.draw_text, client.visible, client.exec, client.trace_line, client.set_cvar
local client_world_to_screen, client_draw_hitboxes, client_get_cvar, client_draw_line, client_camera_angles, client_draw_debug_text, client_random_int, client_random_float = client.world_to_screen, client.draw_hitboxes, client.get_cvar, client.draw_line, client.camera_angles, client.draw_debug_text, client.random_int, client.random_float
local entity_get_local_player, entity_is_enemy, entity_hitbox_position, entity_get_player_name, entity_get_steam64, entity_get_bounding_box, entity_get_all, entity_set_prop = entity.get_local_player, entity.is_enemy, entity.hitbox_position, entity.get_player_name, entity.get_steam64, entity.get_bounding_box, entity.get_all, entity.set_prop
local entity_is_alive, entity_get_player_weapon, entity_get_prop, entity_get_players, entity_get_classname = entity.is_alive, entity.get_player_weapon, entity.get_prop, entity.get_players, entity.get_classname
local globals_realtime, globals_absoluteframetime, globals_tickcount, globals_curtime, globals_mapname, globals_tickinterval, globals_framecount, globals_frametime, globals_maxplayers = globals.realtime, globals.absoluteframetime, globals.tickcount, globals.curtime, globals.mapname, globals.tickinterval, globals.framecount, globals.frametime, globals.maxplayers
local ui_new_slider, ui_new_combobox, ui_reference, ui_set_visible, ui_is_menu_open, ui_new_color_picker, ui_set_callback, ui_set, ui_new_checkbox, ui_new_hotkey, ui_new_button, ui_new_multiselect, ui_get = ui.new_slider, ui.new_combobox, ui.reference, ui.set_visible, ui.is_menu_open, ui.new_color_picker, ui.set_callback, ui.set, ui.new_checkbox, ui.new_hotkey, ui.new_button, ui.new_multiselect, ui.get
local math_ceil, math_tan, math_log10, math_randomseed, math_cos, math_sinh, math_random, math_huge, math_pi, math_max, math_atan2, math_ldexp, math_floor, math_sqrt, math_deg, math_atan, math_fmod = math.ceil, math.tan, math.log10, math.randomseed, math.cos, math.sinh, math.random, math.huge, math.pi, math.max, math.atan2, math.ldexp, math.floor, math.sqrt, math.deg, math.atan, math.fmod
local math_acos, math_pow, math_abs, math_min, math_sin, math_frexp, math_log, math_tanh, math_exp, math_modf, math_cosh, math_asin, math_rad = math.acos, math.pow, math.abs, math.min, math.sin, math.frexp, math.log, math.tanh, math.exp, math.modf, math.cosh, math.asin, math.rad
local table_maxn, table_foreach, table_sort, table_remove, table_foreachi, table_move, table_getn, table_concat, table_insert = table.maxn, table.foreach, table.sort, table.remove, table.foreachi, table.move, table.getn, table.concat, table.insert
local string_find, string_format, string_rep, string_gsub, string_len, string_gmatch, string_dump, string_match, string_reverse, string_byte, string_char, string_upper, string_lower, string_sub = string.find, string.format, string.rep, string.gsub, string.len, string.gmatch, string.dump, string.match, string.reverse, string.byte, string.char, string.upper, string.lower, string.sub
--end of local variables
local enabled_reference = ui.new_multiselect("VISUALS", "Other ESP", "Enemy pingspike warning", "Container", "Above name", "Brazilian flag")
local color_reference = ui.new_color_picker("VISUALS", "Other ESP", "Enemy pingspike warning", 255, 30, 30, 240)
local maxping_reference = ui.new_slider("VISUALS", "Other ESP", "Max tolerated ping", 1, 999, 180, true, "ms")
local function contains(table, val)
for i=1,#table do
if table[i] == val then
return true
end
end
return false
end
local function draw_container(ctx, x, y, w, h)
local c = {10, 60, 40, 40, 40, 60, 20}
for i = 0,6,1 do
client_draw_rectangle(ctx, x+i, y+i, w-(i*2), h-(i*2), c[i+1], c[i+1], c[i+1], 255)
end
end
local function draw_brazilian_flag(ctx, x, y, a_multiplier)
local width, height = 19, 13
--green background
client_draw_rectangle(ctx, x, y, width, height, 0, 156, 55, 255*a_multiplier)
--yellow rectangle
client_draw_line(ctx, x+3, y+height/2, x+width/2, y+2, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+3, y+height/2, x+width/2, y+height-3, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+width-3, y+height/2, x+width/2, y+2, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+width-3, y+height/2, x+width/2, y+height-3, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+4, y+height/2, x+width/2, y+2, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+4, y+height/2, x+width/2, y+height-3, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+width-4, y+height/2, x+width/2, y+2, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+width-4, y+height/2, x+width/2, y+height-3, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+5, y+height/2, x+width/2, y+2, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+5, y+height/2, x+width/2, y+height-3, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+width-5, y+height/2, x+width/2, y+2, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+width-5, y+height/2, x+width/2, y+height-3, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+6, y+height/2, x+width/2, y+2, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+6, y+height/2, x+width/2, y+height-3, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+width-6, y+height/2, x+width/2, y+2, 254, 223, 0, 255*a_multiplier)
client_draw_line(ctx, x+width-6, y+height/2, x+width/2, y+height-3, 254, 223, 0, 255*a_multiplier)
--center circle, drawn twice to make it appear sharperw
client_draw_circle(ctx, x+width/2, y+height/2, 0, 39, 118, 255*a_multiplier, 3, 0, 1)
client_draw_circle(ctx, x+width/2, y+height/2, 0, 39, 118, 255*a_multiplier, 3, 0, 1)
--stars
client_draw_rectangle(ctx, x+width/2+1, y+height/2+2, 1, 1, 255, 255, 255, 255*a_multiplier)
client_draw_rectangle(ctx, x+width/2-1, y+height/2+1, 1, 1, 255, 255, 255, 255*a_multiplier)
client_draw_rectangle(ctx, x+width/2+1, y+height/2, 1, 1, 255, 255, 255, 255*a_multiplier)
--outline - horizontal
client_draw_line(ctx, x-1, y, x+width, y, 16, 16, 16, 220*a_multiplier)
client_draw_line(ctx, x-1, y+height, x+width, y+height, 16, 16, 16, 220*a_multiplier)
--outline - vertical
client_draw_line(ctx, x, y, x, y+height, 16, 16, 16, 220*a_multiplier)
client_draw_line(ctx, x+width-1, y, x+width-1, y+height, 16, 16, 16, 220*a_multiplier)
end
local function truncate(text, max_length)
local max_length = max_length or 16
if string_len(text) < max_length then
return text
else
return string_sub(text, 1, max_length)
end
end
local function get_dormant_players(enemy_only, alive_only)
local enemy_only = enemy_only ~= nil and enemy_only or false
local alive_only = alive_only ~= nil and alive_only or true
local result = {}
local player_resource = entity_get_all("CCSPlayerResource")[1]
for player=1, globals_maxplayers() do
if entity_get_prop(player_resource, "m_bConnected", player) == 1 then
local local_player_team
if enemy_only then
local_player_team = entity_get_prop(entity_get_local_player(), "m_iTeamNum")
end
local is_enemy = true
if enemy_only and entity_get_prop(player, "m_iTeamNum") == local_player_team then
is_enemy = false
end
if is_enemy then
local is_alive = true
if alive_only and entity_get_prop(player_resource, "m_bAlive", player) ~= 1 then
is_alive = false
end
if is_alive then
table_insert(result, player)
end
end
end
end
return result
end
local function get_ping(player_resource, player)
return entity_get_prop(player_resource, string_format("%03d", player))
end
local function setMath(int, max, declspec)
local int = (int > max and max or int)
local tmp = max / int;
local i = (declspec / tmp)
i = (i >= 0 and math_floor(i + 0.5) or math_ceil(i - 0.5))
return i
end
local function getColor(number, max)
local r, g, b
i = setMath(number, max, 9)
if i <= 1 then r, g, b = 255, 0, 0
elseif i == 2 then r, g, b = 237, 27, 3
elseif i == 3 then r, g, b = 235, 63, 6
elseif i == 4 then r, g, b = 229, 104, 8
elseif i == 5 then r, g, b = 228, 126, 10
elseif i == 6 then r, g, b = 220, 169, 16
elseif i == 7 then r, g, b = 213, 201, 19
elseif i == 8 then r, g, b = 176, 205, 10
elseif i == 9 then r, g, b = 124, 195, 13
end
return r, g, b
end
local function on_enabled_changed()
local enabled = #ui_get(enabled_reference) > 0
ui_set_visible(maxping_reference, enabled)
end
ui.set_callback(enabled_reference, on_enabled_changed)
local function on_paint(ctx)
local enabled = ui_get(enabled_reference)
if #enabled == 0 then
return
end
local local_player = entity_get_local_player()
if local_player == nil or entity_get_prop(local_player, "m_lifeState") ~= 0 then
return
end
local players = get_dormant_players(true, true)
if #players == 0 then
return
end
local maxping = ui_get(maxping_reference)
local player_resource = entity_get_all("CCSPlayerResource")[1]
local players_matching = {}
local pings = {}
for i=1, #players do
local player = players[i]
local ping = get_ping(player_resource, player)
ping = math_min(ping, 999)
if maxping <= ping then
table_insert(players_matching, player)
end
pings[player] = ping
end
if #players_matching == 0 then
return
end
local r, g, b, a = ui_get(color_reference)
local width, height = client_screen_size()
local x = 10
local y = 600
local y_additional = 0
if contains(enabled, "Container") then
local height = 14 + #players_matching*12
local width = 136
draw_container(ctx, x, y, width, height)
for i=1, #players_matching do
local y_additional = (i-1)*12
local player = players_matching[i]
local name = entity_get_player_name(player)
name = truncate(name, 15)
local ping = pings[player]
client_draw_text(ctx, x + 10, y + 6 + y_additional, r, g, b, a, "", 0, name)
client_draw_gradient(ctx, x + 10 + (width-65), y + 6 + y_additional + 1, 12, 12, 20, 20, 20, 1, 20, 20, 20, 255, true)
client_draw_rectangle(ctx, x + 10 + (width-53), y + 6 + y_additional + 1, 35, 12, 20, 20, 20, 255)
local ping_r, ping_g, ping_b = getColor((999-ping)/999 - 0.2, 1)
client_draw_text(ctx, x + 10 + (width-20), y + 6 + y_additional, ping_r, ping_g, ping_b, a, "br", 0, ping, "ms")
end
end
if contains(enabled, "Above name") or contains(enabled, "Brazilian flag") then
for i=1, #players_matching do
local player = players_matching[i]
local ping = pings[player]
local name = entity_get_player_name(player)
local y_additional = name == "" and -8 or 0
local x1, y1, x2, y2, a_multiplier = entity_get_bounding_box(ctx, player)
if x1 ~= nil and a_multiplier > 0 then
if contains(enabled, "Above name") then
local x_center = x1 + (x2-x1)/2
local ping_r, ping_g, ping_b = getColor((999-ping)/999 - 0.2, 1)
if x_center ~= nil then
client_draw_text(ctx, x_center, y1-13+y_additional, ping_r, ping_g, ping_b, a*a_multiplier, "c-", 0, ping, " MS")
end
end
if contains(enabled, "Brazilian flag") then
local a_multiplier = a_multiplier
if 1 > a_multiplier then
a_multiplier = a_multiplier * 0.5
end
a_multiplier = a_multiplier * math_min(((ping)/400), 1)
draw_brazilian_flag(ctx, x2+2, y2-14, a_multiplier)
end
end
end
end
end
client.set_event_callback("paint", on_paint)