UGX-Mods

Call of Duty: Black Ops 3 => Help Desk => Scripting => Topic started by: Nelonn on March 22, 2017, 04:21:08 pm

Title: Custom sound when entering the game
Post by: Nelonn on March 22, 2017, 04:21:08 pm
Hello everyone, so the idea is to play a sound in the start or middle of the black screen (just when it begins to fade)
What i tried is this script below, but it doesn't work for some reason. And I don't have line under function main()
Need help !

function on_player_spawned()
{
level.playSoundLocation PlaySound("welcoming_sound");
}

Title: Re: Custom sound when entering the game
Post by: MegaMech43 on March 28, 2017, 12:01:38 am
Get all the players with a for loop. Use zm utility for sound
Code Snippet
Plaintext
#using zmutility
For()
Var player Get players[i]
zmutility::playsound('sound', 'player')
End
[code]
Title: Re: Custom sound when entering the game
Post by: Nelonn on March 28, 2017, 12:31:51 pm
Thanks a lot for reply, but could you explain the "Var player Get players" line ? And should i change anyting in For() ?
Title: Re: Custom sound when entering the game
Post by: MegaMech43 on March 28, 2017, 10:02:29 pm
Code Snippet
Plaintext
#using scripts\zm\_zm_utility; //This line goes else where, you can figure it out
function ouijfadregiojharegregajkuharegujkharegkjhregakjharegjhklaregjkh() {
players = getplayers();
for(i=0; i<players.size; i++)
{
             zm_utility::play_sound_at_pos('sound', 'players[i].origin');
}
}
//put the following line in the main class.
ouijfadregiojharegregajkuharegujkharegkjhregakjharegjhklaregjkh();

You'll need to either sort through zm_utility to find a play sound function or work with the one I gave you or search through the API for a play sound function that does what you want it to do. What I wrote before was pseudo code. It's up to you to make it work. I copy'd some code from my own code. So what I put in this reply is compilable.

You should start by learning this: https://www.w3schools.com/js/ (https://www.w3schools.com/js/)
Then you'll understand the basic concepts of GSC.
Title: Re: Custom sound when entering the game
Post by: Nelonn on March 29, 2017, 05:05:24 am
Thank you for helping me again, let's see what i can do.
Title: Re: Custom sound when entering the game
Post by: Nelonn on April 02, 2017, 12:01:49 am
Hahah guys, all i wanted is to get a simple line of code, which i don't know how to correctly apply. I don't really have any time to learn all these c an js laungages just to get sound working, but thanks for tips anyway.
Title: Re: Custom sound when entering the game
Post by: MegaMech43 on April 02, 2017, 11:06:38 pm
Hahah guys, all i wanted is to get a simple line of code
I have never used this method:
level.playSoundLocation PlaySound("welcoming_sound");
I posted a way that I have used before and I know works.

Did you put "on_player_spawned();" under the main function? If you didn't do that than the function "on_player_spawned()" will not run. Functions only run when they are called. to call a function you simply take their name ex. "fname" and put "fname();" Do not call your function within itself, or call the function from somewhere where that line of code won't be run. So the best place to call a function is from the main class, or another function that perhaps does other stuff before calling your function.

Also "level.playSoundLocation" is nil unless the game knows what "playSoundLocation" is.
You should have:
Code Snippet
Plaintext
level.playSoundLocation GetEnt("SoundEntity", "targetname"); //make a sound struct or position struct with those key/values
//Now if you put,
level.playSoundLocation PlaySound("welcoming_sound"); //it might work. "PlaySound" might not be global, or you could be missing arguments. It could be local only. That's why I gave you my own function. I have no idea how "PlaySound" works.
Also if that works, it's over complicated you can simply do this:
Code Snippet
Plaintext
asound GetEnt("SoundEnt","targetname");
asound PlaySound("welcoming_sound");
You don't even have to bother putting that code in a function. Just put it under the main class.
If the code is running too early (sound plays too early). Or maybe it doesn't play at all, you may need to add "wait(time);" before the line with "GetEnt". Ex. wait(3); (Waits 3 seconds.) It's possible that if the code is run before the game starts it might not play the sound at all.

Another reason to do it my way: If all your players spawn in a circle in a vicinity of lets say 5 meters. You put the sound struct in the center. So the sound plays in some peoples left ear and some peoples right ear. Depending where you put the struct some players may hear it loud and other may hear it quiet. With my function it plays the sound on every player. Although I've realized because my way is global. If you have 4 players, it's gonna play the sound 4 times for every single player instead of just once for every player. This could be solved by using a different playsound function. That runs locally. a variety of other solutions exist as well
Title: Re: Custom sound when entering the game
Post by: Nelonn on April 03, 2017, 02:23:32 pm
By putting "on_player_spawned(); " under main function, you mean putting it under function main() ?
I tried doing this, i got insta-killed by nothing.

Placing asound lines under function main() or on_player_spawned()  causes this error - Compiler Internal Error :  Uninitialized local variable 'asound'

But the most funny thing is that my code used to work on my old computer, just after the spawn, the sound played correctly. And i have to tell you that I copied the welcoming screen script from someone i don't remember. But a have concerns about this line
Code Snippet
Plaintext
callback::on_spawned( &on_player_spawned );
Here is the .gsc file fragment if it interests you
Code Snippet
Plaintext
function main()
{
zm_usermap::main();

callback::on_spawned( &on_player_spawned );

//Setup the levels Zombie Zone Volumes
level.zones = [];
level.zone_manager_init_func =&usermap_test_zone_init;
init_zones[0] = "start_zone";
level thread zm_zonemgr::manage_zones( init_zones );
level thread add_zm_vox();
level.pathdist_type = PATHDIST_ORIGINAL;
}

function usermap_test_zone_init()
{
level flag::init( "always_on" );
level flag::set( "always_on" );
}

function custom_add_weapons()
{
zm_weapons::load_weapon_spec_from_table("gamedata/weapons/zm/zm_levelcommon_weapons.csv", 1);
}
//WELCOMING SCREEN
function on_player_spawned()
{
        level.playSoundLocation PlaySound("welcoming_sound");
self.diamond_text = NewClientHudElem( self );
self.diamond_text.alignX = "center";
self.diamond_text.alignY = "middle";
self.diamond_text.horzAlign = "center";
self.diamond_text.vertAlign = "middle";
self.diamond_text.foreground = true;
self.diamond_text.font = "bold";
self.diamond_text.fontScale = 2;
self.diamond_text.color = ( 0.5, 1, 0.5 );
self.diamond_text SetText("Survive at all costs...");
self.diamond_text setCOD7DecodeFX(100, 10000, 500);
wait(17);
self.diamond_text Destroy();
Title: Re: Custom sound when entering the game
Post by: shinged on April 03, 2017, 06:39:13 pm
Replace
Code Snippet
Plaintext
level.playSoundLocation PlaySound("welcoming_sound");
With
Code Snippet
Plaintext
self PlayLocalSound( "welcoming_sound" );

Also that diamond_text script is from my minecraft map  :)
Title: Re: Custom sound when entering the game
Post by: Nelonn on April 03, 2017, 06:50:53 pm
Thanks for the help and diamond text script, i really liked it. By the way your minecraft castle map was really impressive, hopefully you will create something minecraft themed once more :)
Title: Re: Custom sound when entering the game
Post by: MegaMech43 on April 07, 2017, 03:23:58 am
My mistake

This:
Code Snippet
Plaintext
asound GetEnt("SoundEnt","targetname");
asound PlaySound("welcoming_sound");
Should be:
Code Snippet
Plaintext
asound = GetEnt("SoundEnt","targetname");
asound PlaySound("welcoming_sound");