Fortress Forever

Go Back   Fortress Forever > Editing > Mapping > Lua

Reply
 
Thread Tools Display Modes
Old 05-21-2013, 11:10 PM   #1
Headz
 
Headz's Avatar
 
Join Date: Mar 2013
Location: England
Posts Rated Helpful 81 Times
Help with 'On Player Death' trigger sound

Trying to make it so when player dies a custom sound plays local to death area, tried using input/output system with ambient_generic set to play local to entity ( teamspawn ) and nothing happens, is there a work around in lua for this, a bonus would be different sounds played depending what class dies.

Almost finished my ctf map called Pilkington just need this last bit to work and ready to go, many thanks if anyone can help.
Headz is offline   Reply With Quote


1 members found this post helpful.
Old 05-22-2013, 09:06 PM   #2
ddm999
worst ff player eu
 
Join Date: Jun 2012
Location: South Yorks., England
Class/Position: o - no, d - scout
Gametype: IvDZ
Posts Rated Helpful 18 Times
There will be a way to do this using the base code used in locations (if your map uses locations, it'll be easier to implement), and the function player_killed, but unfortunately I just don't have the time. Sorry. D:

Someone can help you though (prolly squeek knowing just how helpful he always is ;D).
__________________
gg ff not ded
ff very much alive
ddm999 is offline   Reply With Quote


1 members found this post helpful.
Old 05-26-2013, 11:41 AM   #3
Headz
 
Headz's Avatar
 
Join Date: Mar 2013
Location: England
Posts Rated Helpful 81 Times
No worries, its been a right ball ache, would be nice to have though.
Headz is offline   Reply With Quote


Old 05-26-2013, 12:59 PM   #4
squeek.
Stuff Do-er
Lua Team
Wiki Team
Fortress Forever Staff
 
squeek.'s Avatar
 
Join Date: Mar 2007
Location: Northern California
Class/Position: Rallygun Shooter
Gametype: Conc tag (you just wait)
Affiliations: Mustache Brigade
Posts Rated Helpful 348 Times
Send a message via AIM to squeek.
It's possible using Lua for sure.

Either something like (I forget if this works right):
Code:
local death_sound = "soundname"

-- sounds need to be precached
function precache()
	PrecacheSound( death_sound )
end

function player_killed( player, damageinfo )
	-- could test various things about the death here 
	-- and then only play the sound depending on certain conditions

	-- 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
or something like (no clue if this would actually work, haven't moved sound entities before):
Code:
function player_killed( player, damageinfo )
	-- could test various things about the death here 
	-- and then only play the sound depending on certain conditions

	-- teleport the entity (like an ambient_generic or w/e) 
	-- with the given name to the location of the death 
	-- and then trigger it to play its sound
	local sound_ent_name = "entity_name"
	local deathpos = player:GetOrigin()
	local sound_ent = GetEntityByName( sound_ent_name )
	sound_ent:SetOrigin( deathpos.x, deathpos.y, deathpos.z )
	OutputEvent(sound_ent_name, "PlaySound")
end
The second method might get somewhat weird when multiple people are dying in rapid succession in different places around the map (the entity would be teleporting all around, I'm not sure how it'd sound).

Both are completely untested.
__________________
Support FF:
#FF.Pickup Fortress-Forever pickups

My Non-official Maps
Released FF_DM_Squeek - FF_2Mesa3_Classic - FF_Siege_Classic
Beta FF_Myth - FF_Redlight_Greenlight

Sick of the people on the internet, always moanin'. They just moan.
- Karl Pilkington

Last edited by squeek.; 05-26-2013 at 01:01 PM.
squeek. is offline   Reply With Quote


Old 05-26-2013, 05:38 PM   #5
Headz
 
Headz's Avatar
 
Join Date: Mar 2013
Location: England
Posts Rated Helpful 81 Times
Thanks Squeek for info

first one diden't work
and 2nd gave me this error in console

[SCRIPT] Error calling player_killed ([string "maps\pilkingtonbeta.lua"]:305: attempt to index local 'sound_ent' (a nil value)) ent: NULL

also tried level_sounds.txt
Headz is offline   Reply With Quote


Old 05-26-2013, 10:25 PM   #6
squeek.
Stuff Do-er
Lua Team
Wiki Team
Fortress Forever Staff
 
squeek.'s Avatar
 
Join Date: Mar 2007
Location: Northern California
Class/Position: Rallygun Shooter
Gametype: Conc tag (you just wait)
Affiliations: Mustache Brigade
Posts Rated Helpful 348 Times
Send a message via AIM to squeek.
First one should work.

Here's what I'm using:

maps/<mapname>_level_sounds.txt
Code:
"customsound.test"
{
	"channel"	"CHAN_STATIC"
	"volume"		"1.0"
	"CompatibilityAttenuation"	"0.8"
	"wave"		"player/scream1.wav"
}
maps/<mapname>.lua
Code:
local death_sound = "customsound.test"

-- sounds need to be precached
function precache()
	PrecacheSound( death_sound )
end

function player_killed( player, damageinfo )
	-- could test various things about the death here 
	-- and then only play the sound depending on certain conditions

	-- 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 learn more about soundscripts here: https://developer.valvesoftware.com/wiki/Soundscripts
__________________
Support FF:
#FF.Pickup Fortress-Forever pickups

My Non-official Maps
Released FF_DM_Squeek - FF_2Mesa3_Classic - FF_Siege_Classic
Beta FF_Myth - FF_Redlight_Greenlight

Sick of the people on the internet, always moanin'. They just moan.
- Karl Pilkington
squeek. is offline   Reply With Quote


1 members found this post helpful.
Old 05-27-2013, 10:33 PM   #7
Headz
 
Headz's Avatar
 
Join Date: Mar 2013
Location: England
Posts Rated Helpful 81 Times
Perfect, works a treat and local to area, thanks a lot Squeek, any chance of writing a script for class specific death sounds, want to avoid too much repetition with just 1 sound, cheers
Headz is offline   Reply With Quote


Old 05-28-2013, 04:40 AM   #8
squeek.
Stuff Do-er
Lua Team
Wiki Team
Fortress Forever Staff
 
squeek.'s Avatar
 
Join Date: Mar 2007
Location: Northern California
Class/Position: Rallygun Shooter
Gametype: Conc tag (you just wait)
Affiliations: Mustache Brigade
Posts Rated Helpful 348 Times
Send a message via AIM to squeek.
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.
__________________
Support FF:
#FF.Pickup Fortress-Forever pickups

My Non-official Maps
Released FF_DM_Squeek - FF_2Mesa3_Classic - FF_Siege_Classic
Beta FF_Myth - FF_Redlight_Greenlight

Sick of the people on the internet, always moanin'. They just moan.
- Karl Pilkington
squeek. is offline   Reply With Quote


1 members found this post helpful.
Old 05-28-2013, 02:23 PM   #9
Headz
 
Headz's Avatar
 
Join Date: Mar 2013
Location: England
Posts Rated Helpful 81 Times
excellent, just tried them and I prefer the random script, works very well, many thanks
Headz is offline   Reply With Quote


Old 05-28-2013, 09:48 PM   #10
squeek.
Stuff Do-er
Lua Team
Wiki Team
Fortress Forever Staff
 
squeek.'s Avatar
 
Join Date: Mar 2007
Location: Northern California
Class/Position: Rallygun Shooter
Gametype: Conc tag (you just wait)
Affiliations: Mustache Brigade
Posts Rated Helpful 348 Times
Send a message via AIM to squeek.
Once you get the map ready, make sure to test it on a dedicated server to make sure the sounds still work. You either need to pakrat the custom sounds into the BSP or include the sound files themselves in the download (in the correct directory structure). I forget now exactly what I did, but in 2mesa3_classic, I forgot to include the alarm bell sound so the help button doesn't play anything. It worked when I tested on a listen server but it stopped working on a dedicated server.
__________________
Support FF:
#FF.Pickup Fortress-Forever pickups

My Non-official Maps
Released FF_DM_Squeek - FF_2Mesa3_Classic - FF_Siege_Classic
Beta FF_Myth - FF_Redlight_Greenlight

Sick of the people on the internet, always moanin'. They just moan.
- Karl Pilkington
squeek. is offline   Reply With Quote


Old 05-28-2013, 10:32 PM   #11
Headz
 
Headz's Avatar
 
Join Date: Mar 2013
Location: England
Posts Rated Helpful 81 Times
yep random sounds dont work when someone else kills you unless they use sniper rifle or emp, worked when killed self, so had to use the class specific sounds and that works fine on dedicated server.

Used to be a bug in tfc for rotating ents, and moving ring lazers, worked fine on listen but not on dedicated, set up a quick srcds just to make sure, ty for helps

I used pakrat to make sure sounds get precached with ents in map non active, also included them in sounds folder with .res etc just to make sure, but I did find sound.txt is server side so all good, should be ok for fast url dl if files been uploaded properly.

Might use this tut for pilk head, see how it goes, and make a low poly one, and maybe a gervais one.


I learn something every time a make a new map, its never ending
Headz is offline   Reply With Quote


Reply

Tags
lua help


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:22 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.