UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

help making this sound script better!

broken avatar :(
Created 9 years ago
by thezombieproject
0 Members and 1 Guest are viewing this topic.
1,691 views
broken avatar :(
×
broken avatar :(
Location: usNUKETOWN
Date Registered: 19 February 2014
Last active: 7 years ago
Posts
177
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
My Contact & Social Links
More
Personal Quote
Zombie Specialist
Signature
×
thezombieproject's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Oil Rig Beta Access
Oil Rig Beta Access
 Ive been messing around with scripting lately and decided to try something kinda easy. I know there are tuts out there for something like this but im trying to make some of my own scripts for scripting practice and to better understand scripting.   I attempted to make a script so when players are touching a trigger multiple/radius it plays a custom loop sound. This script works but I am still learning when it comes to scripting so can someone please explain to me...

1. why with my code the loop sound stops when i throw a nade or switch weapons while in the trigger multiple?

2. How can i  make this script better? I know there is a better way of doing this. If i wanted to add another sound i would have to copy the code.


Code Snippet
Plaintext
main()
{


playsound = getEntArray( "playsound", "targetname" );
for( i = 0; i < playsound.size; i++ )
{
playsound[i] thread play_loop_sound();
}
}


play_loop_sound()
{
while( 1 )
{
players = get_players();
player_touching = false;
for( i = 0; i < players.size; i++ )
{
if( players[i] isTouching( self ) )
{
player_touching = true;
players[i] playLoopSound( "tzp_generator_loop" ); // name of sound
while( player_touching )
{
if( !players[i] isTouching( self ) )
{
players[i] StopLoopSound();
player_touching = false;
break;
}
wait( 0.5 );
}
}
}
wait( 0.5 );
}
}
Last Edit: July 17, 2015, 09:43:59 pm by thezombieproject
Marked as best answer by thezombieproject 9 years ago
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 14 September 2013
Last active: 4 years ago
Posts
1,895
Respect
Forum Rank
Zombie Destroyer
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
BE ORIGINAL
Signature
×
MakeCents's Groups
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
I think its cause you are playing the sound from the player. You may be able to get away with playlocalsound or playsound(sound,origin), or spawn an ent, link it to player, and playloopsound from that. But I am not the export on sounds. I just try things till it works. But I do know there is a difference in behavior between those three functions.

Depending on how you resolve your sound issue, depends on the solution for your function then, but... here are a few things: (as always, a bunch of ways to do it)
 - Your method is to constantly check if the player is touching something. You could just use triggers and waittill("trigger", player); in your while loop, and not need the players for loop then.
 - player_touching isn't needed, its redundant to the check
 - Since it is thread per trigger, you don't want that while loop in the while loop, you'll want to thread another function based on an if condition. The if will be a player var prob to check if they were already touching so they don't constantly run the other function when they are touching. similar to the player_touching you used, but for the player.
(The while loop in the while loop will stop, or pause, that function per ent while the second while loop is true, that is why you want to thread another function rather than another while loop.)
 - When you make a new function, passing the player var, this:

Code Snippet
Plaintext
				while( player_touching )
{
if( !players[i] isTouching( self ) )
{
players[i] StopLoopSound();
player_touching = false;
break;
}
wait( 0.5 );
will become this:
Code Snippet
Plaintext
//replace that while loop with self thread TouchingMe(player);
TouchingMe(player){
        player endon("disconnect");
while( player isTouching( self ) )
{
wait( 0.5 );
}
player StopLoopSound();
}

As far as using multiple sounds, you could add a kvp script_sound to your trig and then use that in your script instead, self.script_sound.

Of course, this all changes once you figure out your sound issue. You could always just play the sound from the trigger origin too, unless you need it to follow the player around.
Last Edit: July 17, 2015, 03:36:58 pm by MakeCents
broken avatar :(
×
broken avatar :(
Location: usNUKETOWN
Date Registered: 19 February 2014
Last active: 7 years ago
Posts
177
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
My Contact & Social Links
More
Personal Quote
Zombie Specialist
×
thezombieproject's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Oil Rig Beta Access
Oil Rig Beta Access
+1 for you :)!!! thanks for explaining that, i went in and changed a few things u pointed out and i remade the script. I tried doing it several different ways but i kept having that issue with the nades. I made it so only when the player is standing in the trigger multiiple it constantly checks if the player is touching something instead of before where it was always checking. Doing that  fixed the sound shutting off issue when i use a  nade or switch weapons:). Im not sure if thats the best way but it worked nicely. 

I didnt even think of using script_sound  till u mentioned it. Scripting, one big learning process. Thanks again the help. 
Last Edit: July 18, 2015, 03:20:53 am by thezombieproject
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 4 years ago
Posts
6,877
Respect
1,004Add +1
Forum Rank
Immortal
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Signature
If you want scripts / features made for you, then contact me by PM or email / skype etc
it will cost you tho so if you have no intention of reciprocating don't even waste my time ;)
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social Links[email protected]HarryBo21HarryBo000
Yeah hes right, buried somewhere deep in the cod code that im yet to find is a stopLoopedSound() on player ( by the sounds of it - in the grenade throw function )

this is probably used for cleaning up left over sounds, i guess they never wanted us to use "player" for sounds directly ( This is why my craftables sounds stopped working once, took me ages to work out why coz "just coz" wasnt acceptable lol )
Last Edit: July 18, 2015, 08:05:31 pm by Harry Bo21
broken avatar :(
×
broken avatar :(
Location: usNUKETOWN
Date Registered: 19 February 2014
Last active: 7 years ago
Posts
177
Respect
Forum Rank
Pack-a-Puncher
Primary Group
Donator ♥
My Groups
More
My Contact & Social Links
More
Personal Quote
Zombie Specialist
×
thezombieproject's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Oil Rig Beta Access
Oil Rig Beta Access
Yeah hes right, buried somewhere deep in the cod code that im yet to find is a stopLoopedSound() on player ( by the sounds of it - in the grenade throw function )

this is probably used for cleaning up left over sounds, i guess they never wanted us to use "player" for sounds directly ( This is why my craftables sounds stopped working once, took me ages to work out why coz "just coz" wasnt acceptable lol )

i remade the script so it doesn't loop constantly anymore and to fix that issue with nades and switching weapons i...

 instead of
players playLoopSound( "tzp_generator_loop" );

 i added,
sound = spawn("script_origin", self.origin);
 mysounds(sound);

then to stop the sound,
sound StopLoopSound();

with what im trying to do thats the only way i got it to work without bugs
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 4 years ago
Posts
6,877
Respect
1,004Add +1
Forum Rank
Immortal
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social Links[email protected]HarryBo21HarryBo000
lol - yes thats exactly what make cents suggested lol scratch that - getting really mixed up on my posts today apparently

Make sure your deleting the ent you create after the sound is finished

I dont see why you need it to only play when your there though? Have it play constantly and reduce the radius it can be heard from

Exact same effect, youll only be able to hear it when you get close, no need for triggers or functions and can use playsoundatposition()
Last Edit: July 19, 2015, 02:58:46 am by Harry Bo21
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 14 September 2013
Last active: 4 years ago
Posts
1,895
Respect
Forum Rank
Zombie Destroyer
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
BE ORIGINAL
×
MakeCents's Groups
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
i remade the script so it doesn't loop constantly anymore and to fix that issue with nades and switching weapons i...

 instead of
players playLoopSound( "tzp_generator_loop" );

 i added,
sound = spawn("script_origin", self.origin);
 mysounds(sound);

then to stop the sound,
sound StopLoopSound();

with what im trying to do thats the only way i got it to work without bugs

That's good, you may want to also linkto the player but definitely delete it after you are done. Otherwise you could just use a function with a loop with PlaySoundAtPosition(sound, self.origin);

 
Loading ...