Sure.
Code:
death_sounds = {
[Player.kScout] = "customsound.scout",
[Player.kSniper] = "customsound.sniper",
[Player.kSoldier] = "customsound.soldier",
[Player.kDemoman] = "customsound.demoman",
[Player.kMedic] = "customsound.medic",
[Player.kHwguy] = "customsound.hwguy",
[Player.kPyro] = "customsound.pyro",
[Player.kSpy] = "customsound.spy",
[Player.kEngineer] = "customsound.engineer",
[Player.kCivilian] = "customsound.civilian"
}
-- sounds need to be precached
function precache()
-- precache each sound in the table
for class_id,death_sound in pairs(death_sounds) do
PrecacheSound( death_sound )
end
end
function player_killed( player, damageinfo )
-- could test various things about the death here
-- and then only play the sound depending on certain conditions
local death_sound = death_sounds[ player:GetClass() ]
-- emit sound from the dying player
-- EmitSound will play a sound from a sound script
-- (you can write a <mapname>_level_sounds.txt
-- in the maps folder if you want a custom sound I think,
-- see ff_waterpolo_level_sounds.txt)
player:EmitSound( death_sound )
end
You can also use soundscripts to randomly choose between a number of different sounds, like so (taken from scripts/game_sounds_ff_player.txt):
Code:
"Player.Pain"
{
"channel" "CHAN_VOICE"
"volume" "1.0"
"CompatibilityAttenuation" "1.0"
"rndwave"
{
"wave" "player/pain1.wav"
"wave" "player/pain2.wav"
"wave" "player/pain3.wav"
"wave" "player/pain4.wav"
"wave" "player/pain5.wav"
"wave" "player/pain6.wav"
"wave" "player/pain7.wav"
"wave" "player/pain8.wav"
}
}
That will use one of pain1-pain8.wav each time Player.Pain is played.