local add_checkbox, add_slider_float, get_convar = ui.add_checkbox, ui.add_slider_float, se.get_convar
local ui_get_bool, ui_get_float, register_callback = ui.get_bool, ui.get_float, client.register_callback
local get_index_by_userid, get_local_player = engine.get_player_for_user_id, engine.get_local_player
local get_realtime, execute_client_cmd = globalvars.get_real_time, engine.execute_client_cmd
add_checkbox("kill sound", "b_killsound", false)
add_slider_float("sound length", "fl_sound_length", 0.0, 20.0, 2.0)
local voice_inputfromfile = get_convar("voice_inputfromfile")
local voice_loopback = get_convar("voice_loopback")
local time = 0
local is_playing = false
local function event_listener(event)
if ui_get_bool("b_killsound") and event:get_name() == "player_death" then
local attacker = get_index_by_userid(event:get_int("attacker", 0))
local dead = get_index_by_userid(event:get_int("userid", 0))
local me = get_local_player()
if attacker == me and dead ~= me then
voice_inputfromfile:set_int(1)
execute_client_cmd("+voicerecord")
voice_loopback:set_int(1)
time = get_realtime() + ui_get_float("fl_sound_length")
is_playing = true
end
end
end
local function handler()
if time < get_realtime() and is_playing then
voice_inputfromfile:set_int(0)
execute_client_cmd("-voicerecord")
voice_loopback:set_int(0)
is_playing = false
end
end
register_callback("paint", handler)
register_callback("fire_game_event", event_listener)