English Specific sound for specific team on flag take

12 replies
Goto Page
To the start Previous 1 Next To the start
Up
SkullFace
User
Offline Off
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. )

Code:
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 :
Code:
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
IMG:http://steamsignature.com/status/default/76561198028496057.png
IMG:http://steamsignature.com/AddFriend.png
03.02.18 09:11:07 pm
Up
script favor
User
Offline Off
@user SkullFace:

Code:
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
Visit my website : https://bounty-mafia.tk , Discord : https://discord.gg/ntNd6TX, IMG:http://i60.tinypic.com/5kixc8.gif
03.02.18 09:12:33 pm
Up
Cure Pikachu
User
Offline Off
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:
Code:
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
IMG:https://i.imgur.com/5UWPaft.png
03.02.18 10:10:09 pm
Up
Waldin
User
Offline Off
user Cure Pikachu has written:
I got ninja'd, but I at least mentioned why it failed.


And at least your code works.
i was going to post my solution but i lost my internet connection
user Waldin (2014) has written:
can be create 3D option for tiles on 3D
user DC (2014) has written:
@user Waldin: This is a 2D game. there are no 3D tiles.
changelog (2017) has written:
ADDED Experimental 3D rendering mode
03.02.18 11:28:22 pm
Up
SkullFace
User
Offline Off
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.
Code:
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 :
Code:
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
IMG:http://steamsignature.com/status/default/76561198028496057.png
IMG:http://steamsignature.com/AddFriend.png
03.02.18 11:55:43 pm
Up
Waldin
User
Offline Off
try with my code i already tested it.
Code:
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
user Waldin (2014) has written:
can be create 3D option for tiles on 3D
user DC (2014) has written:
@user Waldin: This is a 2D game. there are no 3D tiles.
changelog (2017) has written:
ADDED Experimental 3D rendering mode
04.02.18 12:00:57 am
Up
Cure Pikachu
User
Offline Off
user Waldin has written:
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

I just noticed myself. Thanks!
IMG:https://i.imgur.com/5UWPaft.png
04.02.18 12:57:36 am
Up
SkullFace
User
Offline Off
@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
IMG:http://steamsignature.com/status/default/76561198028496057.png
IMG:http://steamsignature.com/AddFriend.png
04.02.18 01:22:42 am
Up
Waldin
User
Offline Off
Code:
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
user Waldin (2014) has written:
can be create 3D option for tiles on 3D
user DC (2014) has written:
@user Waldin: This is a 2D game. there are no 3D tiles.
changelog (2017) has written:
ADDED Experimental 3D rendering mode
04.02.18 03:18:57 pm
Up
SkullFace
User
Offline Off
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
IMG:http://steamsignature.com/status/default/76561198028496057.png
IMG:http://steamsignature.com/AddFriend.png
04.02.18 06:39:48 pm
Up
Waldin
User
Offline Off
Code:
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
user Waldin (2014) has written:
can be create 3D option for tiles on 3D
user DC (2014) has written:
@user Waldin: This is a 2D game. there are no 3D tiles.
changelog (2017) has written:
ADDED Experimental 3D rendering mode
04.02.18 09:47:40 pm
Up
SkullFace
User
Offline Off
@user Waldin: Works like a charm, thanks for solving this!
IMG:http://steamsignature.com/status/default/76561198028496057.png
IMG:http://steamsignature.com/AddFriend.png
05.02.18 12:31:58 pm
Up
script favor
User
Offline Off
@user SkullFace: Dude,my script isn't work ? cant you add your sounds !??
Visit my website : https://bounty-mafia.tk , Discord : https://discord.gg/ntNd6TX, IMG:http://i60.tinypic.com/5kixc8.gif
To the start Previous 1 Next To the start