ui.Checkbox("kill sound", "b_killsound", false)
ui.SliderFloat("sound length", "fl_sound_length", 0.0, 20.0, 2.0)
local voice_inputfromfile = client.GetConvar("voice_inputfromfile")
local voice_loopback = client.GetConvar("voice_loopback")
local time = 0
local is_playing = false
local function event_listener(event)
if ui.GetBool("b_killsound") and event:GetName() == "player_death" then
local attacker = engine.GetPlayerIndexByUserID(event:GetInt("attacker", 0))
local dead = engine.GetPlayerIndexByUserID(event:GetInt("userid", 0))
local me = engine.GetLocalPlayer()
if attacker == me and dead ~= me then
voice_inputfromfile:SetInt(1)
engine.ExecuteClientCmd("+voicerecord")
voice_loopback:SetInt(1)
time = globalvars.GetRealTime() + ui.GetFloat("fl_sound_length")
is_playing = true
end
end
end
local function handler()
if time < globalvars.GetRealTime() and is_playing then
voice_inputfromfile:SetInt(0)
engine.ExecuteClientCmd("-voicerecord")
voice_loopback:SetInt(0)
is_playing = false
end
end
client.RegisterCallback("Paint", handler)
client.RegisterCallback("FireGameEvent", event_listener)