Forum

> > CS2D > Scripts > Specific sound for specific team on flag take
Forums overviewCS2D overview Scripts overviewLog in to reply

English Specific sound for specific team on flag take

12 replies
To the start Previous 1 Next To the start

old Specific sound for specific team on flag take

Casper-
User Off Offline

Quote
I need help with this one.
I've been trying to make a script where when you capture a flag,
it would say : "Our flag has been taken"
and for the enemy it would say : "Enemy flag taken"

So this is what I've made. (And failed ofc. )

1
2
3
4
5
6
7
8
9
10
11
addhook("flagtake","on_flag_take")
	function on_flag_take(id,team,x,y)
	
	if player(id,"team") == 1 then
	parse("sv_sound2 "..player(id,"team1").." Neva_FlagHasBeenTak.wav ")
	parse("sv_sound2 "..player(id,"team2").." Geva_FlagHasBeenTak.wav ")
	elseif player(id,"team") == 2 then
	parse("sv_sound2 "..player(id,"team1").." Neva_FlagHasBeenTak.wav ")
	parse("sv_sound2 "..player(id,"team2").." Geva_FlagHasBeenTak.wav ")
end
end

I've checked console for what it says and got this :
1
2
3
LUA ERROR: sys/lua/autorun/TEST.lua:154: attempt to concatenate a boolean value
-> sys/lua/autorun/TEST.lua:154: in function <sys/lua/autorun/TEST.lua:148>
-> in Lua hook 'flagtake', params: 1, 2, 3
edited 1×, last 03.02.18 09:04:44 pm

old Re: Specific sound for specific team on flag take

script favor
User Off Offline

Quote
@user Casper-:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("flagtake","on_flag_take")
     function on_flag_take(id,team,x,y)
     if player(id,"team") == 1 and player(id,"x") and player(id,"y") then
	 	 msg("work t")
		 local t = player(id,"team")
     parse("sv_sound2 "..t.." Neva_FlagHasBeenTak.wav ")
     parse("sv_sound2 "..t.." Geva_FlagHasBeenTak.wav ")
     elseif player(id,"team") == 2 and player(id,"x") and player(id,"y") then		
	 msg("work ct")
	 local t = player(id,"team")
     parse("sv_sound2 "..t.." Neva_FlagHasBeenTak.wav ")
     parse("sv_sound2 "..t.." Geva_FlagHasBeenTak.wav ")
end
end

old Re: Specific sound for specific team on flag take

Cure Pikachu
User Off Offline

Quote
Because
player(id,"team1")
and
player(id,"team2")
are tables (Though it's supposed to be
player(0,"team1")
and
player(0,"team2")
respectively). The parameter in cs2d cmd sv_sound2 calls for an integer, so yeah. You'll need to do some looping, like:
1
2
3
4
5
6
7
8
9
10
addhook("flagtake","on_flag_take")
function on_flag_take(id,team,x,y)
	for _, i in ipairs(player(0,"table")) do
		if player(i,"team") == 1 then
			parse("sv_sound2 "..i.." Neva_FlagHasBeenTak.wav")
		elseif player(i,"team") > 1 then
			parse("sv_sound2 "..i.." Geva_FlagHasBeenTak.wav")
		end
	end
end
I got ninja'd, but I at least mentioned why it failed.
edited 2×, last 04.02.18 12:02:15 am

old Re: Specific sound for specific team on flag take

Casper-
User Off Offline

Quote
Thanks for the help everyone, I unfortunately don't have too high level of lua knowledge, so I'm stuck here.

@user script favor: Your script works but for some odd reason (that I've met before) doesn't load the sound for ct. It says 'work ct' but doesnt load the sound. While for tt, it says 'work t' + loads the sound. Both .wav files are in the same folder (sfx folder).
This is what I tried to fix that sound loading.
1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("flagtake","on_flag_take")
function on_flag_take(id,team,x,y)
	if player(id,"team") == 1 and player(id,"x") and player(id,"y") then
		msg("work t")
		local t = player(id,"team")
		parse("sv_sound2 "..t.." \"Neva_FlagHasBeenTak.wav\" ")
		
	elseif player(id,"team") == 2 and player(id,"x") and player(id,"y") then          
		msg("work ct")
		local b = player(id,"team")
		parse("sv_sound2 "..b.." \"Geva_FlagHasBeenTak.wav\" ")
end
end

My goal is that Terrorists have 1 voice announcer and CTs have a different voice announcer that differs from Terrorists. It feels very complex atm.

@user Cure Pikachu: Your script didn't work for me. I've read the console and seems like I need to add more lines or tables (which I don't know about, alot)
This was the result in console :
1
2
3
4
LUA ERROR : sys/lua/autorun/TEST.lua:190:bad argument #1 to 'ipairs' (table expected, got boolean)
-> [C]: in function 'ipairs'
-> sys/lua/autorun/TEST.lua:190: in function <sys/lua/autorun/TEST.lua:189>
-> in Luka hook 'flagtake', params: 1, 2, 3

old Re: Specific sound for specific team on flag take

Waldin
User Off Offline

Quote
try with my code i already tested it.
1
2
3
4
5
6
7
8
9
addhook("flagtake", "on_flag_take")
function on_flag_take(id, team, x, y)
	for _, id in ipairs(player(0, "team"..team)) do
		parse("sv_sound2 "..id.." Neva_FlagHasBeenTak.wav ")
	end
	for _, id in ipairs(player(0, "team"..(team == 1 and 2 or 1))) do
		parse("sv_sound2 "..id.." Geva_FlagHasBeenTak.wav ")
	end
end

also user script favor's code will not work. its calling the win sound to id
player(id, "team")
that is the number of player team (1 for terrorist) so playing sound to id 1.

Also for user Cure Pikachu's code, when calling for a table with all players the id should be 0
player(0, "table")
so you can replace it in line 190

old Re: Specific sound for specific team on flag take

Casper-
User Off Offline

Quote
@user Waldin: Thanks Waldin for the effort.

I've tried your script aswell but it triggers for both flags same sfx.
The other 'geva' line was never triggered.
What I want is that 1 team has their own announcer when their team has taken the flag or lost the flag.
And other team to have a different announcer when their team has taken the flag or lost the flag.

I know that
for
is the loop, but what is
_
?
I'm not familiar with this part.

Here are the sfx if you wanna test them.

So in short, if a player 1 is in T team, he hears the male version and if a player 2 is in CT team, he hears the female version

old Re: Specific sound for specific team on flag take

Waldin
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
addhook("flagtake", "on_flag_take")
function on_flag_take(id, team, x, y)
	local ct_sound = "Geva_FlagHasBeenTak.wav"
	local t_sound = "Neva_FlagHasBeenTak.wav"

	team = team == 1 and 2 or 1

	local playedsound = team == 1 and t_sound or ct_sound

	local teamstring = "team"..team

	for _, id in ipairs(player(0, teamstring)) do
		parse("sv_sound2 "..id.." "..playedsound)
	end
end
Okay i'll explain you so read carefully. team will be a number which is 1 if the player that captured the flag is terrorist, or counter terrorists otherwise. I inverted it so we play the sound to the enemy team
so in playedsound we are checking if team is 1 (terrorist) playedsound will be t_sound (the sound played for terrorists), otherwise it will be ct_sound (the sound played for counter terrorists). We will play this sound for each player on the same team.

teamstring is used to call player function team1 for terrorist or team2 for counter terrorists. now we iterate over the team that we want to play the sound. i defined first value _ because we dont need it, but it would be the index of the player in the table returned by player(0, teamstring). we play the sound for every player and all happy

old Re: Specific sound for specific team on flag take

Casper-
User Off Offline

Quote
So finally, this was my result that I've wanted.
Spoiler >


But now I wanted to add 2 more files.
So now, when your flag was taken, you and your team (lets say CT) would be notified "The enemy has our flag" and the enemy (terrorists) would be notified "We have their flag."
And vice versa.
I've tried this and failed :


Spoiler >


Spoiler >


Spoiler >


Spoiler >
edited 1×, last 04.02.18 04:28:24 pm

old Re: Specific sound for specific team on flag take

Waldin
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
addhook("flagtake", "on_flag_take")
function on_flag_take(id, team, x, y)
	local ct_sound1 = "Geva_FlagHasBeenTak.wav"
	local ct_sound2 = "Geva_EnemyHasFlag.ogg"
	local t_sound1 = "Neva_FlagHasBeenTak.wav"
	local t_sound2 = "Neva_EnemyHasFlag.ogg"

	local teamstring = "team"..team
	local playedsound = team == 1 and t_sound1 or ct_sound1
	for _, id in ipairs(player(0, teamstring)) do
		parse("sv_sound2 "..id.." "..playedsound)
	end

	teamstring = "team"..(3 - team)
	playedsound = team == 1 and ct_sound2 or t_sound2
	for _, id in ipairs(player(0, teamstring)) do
		parse("sv_sound2 "..id.." "..playedsound)
	end
end

This plays the captured flag (c/t_sound1) to the team that captured the flag and the flah has been taken (c/t_sound2) to the team that its flag has been taken
edited 1×, last 04.02.18 07:18:18 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview