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

Custom sound when entering the game

broken avatar :(
Created 7 years ago
by Nelonn
0 Members and 1 Guest are viewing this topic.
4,397 views
broken avatar :(
×
broken avatar :(
Location: fiHamina
Date Registered: 19 May 2014
Last active: 2 years ago
Posts
17
Respect
Forum Rank
Legless Crawler
Primary Group
Member
My Contact & Social Links
More
×
Nelonn's Groups
Nelonn's Contact & Social LinksNelonn
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");
}

This topic contains a post which is marked as the Best Answer. Click here to view it.
broken avatar :(
×
broken avatar :(
Location: caCanada, Eh
Date Registered: 24 November 2016
Last active: 5 years ago
Posts
85
Respect
Forum Rank
Rotting Walker
Primary Group
Member
My Contact & Social Links
More
×
MegaMech43's Groups
MegaMech43's Contact & Social Linksmegamechmegamech.net
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]
broken avatar :(
×
broken avatar :(
Location: fiHamina
Date Registered: 19 May 2014
Last active: 2 years ago
Posts
17
Respect
Forum Rank
Legless Crawler
Primary Group
Member
My Contact & Social Links
More
×
Nelonn's Groups
Nelonn's Contact & Social LinksNelonn
Thanks a lot for reply, but could you explain the "Var player Get players" line ? And should i change anyting in For() ?
Marked as best answer by Nelonn 7 years ago
broken avatar :(
×
broken avatar :(
Location: caCanada, Eh
Date Registered: 24 November 2016
Last active: 5 years ago
Posts
85
Respect
Forum Rank
Rotting Walker
Primary Group
Member
My Contact & Social Links
More
×
MegaMech43's Groups
MegaMech43's Contact & Social Linksmegamechmegamech.net
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/
Then you'll understand the basic concepts of GSC.
Last Edit: March 28, 2017, 10:07:47 pm by MegaMech43
broken avatar :(
×
broken avatar :(
Location: fiHamina
Date Registered: 19 May 2014
Last active: 2 years ago
Posts
17
Respect
Forum Rank
Legless Crawler
Primary Group
Member
My Contact & Social Links
More
×
Nelonn's Groups
Nelonn's Contact & Social LinksNelonn
Thank you for helping me again, let's see what i can do.
broken avatar :(
×
broken avatar :(
Location: fiHamina
Date Registered: 19 May 2014
Last active: 2 years ago
Posts
17
Respect
Forum Rank
Legless Crawler
Primary Group
Member
My Contact & Social Links
More
×
Nelonn's Groups
Nelonn's Contact & Social LinksNelonn
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.
Last Edit: April 02, 2017, 12:02:57 am by Nelonn
broken avatar :(
×
broken avatar :(
Location: caCanada, Eh
Date Registered: 24 November 2016
Last active: 5 years ago
Posts
85
Respect
Forum Rank
Rotting Walker
Primary Group
Member
My Contact & Social Links
More
×
MegaMech43's Groups
MegaMech43's Contact & Social Linksmegamechmegamech.net
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
Last Edit: April 02, 2017, 11:24:37 pm by MegaMech43
broken avatar :(
×
broken avatar :(
Location: fiHamina
Date Registered: 19 May 2014
Last active: 2 years ago
Posts
17
Respect
Forum Rank
Legless Crawler
Primary Group
Member
My Contact & Social Links
More
×
Nelonn's Groups
Nelonn's Contact & Social LinksNelonn
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();
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 17 February 2014
Last active: 1 year ago
Posts
69
Respect
Forum Rank
Rotting Walker
Primary Group
Member
My Contact & Social Links
More
Personal Quote
What is broken can be reforged
Signature
Completed maps:
Kingdom Hearts - World at War Link
Minecraft - Black ops 3 Link

WIP:
~

×
shinged's Groups
shinged's Contact & Social LinksShingedvinny545TheShingedMatarra_
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  :)
Last Edit: April 03, 2017, 06:40:43 pm by shinged
broken avatar :(
×
broken avatar :(
Location: fiHamina
Date Registered: 19 May 2014
Last active: 2 years ago
Posts
17
Respect
Forum Rank
Legless Crawler
Primary Group
Member
My Contact & Social Links
More
×
Nelonn's Groups
Nelonn's Contact & Social LinksNelonn
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 :)
broken avatar :(
×
broken avatar :(
Location: caCanada, Eh
Date Registered: 24 November 2016
Last active: 5 years ago
Posts
85
Respect
Forum Rank
Rotting Walker
Primary Group
Member
My Contact & Social Links
More
×
MegaMech43's Groups
MegaMech43's Contact & Social Linksmegamechmegamech.net
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");

 
Loading ...