forked from Syihabuddinsanni/gamesense-workshop-luas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VALORANT kill effects.lua
162 lines (128 loc) · 4.54 KB
/
VALORANT kill effects.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
-- VALORANT kill effects for Counter-Strike: Global Offensive, by nicole
-- Localized functions
local globals_realtime, globals_mapname = globals.realtime, globals.mapname
-- Libraries
local ffi = require "ffi"
local gif_decoder = require "gamesense/gif_decoder"
local http = require "gamesense/http"
-- Game definitions
local vftable_e =
{
surface =
{
playsound = 82
}
}
-- General enums
local http_status_code_e =
{
ok = 200
}
-- FFI
-- https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/public/vgui/ISurface.h#L272
local ISurface__PlaySound = vtable_bind("vguimatsurface.dll", "VGUI_Surface031", vftable_e.surface.playsound, "void (__thiscall*)(void* ecx, const char* sPath)")
-- Menu
local g_pMenuKillEffectsEnabled = ui.new_checkbox("VISUALS", "Effects", "VALORANT kill effects")
-- Constants
local ASSET_CDN = "https://aether.moe/gamesense"
local MAX_KILLS = 6
-- Globals
local g_nMissingFiles = 0
local g_nKills = 0
local g_flPlaybackStart = 0.0
local g_flPlayUntil = 0.0
local g_aBanners = nil
local g_anDisplayAtX = nil
local g_anDisplayAtY = nil
function on_player_death(e)
local nLocalPlayer = entity.get_local_player()
if client.userid_to_entindex(e.attacker) ~= nLocalPlayer or e.attacker == e.userid or g_nKills >= MAX_KILLS then
return
end
g_nKills = g_nKills + 1
-- Plays the sound
ISurface__PlaySound(string.format("valorant_%d.wav", g_nKills))
-- Displays the kill banner
g_flPlaybackStart = globals.realtime()
g_flPlayUntil = g_flPlaybackStart + g_aBanners[g_nKills].duration
-- Specify where to play the kill banner
g_anDisplayAtX, g_anDisplayAtY = client.screen_size()
g_anDisplayAtX = g_anDisplayAtX / 2 -- Center
g_anDisplayAtX = g_anDisplayAtX - g_aBanners[g_nKills].width / 2
g_anDisplayAtY = g_anDisplayAtY * 0.9 -- 90%-ish of screen height
g_anDisplayAtY = g_anDisplayAtY - g_aBanners[g_nKills].height
end
function on_player_spawn(e)
local nLocalPlayer = entity.get_local_player()
if client.userid_to_entindex(e.userid) ~= nLocalPlayer then
return
end
reset_vars()
end
function on_paint_ui()
local flRealTime = globals_realtime()
if flRealTime < g_flPlayUntil and globals_mapname() ~= nil then
local pBanner = g_aBanners[g_nKills]
pBanner:draw(flRealTime - g_flPlaybackStart, g_anDisplayAtX, g_anDisplayAtY, pBanner.width, pBanner.height, 255, 255, 255, 255)
end
end
function reset_vars()
g_nKills = 0
g_flPlaybackStart = 0.0
g_flPlayUntil = 0.0
end
function set_callbacks(enable)
local pFunc = enable and client.set_event_callback or client.unset_event_callback
pFunc("player_death", on_player_death)
pFunc("player_spawn", on_player_spawn)
pFunc("paint_ui", on_paint_ui)
if enable and g_aBanners == nil then
if not load_files() then
g_aBanners = nil
ui.set(g_pMenuKillEffectsEnabled, false)
client.error_log("Some assets could not be found. Attempting to retrieve them...")
else
client.log("VALORANT assets loaded.")
end
end
end
function on_menu_kill_effects_enabled_callback(ref)
set_callbacks(ui.get(ref))
end
function download_file(path)
http.get(string.format("%s/%s", ASSET_CDN, path), function(success, response)
if not success or response.status ~= http_status_code_e.ok then
client.error_log(string.format("Could not retrieve asset \"%s\" from server. Error code: %d", path, response.status))
return
end
writefile(path, response.body)
g_nMissingFiles = g_nMissingFiles - 1
client.log(string.format("Successfully installed asset at path \"%s\".", path))
-- Finished downloading everything, re-enable the checkbox for a smooth first-time installation..
if g_nMissingFiles == 0 then
client.log("VALORANT assets downloaded. Loading them.. this might take a while.")
client.delay_call(globals.tickinterval(), ui.set, g_pMenuKillEffectsEnabled, true)
end
end)
end
function check_and_download(path)
if not readfile(path) then
g_nMissingFiles = g_nMissingFiles + 1
download_file(path)
end
end
function load_files()
g_aBanners = {}
g_nMissingFiles = 0
for i = 1, MAX_KILLS do
check_and_download(string.format("csgo/sound/valorant_%d.wav", i))
check_and_download(string.format("csgo/materials/valorant_%d.gif", i))
end
if g_nMissingFiles == 0 then
for i = 1, MAX_KILLS do
g_aBanners[i] = gif_decoder.load_gif(readfile(string.format("csgo/materials/valorant_%d.gif", i)))
end
end
return g_nMissingFiles == 0
end
ui.set_callback(g_pMenuKillEffectsEnabled, on_menu_kill_effects_enabled_callback)