forked from sapphyrus/gamesense-lua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recoil_crosshair.lua
105 lines (81 loc) · 6.95 KB
/
recoil_crosshair.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
--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_combobox("VISUALS", "Other ESP", "Recoil crosshair", {"Off", "Dot", "Circle"})
local color_reference = ui.new_color_picker("VISUALS", "Other ESP", "Recoil crosshair", 255, 178, 0, 255)
local aimpoint_distance = 10000
--local yaw_prev, pitch_prev = 0, 0
local function lerp(v1, v2, percentage)
return (1-percentage)*v1 + percentage*v2 -- Linear Interpolation
end
local function distance(x1, y1, x2, y2)
return math_sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
end
local function on_paint(ctx)
local enabled = ui_get(enabled_reference)
if enabled == "Off" then
return
end
local local_player = entity_get_local_player()
local r, g, b, a = ui_get(color_reference)
local aim_punch_angle_pitch, aim_punch_angle_yaw = entity_get_prop(local_player, "m_aimPunchAngle")
--local view_punch_angle_pitch, view_punch_angle_yaw = entity_get_prop(local_player, "m_viewPunchAngle")
local weapon = entity_get_player_weapon(local_player)
local weapon_name = entity_get_classname(weapon)
--ghetto fix to not show recoil crosshair for snipers
if weapon_name == "CWeaponAWP" or weapon_name == "CWeaponSSG08" then
return
end
if entity_get_prop(weapon, "m_flRecoilIndex") == 0 then
return
end
local x, y, z = entity_get_prop(local_player, "m_vecAbsOrigin")
z = z + entity_get_prop(local_player, "m_vecViewOffset[2]")
local pitch, yaw = client_camera_angles()
local aim_punch_angle_pitch, aim_punch_angle_yaw = entity_get_prop(local_player, "m_aimPunchAngle")
if -aim_punch_angle_pitch >= 0.05 and -aim_punch_angle_pitch >= 0.05 then
--aim_punch_angle_pitch = 0
--aim_punch_angle_yaw = 0
local a_multiplier = 1
local recoil_amount = distance(0, 0, math_abs(aim_punch_angle_pitch), math_abs(aim_punch_angle_yaw))
if recoil_amount+0.2 < 0.8 then
a_multiplier = math_max(0, recoil_amount / 0.8 - 0.2)
end
local recoil_scale = client_get_cvar("weapon_recoil_scale")
aim_punch_angle_pitch = aim_punch_angle_pitch*recoil_scale
aim_punch_angle_yaw = aim_punch_angle_yaw*recoil_scale
yaw = yaw - 180
yaw = math_rad(yaw+aim_punch_angle_yaw)
pitch = math_rad(pitch+aim_punch_angle_pitch)
--yaw, pitch = lerp(yaw, yaw_prev, 0.5), lerp(pitch, pitch_prev, 0.5)
local xTarget = x - math_cos(yaw) * aimpoint_distance
local yTarget = y - math_sin(yaw) * aimpoint_distance
local zTarget = z - math_tan(pitch) * aimpoint_distance
local wx, wy = client_world_to_screen(ctx, xTarget, yTarget, zTarget)
if wx ~= nil then
if enabled == "Dot" then
client_draw_rectangle(ctx, wx-2, wy-2, 4, 4, r, g, b, a*a_multiplier*0.2)
client_draw_rectangle(ctx, wx-1, wy-1, 2, 2, r, g, b, a*a_multiplier)
elseif enabled == "Circle" then
client_draw_circle_outline(ctx, wx, wy, r, g, b, a*a_multiplier, 5, 0, 1, 1)
client_draw_circle_outline(ctx, wx, wy, r, g, b, a*a_multiplier*0.2, 4, 0, 1, 1)
client_draw_circle_outline(ctx, wx, wy, r, g, b, a*a_multiplier*0.1, 3, 0, 1, 1)
client_draw_circle_outline(ctx, wx, wy, r, g, b, a*a_multiplier*0.05, 6, 0, 1, 1)
end
end
--if math_abs(yaw-yaw_prev) > 0.002 and math_abs(pitch-pitch_prev) > 0.002 then
-- yaw_prev, pitch_prev = yaw, pitch
--end
end
end
client.set_event_callback("paint", on_paint)